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

Use <erb> instead of <code> when parsing templates #105

Merged
merged 3 commits into from
Sep 4, 2013

Conversation

jhawthorn
Copy link

This changes the ERB template parser to use <erb> rather than <code> to designate code blocks in a template. This is a somewhat large change to functionality, but fixes several important issues which I can't imagine a better way to fix.

For example:

<%= render template: 'foo/bar' %>

Used to parse as:

<code loud> render template: 'foo/bar' </code>

But now parses as:

<erb loud> render template: 'foo/bar' </erb>

This fixes a number of problems that result from using <code>:

Unfortunately, this breaks any existing deface selectors looking for code, which are somewhat common. To be backwards compatible, selectors could be updated to cover both code and erb:

remove: "code:contains('my_method'), erb:contains('my_method')"

UPDATE: Now uses <erb loud> instead of <erb erb-loud>

This changes the ERB template parser to use `<erb>` rather than `<code>`
to designate code blocks in a template.

For example:

    <%= render template: 'foo/bar' %>

Used to parse as:

    <code erb-loud> render template: 'foo/bar' </code>

But not parses as:

    <erb erb-loud> render template: 'foo/bar' </erb>

This fixes a number of problems that result from using `<code>`:

* There may be </code> tags in the original ERB, which would be turned
  into `%>`
  (Fixes spree#101)

* Any <code> tags in the <head> of a document would be moved to the
  body, since <code> is a real HTML tag, and isn't allowed in the head.
  This happens in nokogiri under jRuby or libXML 2.9.0
  (Fixes spree#84, Fixes spree#100)

Unfortunately this breaks any existing deface selectors looking for
code, which are somewhat common. Selectors should be updated to cover
both code and erb:

    selector: "code:contains('my_method'), erb:contains('my_method')"
@BDQ
Copy link
Member

BDQ commented Sep 3, 2013

@jhawthorn - thanks for tackling this, I'm not against this change I think it's something that's required to solve the issues you've outlined.

I want to review this in detail, and get it merged.

What do you think about dropping the erb- from the erb-loud and erb-silent.

seems a little redundant to me?

@GeekOnCoffee
Copy link

How does haml then get represented?

@BDQ
Copy link
Member

BDQ commented Sep 3, 2013

@GeekOnCoffee haml gets converted to ERB before we remove the <% %> tags, so it's doesn't matter!

@cbrunsdon
Copy link
Member

I'm pro dropping the erb- from the erb erb-loud too.

@jhawthorn
Copy link
Author

What do you think about dropping the erb- from the erb-loud and erb-silent

Might as well, since we are already breaking selectors. I can add that this evening.

@GeekOnCoffee
Copy link

We should look at doing a new version of deface for this, as it's likely to break existing stores.

@swrobel
Copy link

swrobel commented Sep 4, 2013

oh sweet jesus YES! 💥

As we're breaking existing selectors anyways, we might as well remove
the redundant erb-.
@BDQ BDQ merged commit 328b0f2 into spree:master Sep 4, 2013
@BDQ
Copy link
Member

BDQ commented Sep 4, 2013

Merged, thanks for the contribution @jhawthorn

@swrobel - any feedback on this with respect to jruby?

@GeekOnCoffee - I agree, I've been holding back the 1.0.0 release until we got working jruby support so I think we could be ready for that now.

I'm going to add some log output for people using the older style code erb-loud / erb-silent in their selectors to try and cut down the WTF per minute when people upgrade.

@BDQ
Copy link
Member

BDQ commented Sep 4, 2013

I just pushed 1.0.0.rc4

@swrobel
Copy link

swrobel commented Sep 4, 2013

Will test as soon as I have time and update

@swrobel
Copy link

swrobel commented Sep 10, 2013

All good here! 💥

@BDQ
Copy link
Member

BDQ commented Sep 18, 2013

@swrobel - happy days!

@swrobel
Copy link

swrobel commented Oct 14, 2013

@BDQ it seems like 1.0.0.rc4 is stable for me ... any 1.0.0 final plans?

@binaryphile
Copy link

I added a separate issue, but I'll mention it here...can we get deface.heroku.com updated to offer the choice of 0.9 and 1.0 parsing? Thanks.

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

Successfully merging this pull request may close these issues.

None yet

7 participants