mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
support glob page instance vars. fixes #230
This commit is contained in:
parent
22adf3b516
commit
92319ebffc
7 changed files with 90 additions and 23 deletions
|
@ -46,23 +46,45 @@ Feature: Dynamic Pages
|
|||
Given the Server is running at "dynamic-pages-app"
|
||||
When I go to "/fake/one.html"
|
||||
Then I should see "I am real: one"
|
||||
Then I should see "Global: I am one glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
When I go to "/fake2/one.html"
|
||||
Then I should see "I am real: one"
|
||||
Then I should see "Global: I am two glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
When I go to "/fake3/one.html"
|
||||
Then I should see "I am real: one"
|
||||
Then I should see "Global: I am three glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
When I go to "/fake4/one.html"
|
||||
Then I should see "I am real: one"
|
||||
Then I should see "Global: I am four glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
Scenario: Preview proxy with variable two
|
||||
Given the Server is running at "dynamic-pages-app"
|
||||
When I go to "/fake/two.html"
|
||||
Then I should see "I am real: two"
|
||||
Then I should see "Global: I am one glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
When I go to "/fake2/two.html"
|
||||
Then I should see "I am real: two"
|
||||
Then I should see "Global: I am two glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
When I go to "/fake3/two.html"
|
||||
Then I should see "I am real: two"
|
||||
Then I should see "Global: I am three glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
When I go to "/fake4/two.html"
|
||||
Then I should see "I am real: two"
|
||||
Then I should see "Global: I am four glob"
|
||||
Then I should see "All: I am all glob"
|
||||
|
||||
Scenario: Target ignore
|
||||
Given the Server is running at "dynamic-pages-app"
|
||||
|
|
|
@ -16,5 +16,3 @@ Feature: Instance Vars
|
|||
When I go to "/instance-var-set.html"
|
||||
When I go to "/no-instance-var.html"
|
||||
Then I should see "No var..."
|
||||
|
||||
|
|
@ -27,3 +27,23 @@ page "/target_ignore4.html", :proxy => "should_be_ignored8.html", :ignore => tru
|
|||
@num = num
|
||||
end
|
||||
end
|
||||
|
||||
page "f*/*" do
|
||||
@all_glob = "I am all glob"
|
||||
end
|
||||
|
||||
page "fake/*" do
|
||||
@glob_var = "I am one glob"
|
||||
end
|
||||
|
||||
page "fake2/*" do
|
||||
@glob_var = "I am two glob"
|
||||
end
|
||||
|
||||
page "fake3/*" do
|
||||
@glob_var = "I am three glob"
|
||||
end
|
||||
|
||||
page "fake4/*" do
|
||||
@glob_var = "I am four glob"
|
||||
end
|
|
@ -3,3 +3,7 @@ layout: false
|
|||
---
|
||||
|
||||
I am real: <%= @num %>
|
||||
|
||||
Global: <%= @glob_var %>
|
||||
|
||||
All: <%= @all_glob %>
|
|
@ -25,13 +25,15 @@ module Middleman::CoreExtensions::Routing
|
|||
# page "/about.html", :layout => false
|
||||
# page "/", :layout => :homepage_layout
|
||||
def page(url, opts={}, &block)
|
||||
a_block = block_given? ? block : nil
|
||||
|
||||
if url.include?("*")
|
||||
url = Regexp.new(url.gsub("*", "(.*)").gsub(/^\//, "^"))
|
||||
url = Regexp.new(url.gsub("*", "(.*?)").gsub(/^\//, "^"))
|
||||
end
|
||||
|
||||
if url.is_a?(Regexp) && !opts.empty?
|
||||
if url.is_a?(Regexp)
|
||||
provides_metadata_for_path url do |url|
|
||||
{ :options => opts }
|
||||
{ :options => opts, :blocks => [a_block] }
|
||||
end
|
||||
|
||||
return
|
||||
|
@ -57,11 +59,9 @@ module Middleman::CoreExtensions::Routing
|
|||
end
|
||||
end
|
||||
|
||||
a_block = block_given? ? block : nil
|
||||
if a_block || !opts.empty?
|
||||
sitemap.page(url) do
|
||||
template.options = opts
|
||||
template.blocks = [a_block]
|
||||
provides_metadata_for_path url do |url|
|
||||
{ :options => opts, :blocks => [a_block] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,6 +23,14 @@ module Middleman::Sitemap
|
|||
@source_file = src
|
||||
end
|
||||
|
||||
def request_path
|
||||
if proxy?
|
||||
store.page(proxied_to).path
|
||||
else
|
||||
path
|
||||
end
|
||||
end
|
||||
|
||||
def source_file
|
||||
if proxy?
|
||||
store.page(proxied_to).source_file
|
||||
|
@ -83,24 +91,26 @@ module Middleman::Sitemap
|
|||
|
||||
if proxy?
|
||||
# Forward blocks
|
||||
forward_blocks = template.blocks.compact
|
||||
forward_blocks << block if block_given?
|
||||
store.page(proxied_to).template.render(*args) do
|
||||
forward_blocks.each do |block|
|
||||
instance_exec(&block)
|
||||
end
|
||||
end
|
||||
# forward_blocks = template.blocks.compact
|
||||
# forward_blocks << block if block_given?
|
||||
t = store.page(proxied_to).template
|
||||
t.request_path = path
|
||||
t.render(*args)
|
||||
# do
|
||||
# forward_blocks.each do |block|
|
||||
# instance_exec(&block)
|
||||
# end
|
||||
# end
|
||||
elsif !custom_renderer.nil?
|
||||
params = args.dup
|
||||
params << block if block_given?
|
||||
instance_exec(*params, &custom_renderer)
|
||||
else
|
||||
template.request_path = path
|
||||
template.render(*args, &block)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def directory_index?
|
||||
path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Middleman::Sitemap
|
||||
|
||||
class Template
|
||||
attr_accessor :page, :options, :locals, :blocks#, :dependencies
|
||||
attr_accessor :page, :options, :locals, :blocks, :request_path
|
||||
|
||||
def initialize(page)
|
||||
@page = page
|
||||
|
@ -36,7 +36,7 @@ module Middleman::Sitemap
|
|||
|
||||
def metadata
|
||||
metadata = app.cache.fetch(:metadata, source_file) do
|
||||
data = { :options => {}, :locals => {}, :page => {} }
|
||||
data = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||
|
||||
app.provides_metadata.each do |callback, matcher|
|
||||
next if !matcher.nil? && !source_file.match(matcher)
|
||||
|
@ -48,8 +48,17 @@ module Middleman::Sitemap
|
|||
end
|
||||
|
||||
app.provides_metadata_for_path.each do |callback, matcher|
|
||||
next if !matcher.nil? && !path.match(matcher)
|
||||
result = app.instance_exec(path, &callback)
|
||||
if matcher.is_a? Regexp
|
||||
next if !self.request_path.match(matcher)
|
||||
elsif matcher.is_a? String
|
||||
next if "/#{self.request_path}" != matcher
|
||||
end
|
||||
|
||||
result = app.instance_exec(self.request_path, &callback)
|
||||
if result.has_key?(:blocks)
|
||||
metadata[:blocks] << result[:blocks]
|
||||
result.delete(:blocks)
|
||||
end
|
||||
metadata = metadata.deep_merge(result)
|
||||
end
|
||||
|
||||
|
@ -72,6 +81,10 @@ module Middleman::Sitemap
|
|||
app.instance_eval(&block)
|
||||
end
|
||||
|
||||
md[:blocks].flatten.compact.each do |block|
|
||||
app.instance_eval(&block)
|
||||
end
|
||||
|
||||
app.instance_eval(&block) if block_given?
|
||||
result = app.render_template(source_file, locs, opts)
|
||||
|
||||
|
|
Loading…
Reference in a new issue