Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make return values works
  • Loading branch information
florentferry committed May 31, 2018
1 parent b782314 commit c10914b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## Upcoming release

- Block given to component now pass return values

## v2.0.0 (2018-04-22)

**Enhancements:**
Expand Down
1 change: 1 addition & 0 deletions features/component_generator.feature
Expand Up @@ -73,6 +73,7 @@ Feature: Component generator
"""
import "components/all/all";
import "components/bar/bar";
import "components/foo_bar/foo_bar";
import "components/namespaced";
import "components/required/required";
import "components/some_example/some_example";
Expand Down
@@ -0,0 +1 @@
<div class="foo-bar"><%= yield("Foo Bar") %></div>
1 change: 1 addition & 0 deletions fixtures/my_app/frontend/components/foo_bar/foo_bar.css
@@ -0,0 +1 @@
.foo-bar {}
1 change: 1 addition & 0 deletions fixtures/my_app/frontend/components/foo_bar/foo_bar.js
@@ -0,0 +1 @@
import "./foo_bar.css";
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module FooBarComponent
extend ComponentHelper
end
1 change: 1 addition & 0 deletions fixtures/my_app/frontend/components/index.js
@@ -1,5 +1,6 @@
import "components/all/all";
import "components/bar/bar";
import "components/foo_bar/foo_bar";
import "components/namespaced";
import "components/required/required";
import "components/world/world";
2 changes: 1 addition & 1 deletion lib/komponent/komponent_helper.rb
Expand Up @@ -2,7 +2,7 @@

module KomponentHelper
def component(component_name, locals = {}, options = {}, &block)
captured_block = proc { capture(&block) } if block_given?
captured_block = proc { |args| capture(args, &block) } if block_given?
Komponent::ComponentRenderer.new(
controller,
).render(
Expand Down
6 changes: 6 additions & 0 deletions test/komponent/komponent_helper_test.rb
Expand Up @@ -56,4 +56,10 @@ def test_helper_renders_with_block
%(<div class="bar">Bar</div>),
component('bar') { "Bar" }.chomp
end

def test_helper_renders_yield_args
assert_equal \
%(<div class="foo-bar">Foo Bar</div>),
component('foo_bar') { |x| x }.chomp
end
end

0 comments on commit c10914b

Please sign in to comment.