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

JavaScript Helper Creates Invalid JavaScript Tag #30

Closed
wants to merge 2 commits into from
Closed

JavaScript Helper Creates Invalid JavaScript Tag #30

wants to merge 2 commits into from

Conversation

sshaw
Copy link

@sshaw sshaw commented Nov 13, 2010

The JS element cannot be empty:

%= javascript 'script.js' 

generates:

<script src="script.js" type="text/javascript" />

For JS blocks the CDATA tags needs to be commented out:

%=javascript begin
    alert('Wont see this'); 
%end

generates:

<script type="text/javascript"><![CDATA[
    alert('Wont see this'); 
]]></script>

The same problem arises with the stylesheet tag.

I fixed both, but I'm somewhat confused about the logic dealing with CODE ref arguments. This seems unnecessary:

  if (@_ % 2 ? ref $_[-1] ne 'CODE' : ref $_[-1] eq 'CODE') {

What's the point of the false branch? It would handle odd cases like:

%=javascript 'xxx', sub { "var y = 123" }, begin
    var x = 456;
%end

Generating:

<script src="xxx" type="text/javascript">var y = 123</script>

Which ignores the earlier attempt to wrap the code in CDATA. The same logic is used for the stylesheet helper.

Maybe I'm missing something because I haven't looked at the template parsing code?

I removed this logic from my JS fix but not in the stylesheet fix.

@sshaw
Copy link
Author

sshaw commented Nov 13, 2010

Forgot to add newlines for inline blocks, see this commit: https://github.com/sshaw/mojo/commit/6a7fa10ccf1cee31a26822a4d7c8c5c4b01d242d

@kraih
Copy link
Member

kraih commented Nov 13, 2010

Thanks, applied.

This pull request was closed.
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.

2 participants