{"action":"created","issue":{"url":"https://api.github.com/repos/komposable/komponent/issues/78","repository_url":"https://api.github.com/repos/komposable/komponent","labels_url":"https://api.github.com/repos/komposable/komponent/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/komposable/komponent/issues/78/comments","events_url":"https://api.github.com/repos/komposable/komponent/issues/78/events","html_url":"https://github.com/komposable/komponent/issues/78","id":309482569,"number":78,"title":"How access the given block inside the helper","user":{"login":"nicolas-brousse","id":699216,"avatar_url":"https://avatars0.githubusercontent.com/u/699216?v=4","gravatar_id":"","url":"https://api.github.com/users/nicolas-brousse","html_url":"https://github.com/nicolas-brousse","followers_url":"https://api.github.com/users/nicolas-brousse/followers","following_url":"https://api.github.com/users/nicolas-brousse/following{/other_user}","gists_url":"https://api.github.com/users/nicolas-brousse/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolas-brousse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolas-brousse/subscriptions","organizations_url":"https://api.github.com/users/nicolas-brousse/orgs","repos_url":"https://api.github.com/users/nicolas-brousse/repos","events_url":"https://api.github.com/users/nicolas-brousse/events{/privacy}","received_events_url":"https://api.github.com/users/nicolas-brousse/received_events","type":"User","site_admin":false},"labels":[{"id":772285636,"url":"https://api.github.com/repos/komposable/komponent/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-28T18:36:34Z","updated_at":"2018-03-29T12:38:15Z","closed_at":null,"author_association":"NONE","body":"I'm looking for using the given block to my component inside the helper. But I didn't found how to retrieve the block.\r\n\r\nI used `block_given_to_component?` and that's works, but if I use `@block_given_to_component.call` but it returns me the content of my parent component.\r\n\r\nIs it a missing feature? Or a mistake of usage?\r\n\r\nI do some test by extended the `ComponentHelper` module like following:\r\n\r\n```rb\r\nmodule ComponentHelper\r\n  def yield_or_property(property_name)\r\n    if block_given_to_component?\r\n      block_given_to_component\r\n    elsif properties.key? property_name\r\n      properties[property_name]\r\n    else\r\n      raise ArgumentError, \"Missing required block component or parameter: #{property_name}\"\r\n    end\r\n  end\r\n\r\n  def property_or_yield(property_name)\r\n    if properties.key? property_name\r\n      properties[property_name]\r\n    elsif block_given_to_component?\r\n      block_given_to_component\r\n    else\r\n      raise ArgumentError, \"Missing required block component or parameter: #{property_name}\"\r\n    end\r\n  end\r\n\r\n  private\r\n\r\n  def block_given_to_component\r\n    @_block_given_to_component = @block_given_to_component.yield if block_given_to_component?\r\n  end\r\nend\r\n```\r\n\r\nAnd by using this method `yield_or_property(:text)` into the components views.\r\n\r\nBut it returns me a `LocalJumpError`."},"comment":{"url":"https://api.github.com/repos/komposable/komponent/issues/comments/377221928","html_url":"https://github.com/komposable/komponent/issues/78#issuecomment-377221928","issue_url":"https://api.github.com/repos/komposable/komponent/issues/78","id":377221928,"user":{"login":"nicolas-brousse","id":699216,"avatar_url":"https://avatars0.githubusercontent.com/u/699216?v=4","gravatar_id":"","url":"https://api.github.com/users/nicolas-brousse","html_url":"https://github.com/nicolas-brousse","followers_url":"https://api.github.com/users/nicolas-brousse/followers","following_url":"https://api.github.com/users/nicolas-brousse/following{/other_user}","gists_url":"https://api.github.com/users/nicolas-brousse/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolas-brousse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolas-brousse/subscriptions","organizations_url":"https://api.github.com/users/nicolas-brousse/orgs","repos_url":"https://api.github.com/users/nicolas-brousse/repos","events_url":"https://api.github.com/users/nicolas-brousse/events{/privacy}","received_events_url":"https://api.github.com/users/nicolas-brousse/received_events","type":"User","site_admin":false},"created_at":"2018-03-29T12:38:15Z","updated_at":"2018-03-29T12:38:15Z","author_association":"NONE","body":"Hello @florentferry,\r\n\r\nThe idea is to have component where I can pass property or block for the content like following:\r\n\r\n```rb\r\n# frontend/components/button/_button.html.slim\r\n- if link?\r\n  = link_to @href, link_attributes do\r\n    = yield_or_property(:text)\r\n\r\n- else\r\n  = button_tag button_attributes do\r\n    = yield_or_property(:text)\r\n```\r\n\r\n*Usage*\r\n\r\n```rb\r\n= c \"button\", text: \"My button text\"\r\n```\r\n\r\nor\r\n\r\n```rb\r\n= c \"button\" do\r\n  | My button text\r\n```\r\n\r\nIf I use `capture_block = capture(&@block_given_to_component) if block_given_to_component?` I have some wired result.\r\n![screen shot 2018-03-29 at 14 34 16](https://user-images.githubusercontent.com/699216/38089031-569852ca-335e-11e8-8d91-5549e7c510a4.png)\r\n\r\nI confirm that if I just simply use `yield` in the view I've not this issue.\r\n\r\nI'll give you a gist too"}}
{"actor":{"display_login":"nicolas-brousse"}}