markbates / markbates/coffeebeans

Add CDATA section to coffee_script_tag

Open
#10 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
228
Forks
5
PR merge metrics
No merged PRs in 30d

Description

Is there any reason for `coffee_script_tag` to not render JS inside a CDATA section as `javascript_tag` would do?

``` erb
<%= javascript_tag do%>
<%= coffee_script do %>

if 2 < 0
alert('uh?')

<% end %>
<% end %>
```

the code above would render the following html that is friendly to any xml/html parser:

``` html


//<![CDATA[

(function() {

if (2 < 0) {
alert('uh?');
}

}).call(this);

//]]>

```

instead of doing the same `coffee_script_tag` renders the code without wrapping it in `CDATA` turning html to not be well formed anymore (eg. `2 < 0`):

``` erb
<%= coffee_script_tag do%>
if 2 < 0
alert('uh?')
<% end %>
```

``` html

(function() {

if (2 < 0) {
alert('uh?');
}

}).call(this);

```

Thanks

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the coffee_script_tag helper and compare its output with javascript_tag, as shown in the issue examples. Check how the generated CoffeeScript becomes JavaScript, then make the rendered script use the CDATA wrapping demonstrated in the expected HTML. Done means expressions containing < produce well-formed HTML.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, javascript, ruby
Domain
web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.