Commit Graph

19 Commits

Author SHA1 Message Date
David Greenspan
dcdfea3a96 Improve <style> tag parsing and add tests 2015-03-26 19:07:30 -07:00
Sergio Garcia Murillo
bf58b49418 parse string content as raw string 2015-02-23 16:41:24 +01:00
David Greenspan
ab9cae6123 Fix Vincent’s textarea bug
Textarea would get same content as previous tag in a template, because the variable wasn’t cleared!

Needs test
2014-07-14 20:04:12 -07:00
David Greenspan
924f379870 Fix textarea HTML parsing
In modifying getContent, we neglected the fact that parseAttrs wraps arrays in HTML.Attrs.  Now we wrap arrays outside of parseAttrs near the code that modifies the attributes array for textarea contents.

Needs tests
2014-07-14 16:36:28 -07:00
David Greenspan
e0d6a2ef00 Make events and textareas work! 2014-06-30 17:49:03 -07:00
David Greenspan
a2552be8f8 HTMLTools: Kill "Special" as a TemplateTag wrapper
Remove the concept of a "Special" as a generalization of template tags in HTML parsing and the HTMLjs tree.  Just call something that's parsed by hooking the HTML parser a TemplateTag.  Don't wrap the return value of getSpecialTag (now getTemplateTag), just require that it be an instanceof HTMLTools.TemplateTag.

Spacebars.TemplateTag is now a subclass of HTMLTools.TemplateTag.  Both support `.toJS()`.  The same object returned by getTemplateTag is now inserted into the HTMLjs -- that is, the Spacebars compiler creates an HTMLTools.TemplateTag instead of it being created as a wrapper inside HTMLTools.  All usages of the words "special" or "special tag" are replaced with "template tag."
2014-04-24 10:18:02 -07:00
David Greenspan
1e7b91feaa Fix some tests 2014-04-22 15:55:56 -07:00
David Greenspan
43d672bd6a Use refactored html.js in "old" ui-package Blaze
Some failing tests, which are hopefully mostly just tests of the modified code that need to be ported.

The main work was replacing the use of pseudo-attributes $special and $dynamic with the new HTML.Attrs(...) / array representation.  Some functions were also rewritten to use Visitors (`toJS`, old `toHTML`/`toText`/`evaluateAttributes`, `replaceSpecials` in the compiler, but not `optimize` yet or `materialize`).

Create the "blaze-tools" package to hold toJS and other functions that are useful for template parsers/compilers that need to read or generate JS.
2014-04-22 13:47:57 -07:00
David Greenspan
1fcb33e61b parse.js: Add more comments 2014-03-22 09:57:46 -07:00
Avital Oliver
9ef97fc297 Better parsing for {{! }} comments
We now no longer check whether we're at a closing
HTML tag by peeking for "</" since that would fail
if there were a {{! }} comment directly before it.

Instead, we tokenize and then rewind. Presumably
this does have an effect on compilation time but it's
probably fine. An alternative would have been to
explicitly parse {{! }} comments rather than implicitly
skipping them before generally parsing tokens.
2014-03-21 22:08:02 -07:00
David Greenspan
cf4d9ad175 Let tags containing ':' self-close
They won't be rendered to HTML as self-closing, but that should be ok.

This is so that weird XML tags in SVG can be parsed.
2014-03-06 16:51:26 -08:00
David Greenspan
57f11cb961 Use HTMLTools namespace for all of html-tools 2014-03-03 15:51:35 -08:00
David Greenspan
f6c766ae06 Start html.js refactor; case-fold at compile time
- Start shrinking html.js down to the 150-line file it can be
- Move "proper case" logic to the template compiler; the tagName of an HTMLjs tag is now in proper case.  This is both for better performance and reduced size and complexity of runtime code (i.e. blaze.js).
- Start moving html-tools to the HTMLTools namespace
2014-03-03 15:51:35 -08:00
David Greenspan
599ac16632 Treat null/undefined/false attributes as absent
So, in HTML, the following are equivalent, and both mean that a checkbox is checked, because the `checked` attribute is present:

- `<input type="checkbox" checked>`
- `<input type="checkbox" checked="">`

We can't mess with that.  On the other hand, in Spacebars before this commit, the following would *also* result in the checkbox being checked, regardless of whether `foo` evaluates to null, undefined, false, or the empty string:

- `<input type="checkbox" checked={{foo}}>`
- `<input type="checkbox" checked="{{foo}}">`

With this commit, the checkbox will NOT be checked if `foo` evaluates to null, undefined, or false.

To achieve this:

- In HTMLjs, an attribute is considered absent if its value is "nully" after being fully evaluated (i.e. after expanding functions and components via HTML.evaluateDynamicAttributes / HTML.evaluate).  A nully value is one consisting of null, undefined, an empty array, or an array of those things.  `false` is not nully and renders as "false".  An empty string is not nully, and will "prop open" an attribute that would otherwise collapse into absence.

- Spacebars.mustache converts null, undefined, and false to null.  So if you use {{foo}} anywhere in a template and foo evaluates to "false", that gets to converted to a null in HTMLjs (which is ignored).  (true is rendered as "true".)

- When parsing HTML, an attribute that consists of *no tokens* becomes an empty string in the HTMLjs, which props open the attribute (unlike null or an empty array).  (Since comment tokens are stripped during tokenization, if there are only comments in an attribute value that counts as no tokens.)
2014-01-27 14:44:19 -08:00
David Greenspan
0e0d8f218c Better error message for <circle r={{r}}/>
Now we tell you to put a space before the slash.  HTML allows slash as part of a bare attribute value.
2014-01-25 19:41:21 -08:00
David Greenspan
27118d4b5a Improve error message for <input></input>
...and other cases where we see an unexpected HTML end tag.  We'd previously say "Expected EOF", among other things.
2014-01-06 15:41:51 -08:00
David Greenspan
b42112e3e6 tweaks 2014-01-06 14:37:13 -08:00
David Greenspan
7fadc29828 Start to make markdown work; avoid double UI.body 2013-12-11 22:32:48 -08:00
David Greenspan
b20119775f rename package "html" -> "html-tools" 2013-12-11 20:14:26 -08:00