smooth out some edges for blog extension

This commit is contained in:
Thomas Reynolds 2011-11-24 21:52:23 -08:00
parent de077201bd
commit e920cef76a
4 changed files with 37 additions and 7 deletions

View file

@ -375,8 +375,17 @@ class Middleman::Base
# @param [Hash] Rendering locals
# @return [String] Output
def render(engine, data, options={}, locals={}, &block)
data = data.to_s
template_path = File.join(source_dir, data)
if sitemap.exists?(data)
sitemap.page(data).render(options, locals, &block)
elsif File.exists?(template_path)
body = app.cache.fetch(:raw_template, template_path) do
File.read(template_path)
end
Middleman::Sitemap::Template.static_render(self, template_path, body, locals, options, &block)
else
throw "Could not find file to render: #{data}"
end

View file

@ -7,6 +7,14 @@ module Middleman
def fetch(*key)
@cache[key] ||= yield
end
def has_key?(key)
@cache.has_key?(key)
end
def get(key)
@cache[key]
end
def clear
@cache = {}

View file

@ -71,20 +71,30 @@ module Middleman::Sitemap
def touch
end
def render(&block)
def custom_render(&block)
@_custom_renderer ||= nil
@_custom_renderer = block if block_given?
@_custom_renderer
end
def render(*args, &block)
return unless template?
if proxy?
# Forward blocks
forward_blocks = template.blocks.compact
forward_blocks << block if block_given?
store.page(proxied_to).template.render do
store.page(proxied_to).template.render(*args) do
forward_blocks.each do |block|
instance_exec(&block)
end
end
elsif !custom_render.nil?
params = args.dup
params << block if block_given?
instance_exec(*params, &custom_renderer)
else
template.render(&block)
template.render(*args, &block)
end
end

View file

@ -69,7 +69,7 @@ module Middleman::Sitemap
self.class.cache
end
def options_for_ext(ext)
def self.options_for_ext(ext)
cache.fetch(:options_for_ext, ext) do
options = {}
@ -151,12 +151,15 @@ module Middleman::Sitemap
def internal_render(path, locs = {}, opts = {}, &block)
path = path.to_s
opts.merge!(options_for_ext(File.extname(path)))
body = app.cache.fetch(:raw_template, path) do
File.read(path)
end
self.class.static_render(app, path, body, locs, opts, &block)
end
def self.static_render(app, path, body, locs = {}, opts = {}, &block)
options = opts.merge(options_for_ext(File.extname(path)))
template = cache.fetch(:compiled_template, options, body) do
::Tilt.new(path, 1, options) { body }