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
|
@ -171,11 +171,11 @@ module Middleman::CoreExtensions::Rendering
|
|||
# @private
|
||||
def locate_layout(name, preferred_engine=nil)
|
||||
layout_path = false
|
||||
|
||||
|
||||
if !preferred_engine.nil?
|
||||
# Check root
|
||||
layout_path, layout_engine = resolve_template(name, :preferred_engine => preferred_engine)
|
||||
|
||||
|
||||
# Check layouts folder
|
||||
if !layout_path
|
||||
layout_path, layout_engine = resolve_template(File.join("layouts", name.to_s), :preferred_engine => preferred_engine)
|
||||
|
@ -229,8 +229,8 @@ module Middleman::CoreExtensions::Rendering
|
|||
found_path = Dir[path_with_ext].find do |path|
|
||||
::Tilt[path]
|
||||
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
|
||||
[ found_path || on_disk_path, engine ]
|
||||
else
|
||||
|
|
|
@ -25,6 +25,18 @@ module Middleman::CoreExtensions::Routing
|
|||
# page "/about.html", :layout => false
|
||||
# page "/", :layout => :homepage_layout
|
||||
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?
|
||||
|
||||
url = full_path(url)
|
||||
|
|
|
@ -40,5 +40,11 @@ module Middleman::CoreExtensions::Sitemap
|
|||
@_provides_metadata << [block, matcher] if block_given?
|
||||
@_provides_metadata
|
||||
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
|
|
@ -69,6 +69,7 @@ module Middleman::Sitemap
|
|||
end
|
||||
|
||||
def touch
|
||||
template.touch if template?
|
||||
end
|
||||
|
||||
def custom_renderer(&block)
|
||||
|
|
|
@ -115,7 +115,9 @@ module Middleman::Sitemap
|
|||
# @app.logger.debug :sitemap_update, Time.now, path if @app.logging?
|
||||
|
||||
# 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
|
||||
end
|
||||
|
|
|
@ -29,17 +29,31 @@ module Middleman::Sitemap
|
|||
def ext
|
||||
page.ext
|
||||
end
|
||||
|
||||
|
||||
def touch
|
||||
app.cache.remove(:metadata, source_file)
|
||||
end
|
||||
|
||||
def metadata
|
||||
app.cache.fetch(:metadata, source_file) do
|
||||
metadata = { :options => {}, :locals => {} }
|
||||
metadata = app.cache.fetch(:metadata, source_file) do
|
||||
data = { :options => {}, :locals => {} }
|
||||
|
||||
app.provides_metadata.each do |callback, matcher|
|
||||
next if !matcher.nil? && !source_file.match(matcher)
|
||||
result = app.instance_exec(source_file, &callback)
|
||||
metadata = metadata.deep_merge(result)
|
||||
data = data.deep_merge(result)
|
||||
end
|
||||
metadata
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
metadata
|
||||
end
|
||||
|
||||
def render(opts={}, locs={}, &block)
|
||||
|
|
Loading…
Reference in a new issue