Skip to content

Commit

Permalink
Fix logic less bug (Fix #783)
Browse files Browse the repository at this point in the history
The bug occurred when a lambda from the parent scope is called.
  • Loading branch information
minad committed Sep 18, 2023
1 parent df9d42e commit 4ccd62e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Development

* Fix logic less bug - #783

5.1.1 (2023-05-16)

* Support lambda functions as shortcuts - #677 #813 #903
Expand Down
2 changes: 1 addition & 1 deletion lib/slim/logic_less/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def lambda(name, &block)
return @dict.instance_variable_get(var_name).call(&block) if instance_variable?(var_name)
end
end
@parent.lambda(name) if @parent
@parent.lambda(name, &block) if @parent
end

def [](name)
Expand Down
15 changes: 15 additions & 0 deletions test/logic_less/test_logic_less.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,19 @@ def test_render_with_yield
'This is the menu'
end
end

def test_render_parent_lambda
source = %q{
- list
== fn
p = string
}

assert_html '<fn><p>str</p></fn><fn><p>str</p></fn><fn><p>str</p></fn>',
source, scope: {
fn: ->(&block) { "<fn>#{block.call}</fn>" },
list: [ "item1", "item2", "item3" ],
string: "str"
}
end
end

0 comments on commit 4ccd62e

Please sign in to comment.