Skip to content

Commit

Permalink
Allow nested renders to use the same scope object
Browse files Browse the repository at this point in the history
  • Loading branch information
sborrazas committed Jan 31, 2015
1 parent d99c172 commit a6d2c45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/armadillo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get_frame(block_name, frame)
# @return [String]
# @api public
def self.render(template_path, locals = {}, options = {})
scope = options.delete(:scope) { Object.new }
scope = options.fetch(:scope) { Object.new }
context = TemplateContext.new(scope, options)
_render(template_path, locals, context, options)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ def obj.some_text
"<h2>Subtitle</h2>"
])
end

it "uses the same scope object" do
obj = Object.new
def obj.some_text
"text!"
end
content = Armadillo.render("with_sub_template2.html", {}, {
:base_path => TEMPLATES_PATH,
:escape_html => true,
:scope => obj
})
assert_lines_match(content, [
"<h2>text!</h2>"
])
end
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/templates/sub_template2.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2><%= some_text %></h2>
2 changes: 2 additions & 0 deletions spec/templates/with_sub_template2.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Title</h1>
<%== render("sub_template2.html") %>

0 comments on commit a6d2c45

Please sign in to comment.