Skip to content

Commit

Permalink
Don't depend on Sprockets (#48)
Browse files Browse the repository at this point in the history
This engine doesn't need to depend on Sprockets.

Instead, we'll insert a middleware to expose our assets at
`/assets/demo_mode`. These assets don't need to be compiled or minified.
  • Loading branch information
rzane authored Feb 6, 2025
1 parent 820caf3 commit 8c89888
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 72 deletions.
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PATH
remote: .
specs:
demo_mode (1.5.0)
demo_mode (2.0.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui
railties (>= 6.1, < 8.1)
sprockets-rails
typedjs-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -234,15 +232,16 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (2.5.0-arm64-darwin)
sqlite3 (2.5.0-x86_64-darwin)
sqlite3 (2.5.0-x86_64-linux-gnu)
stringio (3.1.0)
thor (1.3.1)
timeout (0.4.1)
typedjs-rails (2.0.9)
railties (>= 3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uncruft (0.3.4)
Expand Down Expand Up @@ -274,6 +273,8 @@ DEPENDENCIES
factory_bot
net-smtp
rspec-rails
sprockets-rails
sqlite3
uncruft
webrick

Expand Down
5 changes: 0 additions & 5 deletions app/assets/stylesheets/demo_mode/application.css

This file was deleted.

6 changes: 4 additions & 2 deletions app/views/layouts/demo_mode/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<meta charset="UTF-8">
<title>Demo Mode</title>
<%= favicon_link_tag '/favicon.ico' %>
<%= stylesheet_link_tag 'demo_mode/application', media: 'all' %>
<%= javascript_include_tag 'demo_mode/application' %>
<link rel="stylesheet" href="/assets/demo_mode/vendor/normalize-v8.0.1.css">
<link rel="stylesheet" href="/assets/demo_mode/demo_mode.css?v=<%= DemoMode::VERSION %>">
<script src="/assets/demo_mode/vendor/typed-v2.1.0.js"></script>
<script src="/assets/demo_mode/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
7 changes: 6 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
DemoMode.add_persona :the_sometimesperson do
features << 'foobar'
callout true
icon 'demo_mode/icon--tophat'
icon :tophat
sign_in_as { DummyUser.create!(name: SecureRandom.uuid) }

variant :the_rarely_person do
Expand Down Expand Up @@ -77,6 +77,11 @@ end
Combustion.path = 'spec/dummy'
Combustion.initialize! :all do
config.active_job.queue_adapter = :async
config.action_dispatch.show_exceptions = if ActiveSupport.version >= Gem::Version.new('7.1')
:none
else
false
end
end

run Combustion::Application
Expand Down
4 changes: 2 additions & 2 deletions demo_mode.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ Gem::Specification.new do |s|
s.add_dependency 'activesupport', rails_constraints
s.add_dependency 'cli-ui'
s.add_dependency 'railties', rails_constraints
s.add_dependency 'sprockets-rails'
s.add_dependency 'typedjs-rails'

s.add_development_dependency 'actionmailer', rails_constraints
s.add_development_dependency 'appraisal'
Expand All @@ -40,6 +38,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'factory_bot'
s.add_development_dependency 'net-smtp'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'sprockets-rails'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'uncruft'
s.add_development_dependency 'webrick'
end
13 changes: 5 additions & 8 deletions gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PATH
remote: ..
specs:
demo_mode (1.5.0)
demo_mode (2.0.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui
railties (>= 6.1, < 8.1)
sprockets-rails
typedjs-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -202,17 +200,15 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (1.7.0-arm64-darwin)
sqlite3 (1.7.0-x86_64-darwin)
sqlite3 (1.7.0-x86_64-linux)
thor (1.3.0)
timeout (0.4.1)
typedjs-rails (2.0.9)
railties (>= 3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uncruft (0.3.4)
Expand Down Expand Up @@ -245,6 +241,7 @@ DEPENDENCIES
net-smtp
railties (~> 6.1.0)
rspec-rails
sprockets-rails
sqlite3 (~> 1.4)
uncruft
webrick
Expand Down
9 changes: 3 additions & 6 deletions gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PATH
remote: ..
specs:
demo_mode (1.5.0)
demo_mode (2.0.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui
railties (>= 6.1, < 8.1)
sprockets-rails
typedjs-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -205,7 +203,7 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand All @@ -214,8 +212,6 @@ GEM
sqlite3 (1.7.0-x86_64-linux)
thor (1.3.0)
timeout (0.4.1)
typedjs-rails (2.0.9)
railties (>= 3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uncruft (0.3.4)
Expand Down Expand Up @@ -248,6 +244,7 @@ DEPENDENCIES
net-smtp
railties (~> 7.0.0)
rspec-rails
sprockets-rails
sqlite3 (~> 1.4)
uncruft
webrick
Expand Down
9 changes: 3 additions & 6 deletions gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PATH
remote: ..
specs:
demo_mode (1.5.0)
demo_mode (2.0.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui
railties (>= 6.1, < 8.1)
sprockets-rails
typedjs-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -245,7 +243,7 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand All @@ -255,8 +253,6 @@ GEM
stringio (3.1.2)
thor (1.3.2)
timeout (0.4.1)
typedjs-rails (2.0.9)
railties (>= 3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uncruft (0.3.4)
Expand Down Expand Up @@ -289,6 +285,7 @@ DEPENDENCIES
net-smtp
railties (~> 7.1.0)
rspec-rails
sprockets-rails
sqlite3 (>= 1.4)
uncruft
webrick
Expand Down
9 changes: 3 additions & 6 deletions gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PATH
remote: ..
specs:
demo_mode (1.5.0)
demo_mode (2.0.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui
railties (>= 6.1, < 8.1)
sprockets-rails
typedjs-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -241,7 +239,7 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand All @@ -251,8 +249,6 @@ GEM
stringio (3.1.2)
thor (1.3.2)
timeout (0.4.1)
typedjs-rails (2.0.9)
railties (>= 3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uncruft (0.3.4)
Expand Down Expand Up @@ -286,6 +282,7 @@ DEPENDENCIES
net-smtp
railties (~> 7.2.0)
rspec-rails
sprockets-rails
sqlite3 (>= 1.4)
uncruft
webrick
Expand Down
9 changes: 3 additions & 6 deletions gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
PATH
remote: ..
specs:
demo_mode (1.5.0)
demo_mode (2.0.0)
actionpack (>= 6.1, < 8.1)
activejob (>= 6.1, < 8.1)
activerecord (>= 6.1, < 8.1)
activesupport (>= 6.1, < 8.1)
cli-ui
railties (>= 6.1, < 8.1)
sprockets-rails
typedjs-rails

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -241,7 +239,7 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand All @@ -251,8 +249,6 @@ GEM
stringio (3.1.2)
thor (1.3.2)
timeout (0.4.1)
typedjs-rails (2.0.9)
railties (>= 3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uncruft (0.3.4)
Expand Down Expand Up @@ -287,6 +283,7 @@ DEPENDENCIES
net-smtp
railties (~> 8.0.0)
rspec-rails
sprockets-rails
sqlite3 (>= 2.1)
uncruft
webrick
Expand Down
7 changes: 6 additions & 1 deletion lib/demo_mode.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# frozen_string_literal: true

require 'rails'
require 'typedjs-rails'
require 'demo_mode/version'
require 'demo_mode/clever_sequence'
require 'demo_mode/config'
require 'demo_mode/engine'
require 'demo_mode/persona'

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}",
}.freeze

class << self
delegate(*Config.configurations, to: :configuration)

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 @@ -39,17 +39,17 @@ def loader(&block)
if block
@loader = block
else
@loader ||= ->(_) { image_tag('demo_mode/loader.png') }
@loader ||= ->(_) { image_tag("/assets/demo_mode/loader.png?v=#{VERSION}") }
end
end

def icon(name_or_path = nil, &block)
if block
@icon = block
elsif name_or_path
@path = name_or_path.is_a?(Symbol) ? "demo_mode/icon--#{name_or_path}" : name_or_path
@path = ICONS.fetch(name_or_path, name_or_path)
else
@path ||= 'demo_mode/icon--user'
@path ||= ICONS.fetch(:user)
path = @path
@icon ||= ->(_) { image_tag path }
end
Expand Down
15 changes: 3 additions & 12 deletions lib/demo_mode/engine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'sprockets/railtie'

module DemoMode
class Engine < ::Rails::Engine
isolate_namespace DemoMode
Expand All @@ -12,23 +10,16 @@ class Engine < ::Rails::Engine
load 'demo_mode/tasks.rb'
end

initializer 'demo_mode' do |_app|
initializer 'demo_mode' do |app|
require 'zeitwerk/version'
raise 'DemoMode only supports Zeitwerk::VERSION >= 2.4.2' unless Gem::Version.new(Zeitwerk::VERSION) >= Gem::Version.new('2.4.2')

Rails.autoloaders.main.on_load(DemoMode.app_base_controller_name) do
DemoMode.app_base_controller_name.constantize.include Demoable
end
end
end

initializer 'demo_mode.assets' do |app|
app.config.assets.precompile << 'demo_mode/application.css'
app.config.assets.precompile << 'demo_mode/application.js'
app.config.assets.precompile << 'demo_mode/icon--user.png'
app.config.assets.precompile << 'demo_mode/icon--users.png'
app.config.assets.precompile << 'demo_mode/icon--tophat.png'
app.config.assets.precompile << 'demo_mode/loader.png'
app.middleware.insert_before(ActionDispatch::Static, ActionDispatch::Static, "#{root}/public")
end
end
end
end
Loading

0 comments on commit 8c89888

Please sign in to comment.