mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
enable the reloader in subclasses automatically
This commit is contained in:
parent
580ecfeff7
commit
e78f84e1b8
3 changed files with 35 additions and 1 deletions
|
@ -218,6 +218,14 @@ module Sinatra
|
||||||
stop_registering_extension
|
stop_registering_extension
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Does everything Sinatra::Base#register does and then registers
|
||||||
|
# the reloader in the +subclass+.
|
||||||
|
def inherited(subclass)
|
||||||
|
result = super
|
||||||
|
subclass.register Sinatra::Reloader
|
||||||
|
result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Contains the methods that the extension adds to the Sinatra
|
# Contains the methods that the extension adds to the Sinatra
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
class <%= name %> < Sinatra::Base
|
class <%= name %> < <%= parent %>
|
||||||
|
<% if enable_reloader %>
|
||||||
register Sinatra::Reloader
|
register Sinatra::Reloader
|
||||||
enable :reloader
|
enable :reloader
|
||||||
|
<% end %>
|
||||||
<% unless inline_templates.nil? %>
|
<% unless inline_templates.nil? %>
|
||||||
enable :inline_templates
|
enable :inline_templates
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -44,6 +44,8 @@ describe Sinatra::Reloader do
|
||||||
options[:middlewares] ||= []
|
options[:middlewares] ||= []
|
||||||
options[:filters] ||= []
|
options[:filters] ||= []
|
||||||
options[:name] ||= app_name
|
options[:name] ||= app_name
|
||||||
|
options[:enable_reloader] = true unless options[:enable_reloader] === false
|
||||||
|
options[:parent] ||= 'Sinatra::Base'
|
||||||
|
|
||||||
update_file(app_file_path) do |f|
|
update_file(app_file_path) do |f|
|
||||||
template_path = File.expand_path('../reloader/app.rb.erb', __FILE__)
|
template_path = File.expand_path('../reloader/app.rb.erb', __FILE__)
|
||||||
|
@ -387,4 +389,26 @@ describe Sinatra::Reloader do
|
||||||
get('/foo').body.strip.should == 'foo'
|
get('/foo').body.strip.should == 'foo'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "automatically registers the reloader in the subclases" do
|
||||||
|
class ::Parent < Sinatra::Base
|
||||||
|
register Sinatra::Reloader
|
||||||
|
enable :reloader
|
||||||
|
end
|
||||||
|
|
||||||
|
setup_example_app(
|
||||||
|
:routes => ['get("/foo") { "foo" }'],
|
||||||
|
:enable_reloader => false,
|
||||||
|
:parent => 'Parent'
|
||||||
|
)
|
||||||
|
|
||||||
|
update_app_file(
|
||||||
|
:routes => ['get("/foo") { "bar" }'],
|
||||||
|
:enable_reloader => false,
|
||||||
|
:parent => 'Parent'
|
||||||
|
)
|
||||||
|
|
||||||
|
get('/foo').body.should == 'bar'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue