Commit Graph

47 Commits

Author SHA1 Message Date
David Glasser
2db7490db5 Fix IE8 minification bug
The minifier changed the two uses of HTMLTag into two different symbols:

  var n = function r() {
    var t = this instanceof e.Tag ? this : new r(), n = 0, o = arguments.length && arguments[0];
    return o && "object" == typeof o && o.constructor === Object && (t.attrs = o, n++),
    n < arguments.length && (t.children = Array.prototype.slice.call(arguments, n)),
    t;
  };
  return n.prototype = new e.Tag(), n.prototype.constructor = n, n.prototype.tagName = t,
  n;

Then, IE8 apparently actually creates two separate objects for 'n' and
'r'; see #3 at http://kiro.me/blog/nfe_dilemma.html

So just because n.prototype is an e.Tag doesn't make r.prototype a e.Tag

This means that `new r() instanceof e.Tag` is false, and so the first
line of the function leads to infinite recursion.

I'm not sure if this is an uglify bug as well; dealing well with
multiple declarations of the same function may be out of spec.

Fixes #2037.
2014-05-21 16:19:43 -07:00
Avital Oliver
ca46407e5d Properly clean up autoruns on UI.toHTML.
The prior commit didn't stop components of type
`Spacebars.With` correctly.
2014-04-17 03:00:05 -07:00
Avital Oliver
797a080e7f Fix UI.toHTML on templates containing {{#with}}
Originally reported at
https://github.com/meteor/meteor/issues/2007#issuecomment-40530195
2014-04-17 03:00:05 -07:00
David Greenspan
6454067e66 Make Blaze packages internal 2014-04-02 09:56:33 -07:00
David Greenspan
09b9b4adba Tower of hacks to get shark deps right
The implementation is getting really, really ugly.  Just want to get to correctness.

We now stop autoruns not just when started from `materialize` but also `toHTML`, `toText`, and `evaluate`, which is important for HTML attributes.  Reactive regions inside attributes aren't individually autorun; the design is that their dependencies will cause the entire attribute updater to be invalidated and re-run.  In other words, HTML.toText doesn't have internal re-runs but it does register dependencies on the current computation.  In fact, however, the presence of emboxedValues means that there *are* autoruns that need to be stopped, even in toText and evaluate.

The hack where we define a `.materialized()` callback for the benefit of UI.With falls short, because toText et al. don't call it.  The current workaround is yet worse hacks in htmljs (stopWithLater).

Finally, the fact that UI.If, UI.Unless, and Spacebars.include return reactive closures that close over emboxedValues is a problem when those same closures are reused in recalculating attributes.  The intent was that recalculating attributes should tear down any boxes internal to the attribute calculation and start fresh, but when we reuse closures that close over boxes, we are reusing boxes, and if those boxes have been stopped we lose correctness.  The ugly hack to get this to work for now is to have the boxes in If, Unless and include not be per reactive closure but per currentComputation, i.e. per autorun.  Since toText et al. don't normally autorun reactive closures, we add an autorun so that they get their own Computation objects.  This hack is supported by UI.namedEmboxValue and callReactiveFunction.

The good news is that the right answer is buried in here somewhere.
2014-03-21 03:54:28 -07:00
David Greenspan
5e85c32ea6 Move asciiLowerCase to 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
b26f0271a0 Rename HTML.evaluate{Dynamic,}Attributes 2014-01-27 14:44:19 -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
0a6e9c984f Make tag.toText slightly more correct 2014-01-20 14:17:29 -08:00
David Greenspan
6a4fb19a80 Use correct node.toHTML arguments
for clarity
2014-01-20 14:07:45 -08:00
Avital Oliver
04ec013674 Allow including templates within {{#markdown}}
The docs app now works. Fixes #1736.
2014-01-20 00:14:17 -08:00
David Greenspan
40d4d9cd84 document html-tools 2014-01-06 21:25:40 -08:00
David Greenspan
32b60177a1 Remove source files from readme 2014-01-06 17:34:42 -08:00
David Greenspan
b9877c7a53 List source files in htmljs readme 2014-01-06 17:26:31 -08:00
David Greenspan
e04edf1ca0 Finish documenting htmljs package 2014-01-05 17:29:01 -08:00
David Greenspan
47596a28ad minor edits 2014-01-05 10:30:44 -08:00
David Greenspan
a6b3a431b2 further internal docs and cleanup 2014-01-03 17:27:17 -08:00
David Greenspan
7710a77270 start of htmljs README 2014-01-02 16:56:31 -08:00
David Greenspan
ddb0f6170f Make htmljs Tag constructor IE 8 safe
To make tags print nicely in the console, we dynamically create constructor functions of the form `function DIV() { ... }`, which is still the only thing Chrome responds to.  Modern browsers interpret a function expression of this form as exposing a symbol `DIV` only to lexical scope of the *body* of the function.  IE 8 does something else -- I forget what exactly, but it's not good.  Also I think `new Function("... code ...")` captures scope in IE 8, so we need to be careful what sort of names we inject.
2013-12-17 18:32:51 -08:00
David Greenspan
250aa0a8ed make #each work in textareas 2013-12-11 19:55:04 -08:00
David Greenspan
218caaf004 Fix spacebars optimizer
It was accidentally disabled, and it tried to optimize SVG, invalidly.
2013-12-11 15:25:11 -08:00
David Greenspan
683fa46ab4 Basic SVG support
Also: allow numbers and booleans in htmljs
2013-12-11 14:33:21 -08:00
David Greenspan
35341b44b4 support basic tag in TEXTAREA 2013-12-10 12:57:42 -08:00
David Greenspan
b5b292ddf6 pass tests 2013-12-10 11:30:17 -08:00
David Greenspan
e954329334 bug fixes 2013-12-09 23:22:51 -08:00
David Greenspan
556870983e more tests and fixes
- moved tojs.js into spacebars

Some failing tests in `spacebars-tests` and `ui`

```
meteor test-packages spacebars htmljs html spacebars-tests ui
```
2013-12-09 23:12:12 -08:00
David Greenspan
cb2d331dbf seems to work (not fully tested) 2013-12-09 22:52:20 -08:00
David Greenspan
87921cf178 Redo the HTML representation; needs debugging
Puts HTML.Tag, toHTML, and toJS in the "htmljs" package.
Introduces toText for textareas and attributes.
Changes dynamic attribute representation.
Instances of HTML.Tag, HTML.CharRef, etc. are now "instanceof".

Once this code seems to work, we'll move packages around further.
- "htmljs" is the runtime; can even take out "tocode.js"
- "html-tools" (new package) takes over for "html".

Then, port the tests.
2013-12-09 22:23:27 -08:00
David Glasser
4b3cb9d305 Rename api.exportSymbol -> api.export. 2013-07-25 18:54:43 -07:00
David Glasser
bc8f251cd1 oops, remove debugging code 2013-07-25 18:54:42 -07:00
David Glasser
e4c568b1e1 Merge exports list with package variables in slice JSON.
This implies that all exports are package variables, which made underscore,
jquery, and htmljs (which explicitly assigned to fields on the global variable)
break. We now properly encapsulate these packages (except for window.jQuery,
which we let sneak out because bootstrap wants it).  This means that packages
that want _ need to use underscore, and packages that want $ need to use jquery.
Also, you can't use _ in minimongo $where any more (matching mongod).
2013-07-25 18:54:42 -07:00
David Glasser
9f38258b54 Drop all @export lines. Add api.exportSymbol instead. 2013-07-25 18:54:40 -07:00
David Glasser
6b48e8bd8a stuff that doesn't have conflicts 2013-05-13 11:51:50 -07:00
David Glasser
8dbee56e77 Add .gitignore to package directories to match linker branch.
This way switching between linker and devel doesn't leave you with lots of junk
in git status.
2013-05-13 10:57:37 -07:00
David Glasser
5a5204e3a4 Remove closures around package files. (hint: git blame -w)
The bundler now adds closures around client files and the server adds closures
around server files.
2013-03-19 15:13:53 -07:00
David Greenspan
d734492e59 gitignore .meteor directories in packages 2012-04-17 20:02:00 -07:00
Geoff Schmidt
76c57526f7 rework public API for defining tests 2012-03-02 05:22:40 -08:00
Geoff Schmidt
cab5afbb91 move test reporting functions out of globals 2012-03-02 03:57:30 -08:00
matt debergalis
b84f048c75 harmonize style: no parens after typeof 2012-02-10 15:43:12 -08:00
Nick Martin
7f133d37b5 Move htmljs test. This was missed as it happened at the same time as the test migration. 2012-01-27 20:03:59 -08:00
Geoff Schmidt
d1d5604976 Refactor bundler; new package API 2012-01-27 20:02:26 -08:00
Geoff Schmidt
e5eb42e55c Refactor package API/bundler 2012-01-27 20:02:24 -08:00
David Greenspan
ad55fc8cb9 fix html.js for IE (support "style"); change template_test to use Meteor._fragmentToHtml 2012-01-27 20:02:24 -08:00
Geoff Schmidt
d73a647bdd jquery cleanups. also, fix htmljs bug. 2011-12-09 23:15:14 -08:00
Geoff Schmidt
ce565dcaea kill basics package 2011-12-07 22:28:43 -08:00
Nick Martin
d69c2d1f19 Initial import from old busted repo. 2011-11-17 18:35:20 -08:00