Skip to content
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 statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully implement ERB-like syntax (eRuby) #9

Open
e2b opened this issue Jan 28, 2013 · 4 comments
Open

Fully implement ERB-like syntax (eRuby) #9

e2b opened this issue Jan 28, 2013 · 4 comments

Comments

@e2b
Copy link
Collaborator

e2b commented Jan 28, 2013

See ERB in the Ruby documentation:

ERB recognizes certain tags in the provided template and converts them based on the rules below:

<% Ruby code -- inline with output %>
<%= Ruby expression -- replace with result %>
<%# comment -- ignored -- useful in testing %>
% a line of Ruby code -- treated as <% line %> (optional -- see ERB.new)
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replace with <% or %> respectively

This also features some escaping for ERB tags.

The trim_mode parameter is interesting, too:

If trim_mode is passed a String containing one or more of the following modifiers, ERB will adjust its code generation as listed:

%  enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
>  omit newline for lines ending in %>
@ollym
Copy link
Owner

ollym commented Jan 28, 2013

I like all of this 👍

@e2b
Copy link
Collaborator Author

e2b commented Jan 28, 2013

Is there anything missing? I've also found out using -%> (note the added minus sign) as end tag would omit a following newline while the old use of <%- and -%> (don't insert spaces before and after the output) seems deprecated. In the current source it's an option for the trim_mode:

#     -  omit blank lines ending in -%>

Should the syntax require a whitespace after/before the start/end tag? E.g. <%= foo %> will work, while <%=foo%> will not be recognized? Do you know how this is implemented in Ruby?

@ollym
Copy link
Owner

ollym commented Jan 28, 2013

I've never used -%> in ERB templates. Seems pointless

@e2b
Copy link
Collaborator Author

e2b commented Feb 4, 2013

I might still implement the minus option since it shouldn't be a big deal and it's deactivated by default (as long as not specified in trim_mode).

Should trim_mode be a new property within the options object or within the options.tags sub-object?

parrot.render(input, {
  trim_mode: undefined, // default
  ...
});
parrot.render(input, {
  tags: {
    trim_mode: undefined, // default
    ...
  }
});

The first one has less nesting and might be better if the tags aren't changed often (or custom tag support is dropped / unofficial in the future). The second one is obviously better categorized.

openstack-gerrit pushed a commit to openstack-archive/cookbook-openstack-network that referenced this issue Apr 20, 2014
After this https://review.openstack.org/#/c/85168/ code review
merged, the neutron services are failed to start becuase of -%>
in neutron.conf.rb template, -%> as end tag would omit a
following newline. please refer to
https://github.com/ruby/ruby/blob/trunk/lib/erb.rb
ollym/parrot#9 (comment)

Change-Id: Ia35a51fc67c2305be6bdc975c924d421ba4f1313
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