Commit Graph

41 Commits

Author SHA1 Message Date
David Greenspan
3006bc72c6 Fix HTML.isConstructedObject and comment
The comments are not related to the fix, they are just for future
reference.

The fix is that having an "own" property named `constructor` should
not disqualify an object from being considered an "instance of some
class."  Instead, we should detect that an object like
`{constructor: ...}` is a plain object by noting that
`!(x instanceof x.constructor)`.
2015-08-13 12:52:46 -07:00
David Greenspan
93e35d1922 Fix external <script> tags in templates
Fixes #4415

See comment https://github.com/meteor/meteor/issues/4415#issuecomment-105688451 for explanation.
2015-05-27 10:39:33 -07:00
David Greenspan
180ef5408a Blaze READMEs 2014-10-27 12:57:16 -07:00
Hunter Trujillo
902308af39 Add HTML5 main tag to list of known element names. 2014-08-29 03:22:30 -06:00
Hunter Trujillo
a8b9cf2122 Alphabetize HTML.knownElementNames. 2014-08-29 03:21:21 -06:00
David Greenspan
14d64c6cfb Minor htmljs README changes 2014-06-23 10:19:18 -07:00
David Greenspan
3df4e95845 Merge branch 'devel' into blaze-refactor
Conflicts:
	packages/spacebars-tests/template_tests.js
	packages/ui/domrange.js
2014-05-27 13:38:59 -07:00
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
David Greenspan
eb34ed8a25 Throw error on invalid attribute objects 2014-05-06 13:49:43 -07:00
David Greenspan
310dcc5528 Finish documenting htmljs (except visitors) 2014-04-28 17:56:42 -07:00
David Greenspan
620adfb141 More docs 2014-04-28 10:36:15 -07:00
David Greenspan
55814cab4c htmljs work 2014-04-28 09:29:31 -07:00
David Greenspan
db6202c69c More HTMLjs docs 2014-04-27 19:16:47 -07:00
David Greenspan
30db75351f Start of new html.js readme (via doctool script) 2014-04-26 11:30:37 -07:00
David Greenspan
5daecb549e Comments 2014-04-24 12:33:19 -07:00
David Greenspan
d96ee0eab2 Rewrite Spacebars optimizer to use Visitors 2014-04-24 12:24:03 -07:00
David Greenspan
8edb5c2da0 Fix rest of tests (for new version of html.js)
Only tested on Chrome.

The "blaze" package is still separate but it shares even more code with "ui" now.
2014-04-23 00:47:57 -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
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
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
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
a6b3a431b2 further internal docs and cleanup 2014-01-03 17:27:17 -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
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
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
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
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
matt debergalis
b84f048c75 harmonize style: no parens after typeof 2012-02-10 15:43:12 -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