Skip to content

Commit

Permalink
Rename asset paths (#55)
Browse files Browse the repository at this point in the history
Mounting assets under `/assets` can cause unexpected issues.

Rails applications typically serve assets from `/assets`. Often times,
NGINX is used to intercept requests to `/assets` and serve those files
from disk, instead of hitting the Rails application.

By serving the assets from a different path, we sidestep that issue.
  • Loading branch information
rzane authored Feb 12, 2025
1 parent 4afce47 commit 833be7c
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
demo_mode (2.2.0)
demo_mode (2.3.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/demo_mode/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<% end %>
<% end %>

<script src="/assets/demo_mode/vendor/typed-v2.1.0.js"></script>
<script src="/assets/demo_mode/demo_mode.js?v=<%= DemoMode::VERSION %>"></script>
<script src="/demo_mode/assets/vendor/typed-v2.1.0.js"></script>
<script src="/demo_mode/assets/demo_mode.js?v=<%= DemoMode::VERSION %>"></script>
<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0, user-scalable=0">
</head>
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (2.2.0)
demo_mode (2.3.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (2.2.0)
demo_mode (2.3.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (2.2.0)
demo_mode (2.3.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (2.2.0)
demo_mode (2.3.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (2.2.0)
demo_mode (2.3.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
Expand Down
6 changes: 3 additions & 3 deletions lib/demo_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

module DemoMode
ICONS = {
tophat: "/assets/demo_mode/icon--tophat.png?v=#{VERSION}",
user: "/assets/demo_mode/icon--user.png?v=#{VERSION}",
users: "/assets/demo_mode/icon--users.png?v=#{VERSION}",
tophat: "/demo_mode/assets/icon--tophat.png?v=#{VERSION}",
user: "/demo_mode/assets/icon--user.png?v=#{VERSION}",
users: "/demo_mode/assets/icon--users.png?v=#{VERSION}",
}.freeze

class << self
Expand Down
6 changes: 3 additions & 3 deletions lib/demo_mode/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def self.app_name

def stylesheets
@stylesheets ||= [
"/assets/demo_mode/vendor/normalize-v8.0.1.css",
"/assets/demo_mode/demo_mode.css?v=#{VERSION}",
"/demo_mode/assets/vendor/normalize-v8.0.1.css",
"/demo_mode/assets/demo_mode.css?v=#{VERSION}",
]
end

Expand All @@ -47,7 +47,7 @@ def loader(&block)
if block
@loader = block
else
@loader ||= ->(_) { image_tag("/assets/demo_mode/loader.png?v=#{VERSION}") }
@loader ||= ->(_) { image_tag("/demo_mode/assets/loader.png?v=#{VERSION}") }
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/demo_mode/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DemoMode
VERSION = '2.2.0'
VERSION = '2.3.0'
end
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
12 changes: 6 additions & 6 deletions spec/demo_mode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def self.enabled?
end

expect(render_value(described_class.logo)).to eq '<strong>Dummy</strong>' # default
expect(render_value(described_class.loader)).to match %r{img src="/assets/demo_mode/loader\.png\?v=#{DemoMode::VERSION}"}o
expect(render_value(described_class.loader)).to match %r{img src="/demo_mode/assets/loader\.png\?v=#{DemoMode::VERSION}"}o
expect(described_class.personas.count).to eq 1
described_class.personas.first.tap do |persona|
expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--user\.png\?v=#{DemoMode::VERSION}"}o # default
expect(render_value(persona.icon)).to match %r{img src="/demo_mode/assets/icon--user\.png\?v=#{DemoMode::VERSION}"}o # default
expect(persona.features).to eq ['test']
expect(generated_persona).to be false
expect(persona.generate!).to eq 'something_important'
Expand Down Expand Up @@ -128,16 +128,16 @@ def self.enabled?

expect(described_class.stylesheets).to eq([
'/before.css',
'/assets/demo_mode/vendor/normalize-v8.0.1.css',
"/assets/demo_mode/demo_mode.css?v=#{DemoMode::VERSION}",
'/demo_mode/assets/vendor/normalize-v8.0.1.css',
"/demo_mode/assets/demo_mode.css?v=#{DemoMode::VERSION}",
'/after.css',
])

expect(render_value(described_class.logo)).to eq '<marquee>The Logo</marquee>'
expect(render_value(described_class.loader)).to match %r{img src="/images/loading-for-real.gif"}
expect(described_class.personas.count).to eq 3
described_class.personas.first.tap do |persona|
expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--tophat\.png\?v=#{DemoMode::VERSION}"}o
expect(render_value(persona.icon)).to match %r{img src="/demo_mode/assets/icon--tophat\.png\?v=#{DemoMode::VERSION}"}o
expect(persona.features).to eq(['foo'])
expect(generated_persona_1).to be false
expect(persona.generate!(password: 'cool_password')).to eq 'banana'
Expand Down Expand Up @@ -189,7 +189,7 @@ def self.enabled?
described_class.personas.tap do |personas|
expect(personas.count).to eq 1
personas.first.tap do |persona|
expect(render_value(persona.icon)).to match %r{img src="/assets/demo_mode/icon--users\.png\?v=#{DemoMode::VERSION}"}o
expect(render_value(persona.icon)).to match %r{img src="/demo_mode/assets/icon--users\.png\?v=#{DemoMode::VERSION}"}o
expect(persona.features).to eq ['foo']
expect(persona.generate!).to eq 'banana'
end
Expand Down

0 comments on commit 833be7c

Please sign in to comment.