page helper uses provides_metadata to apply options at last minute to final output path. closes #182
This commit is contained in:
parent
745ce14624
commit
e2d5839874
|
@ -230,7 +230,7 @@ module Middleman::CoreExtensions::Rendering
|
||||||
::Tilt[path]
|
::Tilt[path]
|
||||||
end
|
end
|
||||||
|
|
||||||
if found_path || File.exists?(on_disk_path)
|
if found_path || (File.exists?(on_disk_path) && !File.directory?(on_disk_path))
|
||||||
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
|
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
|
||||||
[ found_path || on_disk_path, engine ]
|
[ found_path || on_disk_path, engine ]
|
||||||
else
|
else
|
||||||
|
|
|
@ -25,6 +25,18 @@ module Middleman::CoreExtensions::Routing
|
||||||
# page "/about.html", :layout => false
|
# page "/about.html", :layout => false
|
||||||
# page "/", :layout => :homepage_layout
|
# page "/", :layout => :homepage_layout
|
||||||
def page(url, opts={}, &block)
|
def page(url, opts={}, &block)
|
||||||
|
if url.include?("*")
|
||||||
|
url = Regexp.new(url.gsub("*", "(.*)").gsub(/^\//, "^"))
|
||||||
|
end
|
||||||
|
|
||||||
|
if url.is_a?(Regexp) && !opts.empty?
|
||||||
|
provides_metadata_for_path url do |url|
|
||||||
|
{ :options => opts }
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
opts[:layout] = layout if opts[:layout].nil?
|
opts[:layout] = layout if opts[:layout].nil?
|
||||||
|
|
||||||
url = full_path(url)
|
url = full_path(url)
|
||||||
|
|
|
@ -40,5 +40,11 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
@_provides_metadata << [block, matcher] if block_given?
|
@_provides_metadata << [block, matcher] if block_given?
|
||||||
@_provides_metadata
|
@_provides_metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def provides_metadata_for_path(matcher=nil, &block)
|
||||||
|
@_provides_metadata_for_path ||= []
|
||||||
|
@_provides_metadata_for_path << [block, matcher] if block_given?
|
||||||
|
@_provides_metadata_for_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -69,6 +69,7 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
|
|
||||||
def touch
|
def touch
|
||||||
|
template.touch if template?
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_renderer(&block)
|
def custom_renderer(&block)
|
||||||
|
|
|
@ -115,7 +115,9 @@ module Middleman::Sitemap
|
||||||
# @app.logger.debug :sitemap_update, Time.now, path if @app.logging?
|
# @app.logger.debug :sitemap_update, Time.now, path if @app.logging?
|
||||||
|
|
||||||
# Add generic path
|
# Add generic path
|
||||||
page(path).source_file = File.expand_path(file, @app.root)
|
p = page(path)
|
||||||
|
p.source_file = File.expand_path(file, @app.root)
|
||||||
|
p.touch
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,17 +30,31 @@ module Middleman::Sitemap
|
||||||
page.ext
|
page.ext
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def touch
|
||||||
|
app.cache.remove(:metadata, source_file)
|
||||||
|
end
|
||||||
|
|
||||||
def metadata
|
def metadata
|
||||||
app.cache.fetch(:metadata, source_file) do
|
metadata = app.cache.fetch(:metadata, source_file) do
|
||||||
metadata = { :options => {}, :locals => {} }
|
data = { :options => {}, :locals => {} }
|
||||||
|
|
||||||
app.provides_metadata.each do |callback, matcher|
|
app.provides_metadata.each do |callback, matcher|
|
||||||
next if !matcher.nil? && !source_file.match(matcher)
|
next if !matcher.nil? && !source_file.match(matcher)
|
||||||
result = app.instance_exec(source_file, &callback)
|
result = app.instance_exec(source_file, &callback)
|
||||||
|
data = data.deep_merge(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
app.provides_metadata_for_path.each do |callback, matcher|
|
||||||
|
next if !matcher.nil? && !path.match(matcher)
|
||||||
|
result = app.instance_exec(path, &callback)
|
||||||
metadata = metadata.deep_merge(result)
|
metadata = metadata.deep_merge(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
metadata
|
metadata
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def render(opts={}, locs={}, &block)
|
def render(opts={}, locs={}, &block)
|
||||||
opts = options.deep_merge(metadata[:options]).deep_merge(opts)
|
opts = options.deep_merge(metadata[:options]).deep_merge(opts)
|
||||||
|
|
Loading…
Reference in a new issue