8000 Erector should not turn helpers which return into helpers which emit · Issue #43 · erector/erector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Erector should not turn helpers which return into helpers which emit #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy sta 8000 tement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jkingdon opened this issue Jan 24, 2013 · 2 comments
Open

Comments

@jkingdon
Copy link
Contributor

When used with rails, erector currently wraps helper methods so that methods which return HTML, like link_to, will emit output instead.

This is not what rails developers expect, but it also creates problems which do not have easy solutions.

For example, consider the following HAML code to output some tabs with a vertical bar between the tabs.

- tabs = [link_to("File")]
- tabs << link_to("Edit") unless params[:readonly]
- tabs << link_to("Admin") if params[:admin]
= tabs.join(" | ").html_safe

This generates something like "File | Edit | Admin" (with the exact menu items depending on the parameters).

Translating to Erector looks like this:

tabs = [link_to("File")]
tabs << link_to("Edit") unless params[:readonly]
tabs << link_to("Admin") if params[:admin]
text tabs.join(" | ").html_safe

and the result is something like "FileEditAdmin |" because link_to emits rather than returning.

The rails helper to_sentence also suffers from this problems.

With the enclosed patch, the above erector code works.

diff --git a/lib/erector/rails3.rb b/lib/erector/rails3.rb
index 39a770b..ab9972b 100644
--- a/lib/erector/rails3.rb
+++ b/lib/erector/rails3.rb
@@ -48,7 +48,7 @@ module Erector
       def def_simple_rails_helper(method_name)
         module_eval <<-METHOD_DEF, __FILE__, __LINE__+1
           def #{method_name}(*args, &block)
-            text helpers.#{method_name}(*args, &block)
+            helpers.#{method_name}(*args, &block)
           end
         METHOD_DEF
       end
@ajb
Copy link
ajb commented Dec 18, 2013

I know this is 11 months ago, but for anyone else onlooking, you can also give this a shot:

tabs = [Widget.inline { link_to("File") } ]
tabs << Widget.inline { link_to("Edit") } unless params[:readonly]
tabs << Widget.inline { link_to("Admin") } if params[:admin]

tabs.each { |tab| widget tab }

@jkingdon
Copy link
Contributor Author

@adamjacobbecker: I think that version is missing the vertical bars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0