32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'middleman-core/lib/middleman-core/file_renderer.rb', line 32
def render(locs, opts, context, &block)
path = @path.dup
extension = File.extname(path)
engine = extension[1..-1].to_sym
context.current_engine, engine_was = engine, context.current_engine
buf_was = context.save_buffer
body = if opts[:template_body]
opts.delete(:template_body)
else
template_data_for_file
end
extension = File.extname(path)
options = {}.merge!(opts).merge!(options_for_ext(extension))
options[:outvar] ||= '@_out_buf'
options[:context] = context
options.delete(:layout)
options = options.deep_merge(options[:renderer_options]) if options[:renderer_options]
template_class = ::Middleman::Util.tilt_class(path)
body = @app.callbacks_for(:before_render).reduce(body) do |sum, callback|
callback.call(sum, path, locs, template_class) || sum
end
template = ::Tilt.new(path, 1, options) { body }
content = template.render(context, locs, &block)
content = @app.callbacks_for(:after_render).reduce(content) do |sum, callback|
callback.call(sum, path, locs, template_class) || sum
end
output = ::ActiveSupport::SafeBuffer.new ''
output.safe_concat content
output
ensure
context.restore_buffer(buf_was)
context.current_engine = engine_was
end
|