emcee
emcee copied to clipboard
Issue Using Erb Templating in HTML Imports
When I attempt to erb in an HTML import I get an error. For example, I have this in assets/components/post.html.erb
:
<polymer-element name="form-post">
<template>
<%= form_tag("/posts", method: 'post') do %>
<%= text_area_tag "post[body]" %>
<%= submit_tag %>
<% end %>
</template>
<script>
Polymer('form-post', {
ready: function() {
//...
}
});
</script>
</polymer-element>
When I attempt to load a page I get syntax error, unexpected ')'
. I have even attempted to do a blank form_tag
with no parameters:
<polymer-element name="form-post">
<template>
<%= form_tag %>
</template>
<script>
Polymer('form-post', {
ready: function() {
//...
}
});
</script>
</polymer-element>
in which case I get undefined method 'form_tag'
.
I'm not sure how erb-ing would work in templated HTML anyway. I was attempting to try it out. If erb-ing and HTML templating does not work in conjunction then that limits the capabilities of what you could do with frameworks like Polymer. Is there another way of doing this (besides stupid _helpers.html.erb, which doesn't really componentize -- it just renders things once)?
Are you using one of the release versions of Emcee (such as v1.0.3), or are you pulling directly from the repository?
In either case, processing components with erb is something we can look at adding.
It's the latest released gem (I didn't pull from github).
On Sun, Jul 13, 2014 at 6:11 PM, Andrew [email protected] wrote:
Are you using one of the release versions of Emcee (such as v1.0.3), or are you pulling directly from the repository?
In either case, processing components with erb is something we can look at adding.
— Reply to this email directly or view it on GitHub https://github.com/ahuth/emcee/issues/17#issuecomment-48854674.
This is a rough idea, but perhaps a helper such as polymer_element could be added so you could do something like
<%= polymer_element "my-tag" do |e| %>
<%= e.template_tag do |t| %>
<%= t.form_for @something do |f| %>
<%# Contents for @something %>
<% end %>
<% end %>
<% end %>
where the erb code inside of the template_tag
block is evaluated whenever you call the tag. Perhaps calling the polymer_element
tag block -- perhaps a web component-generator-agnostic name like element
-- generates a helper method that allows you to then call my-tag
in erb code.
Again, this is in no way highly thought out -- just listing ideas.
I'm all about listing ideas!
There has to be a way to process a file with erb, too. I'm just not super familiar with how erb files (whether they be views or css/js) get access to all the methods they need.
Never been a better time to learn, though!
@chriswins2much, Sorry for the delay, but I've finally started looking into this.
Right now, erb templating ~~doesn't~~ does work, as long as you don't use any of the view helpers. For example, <p><%= 2 + 2 %></p>
will correctly yield <p>4</p>
.
The problem is that the currently the components being processed don't have access to the view helpers such as form_tag
.
I definitely want to get this working, but I'm not sure how to do it. This gem does exactly what we need, but how it does it is pretty complicated. Hopefully there's an easier way.
Regarding your idea for a polymer_element
tag: I really like that idea. I'm thinking it'll be better to split that out to a seperate gem, though. For now, I want to keep emcee more generic and not tied to one library or framework.
hi, basically you would just need to make sure the binding that gets passed to the erb renderer is in the context of action view. or whatever context is required when you were doing this during the sprockets precompile step if you were using erb inside of a js or css asset.
it has been a while since i've looked into these internals so i could be referring to them incorrectly. I'm happy to take a crack at this though.
@datapimp, I'm honestly a little bit lost about how to do this, but we definitely need it. If you could take a crack at it, I'd appreciate it!
Hi, just wanted to update you guys. This is an issue that I believe should be fixed, but I just don't have the need or motivation to work on this gem anymore. Sorry!
I will accept pull requests, though.