use private before filters, leave sinatra alone. fixes #76
This commit is contained in:
parent
be506c60cc
commit
292ec97bd8
6
features/sinatra.feature
Normal file
6
features/sinatra.feature
Normal file
|
@ -0,0 +1,6 @@
|
|||
Feature: Sinatra Routes
|
||||
|
||||
Scenario: Rendering html
|
||||
Given the Server is running
|
||||
When I go to "/sinatra_test"
|
||||
Then I should see "Ratpack"
|
|
@ -28,3 +28,7 @@ with_layout false do
|
|||
page path
|
||||
end
|
||||
end
|
||||
|
||||
get "/sinatra_test" do
|
||||
"Ratpack"
|
||||
end
|
|
@ -78,7 +78,7 @@ module Middleman::Base
|
|||
end
|
||||
|
||||
# See if Tilt cannot handle this file
|
||||
app.before do
|
||||
app.before_processing do
|
||||
if !settings.views.include?(settings.root)
|
||||
settings.set :views, File.join(settings.root, settings.views)
|
||||
end
|
||||
|
@ -92,12 +92,14 @@ module Middleman::Base
|
|||
content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
|
||||
status 200
|
||||
send_file File.join(settings.views, request.path_info)
|
||||
request["already_sent"] = true
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
else
|
||||
$stderr.puts "File not found: #{request.path_info}"
|
||||
status 404
|
||||
request["already_sent"] = true
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -115,6 +117,19 @@ module Middleman::Base
|
|||
super(option, value, &nil)
|
||||
end
|
||||
|
||||
def before_processing(&block)
|
||||
@before_processes ||= []
|
||||
@before_processes << block
|
||||
end
|
||||
|
||||
def execute_before_processing!(inst)
|
||||
@before_processes ||= []
|
||||
|
||||
@before_processes.all? do |block|
|
||||
inst.instance_eval(&block)
|
||||
end
|
||||
end
|
||||
|
||||
# Convenience method to check if we're in build mode
|
||||
def build?; environment == :build; end
|
||||
end
|
||||
|
@ -122,7 +137,7 @@ module Middleman::Base
|
|||
module InstanceMethods
|
||||
# Internal method to look for templates and evaluate them if found
|
||||
def process_request(options={})
|
||||
return if request["already_sent"]
|
||||
return unless settings.execute_before_processing!(self)
|
||||
|
||||
options.merge!(request['custom_options'] || {})
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
::Tilt.prefer(HamlTemplate)
|
||||
|
||||
app.after_feature_init do
|
||||
app.before do
|
||||
app.before_processing do
|
||||
result = resolve_template(request.path_info, :raise_exceptions => false)
|
||||
|
||||
if result && Tilt.mappings.has_key?(result[1].to_s)
|
||||
|
@ -42,6 +42,8 @@ module Middleman::CoreExtensions::FrontMatter
|
|||
# Forward remaining data to helpers
|
||||
app.data_content("page", data)
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,8 +4,9 @@ module Middleman::CoreExtensions::Routing
|
|||
app.extend ClassMethods
|
||||
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
app.before do
|
||||
app.before_processing do
|
||||
request.path_info = self.class.path_to_index(request.path)
|
||||
true
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
|
@ -43,7 +44,7 @@ module Middleman::CoreExtensions::Routing
|
|||
|
||||
paths = [url]
|
||||
paths << "#{url}/" if url.length > 1 && url.split("/").last.split('.').length <= 1
|
||||
paths << "#{path_to_index(url)}"
|
||||
paths << "/#{path_to_index(url)}"
|
||||
|
||||
options[:layout] = settings.layout if options[:layout].nil?
|
||||
|
||||
|
|
|
@ -42,8 +42,9 @@ module Middleman
|
|||
end
|
||||
|
||||
$stderr.puts "== Blog: #{app.settings.blog_permalink}"
|
||||
end
|
||||
|
||||
app.before do
|
||||
app.before_processing do
|
||||
articles_glob = File.join(app.views, app.settings.blog_permalink.gsub(/(:\w+)/, "*") + ".*")
|
||||
|
||||
articles = Dir[articles_glob].map do |article|
|
||||
|
@ -84,6 +85,7 @@ module Middleman
|
|||
end
|
||||
|
||||
app.data_content("blog", { :articles => articles, :tags => tags })
|
||||
true
|
||||
end
|
||||
|
||||
app.get(app.settings.blog_permalink) do
|
||||
|
@ -96,7 +98,6 @@ module Middleman
|
|||
body body.gsub!(settings.blog_summary_separator, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :included :registered
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue