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