Commit Graph

6078 Commits

Author SHA1 Message Date
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
7c58b08f53 Fix an apparent typo 2014-01-27 14:44:19 -08:00
David Greenspan
54a2423acb Don't ignore falsy helpers
We were weirdly ignoring helpers that were falsy constants, so in `Template.main.foo = 0` / `{{foo}}` you'd get nothing, while if you did `Template.main.foo = function () { return 0; }` you would get "0".
2014-01-27 14:44:19 -08:00
David Greenspan
43cb4f8cc8 Rename tests in html-tools package to html-tools 2014-01-27 14:44:19 -08:00
David Glasser
6471dce8fa Merge branch 'devel' into shark 2014-01-27 13:58:11 -08:00
David Glasser
830aa7036c Merge branch 'new-kexec' into devel 2014-01-27 13:56:44 -08:00
David Glasser
8f4963ecd2 Use new exec 2014-01-27 13:52:54 -08:00
David Glasser
291c2ecad7 Upgrade kexec, drop shell-quote
We only used shell-quote to workaround kexec's lack of a feature added
in this version.
2014-01-27 09:52:50 -08:00
Avital Oliver
d46a5e11b1 Correctly check for reserved template names 2014-01-26 11:52:27 -08:00
Avital Oliver
70aa948634 Isolate attributes on <p {{attrs}}>
A helper can return an object with a set of element attributes via
`<p {{attrs}}>`. When it re-runs due to a dependency changing the
value for a given attribute might stay the same. Test that the
attribute is not set on the DOM element.
2014-01-26 11:52:26 -08:00
Avital Oliver
72a5d4282c Correct helper return value isolation
- When helpers return SafeStrings, compare their underlying
  strings.
- When helpers return objects (such as for dynamic attributes),
  never isolate. The objects may have been mutated directly.
  AttributeHandler ends up only affecting real changes.
2014-01-26 11:52:26 -08:00
Avital Oliver
1223783e14 Isolate return values from helpers
Do the appropriate equality check for three cases:
(1) helpers in text nodes
(2) helpers in element attributes
(3) helpers in dynamic template inclusion

Also, assert that helpers passed to template inclusion indeed
return components or null.
2014-01-26 11:52:26 -08:00
Avital Oliver
63319c8e6d Test that helper return values are isolated
More specifically, a helper re-runs and its return value hash't
changed, nothing should change in the DOM. Test this for:
(1) helpers in text nodes
(2) helpers in element attributes
(3) helpers in dynamic template inclusion
2014-01-26 11:52:26 -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 Glasser
d30bb79498 Ensure crossbar callbacks not called after stop
Hopefully fixes #1767.
2014-01-23 23:23:30 -08:00
David Glasser
fca2966676 Simplify crossbar by making it synchronous
All existing listener callbacks were already calling complete()
synchronously, so this should not be a functional change.

This allows us to also eliminate the callback from crossbar.fire().

This in turn allows us to eliminate the `proxy_write` in
Meteor.refresh. The only purpose of that write was to keep the current
write fence open until fire's async callback got called; now that fire
works synchronously, it's not necessary!  (This relies on the fact that
write fences never get armed while they are the current write fence,
which now has an assertion.)
2014-01-23 23:13:42 -08:00
David Glasser
d868325b83 Don't yield in oplog entry handler 2014-01-23 21:53:51 -08:00
David Glasser
8eca012c32 Minor optimizations to new _IdMaps 2014-01-23 21:28:21 -08:00
David Greenspan
fc955af5c0 Require template tag kw args to be at end 2014-01-23 20:45:09 -08:00
David Glasser
7645cb399e Merge branch 'dev-bundle-http-proxy-1' into devel 2014-01-23 15:37:58 -08:00
David Glasser
97ec2d3948 Update to newer http-proxy API
Take out workaround that's been incorporated into the branch we're using
2014-01-23 14:40:21 -08:00
David Glasser
90b7489e7f Add $USE_TEST_DEV_BUNDLE_SERVER 2014-01-23 13:40:02 -08:00
David Glasser
d4e0cff766 Use a fork of http-proxy with two PRs 2014-01-23 12:23:16 -08:00
David Glasser
a7d10d650d Update Node to 0.10.25. Remove bug workaround. 2014-01-23 12:15:29 -08:00
David Glasser
8354fe403b Bump dev bundle version. 2014-01-23 12:09:40 -08:00
David Glasser
4f34ac0d6e Various dev bundle upgrades
* http-proxy: 1.0.1 (from a pre-release fork of 1.0)
* Node: 0.10.24 (from 0.10.22)
* semver: 2.2.1 (from 2.1.0)
* request: 2.33.0 (from 2.27.0)
* fstream: 0.1.25 (from 0.1.24)
* tar: 0.1.19 (from 0.1.18)
* eachline: 2.4.0 (from 2.3.3)
* source-map: 0.1.31 (from 0.1.30)
* source-map-support: 0.2.5 (from 0.2.3)
* mongo: 2.4.9 (from 2.4.8)
* openssl in mongo: 1.0.1f (from 1.0.1e)

Have not yet updated the various minimum Node version requirements.
2014-01-23 12:09:40 -08:00
Avital Oliver
23405cd5d4 Don't allow templates named 'content'
Trying to include them later with {{> content}}
fails. We could disallow the other built-ins,
eg 'if' and 'elseContent' but sounds less likely
that users will try to define templates with
those names, and this simple change lets us
not duplicate code.
2014-01-22 19:35:44 -08:00
Slava Kim
8b28f1fab6 Change phase and register a fact in the same place 2014-01-22 17:45:24 -08:00
Avital Oliver
ae67643a3f Make docs work on shark 2014-01-22 16:34:56 -08:00
Avital Oliver
91cce88c91 Make {{#if content}} work.
This lets you check whether a template was invoked via
inclusion or as a block helper. An example is the
api_box template in docs.
2014-01-22 16:34:45 -08:00
Slava Kim
2952edc73a Merge branch 'oplog-selector-modifier-operators' into devel
- Cache the matchingDocument on Matcher
- Minor cosmetic changes
2014-01-22 15:30:39 -08:00
Slava Kim
9971e5b298 Glasser's comments
- use startsWith for strings rather than x.indexOf(y) && x[y.length] === '.'
- more comments with examples
- consistent naming isSimple => simpleRange, simpleInequality, etc
2014-01-22 15:29:13 -08:00
Slava Kim
1be7e5a900 Initialize Matcher._matchingDocument in the constructor.
To declare it explicitly to humans and JITs.
2014-01-22 14:17:19 -08:00
Slava Kim
4c3c1389ef Some additional facts about oplog-driver 2014-01-21 18:51:08 -08:00
David Glasser
16b23ecb38 Close proxy/server websockets on client errors
Previously, certain errors on the client/proxy socket would result in
the proxy keeping the websocket to the server open forever rather than
closing it.  For example, disconnecting the client from the internet
without a graceful shutdown. This could easily be reproduced with any
app using `facts`, eg https://github.com/tarangp/test-observers.
Run the app, connect locally with one browser, connect from a second
computer, observe sessions going to 2, disconnect the second computer.
With this commit, sessions will go back to 1 in about a minute. Without
it, it never will.

This particular fix is not very compelling, since it uses undocumented
features of the stream interface. I will file an issue with the
node-http-proxy project tonight asking how we're supposed to do this.

This addresses #1769.  I'll close that once we have a more compelling
fix, and once the similar bug is fixed in the proxies used in the
`meteor deploy` server and in Galaxy.
2014-01-21 18:17:08 -08:00
Slava Kim
1c7e222c63 Refactor matchingDocument into separate method on Matcher's prototype, cache it. 2014-01-21 14:02:23 -08:00
Sashko Stubailo
45ccc12970 Make default accounts-ui styling simpler/flatter 2014-01-21 13:57:52 -08:00
Slava Kim
2a8105a6aa Merge branch 'oplog-selector-modifier-operators' into devel
Brings optimizations to the oplog-tailing:
- analyze modifications coming from oplog and skip uneccessary fetches for certain $-operators
  + ranges of numbers { $gt: 5, $lt: 33 }
  + inequlities { $not: 5 } or { $nin: [ 1, 3, 4 ] } for scalars
  + equalities { $in: [ 2, 4, 6 ] } for scalars
2014-01-21 13:26:25 -08:00
David Greenspan
0a93fa46b9 Organize spacebars-compiler.js 2014-01-21 12:28:23 -08:00
David Greenspan
d0388dc30b Make spacebars compiler shorter 2014-01-20 19:48:24 -08:00
David Greenspan
7be0250867 Fix CRLF handling in HTML tokenizer
We would choke on CR line endings, because we didn't implement the preprocessing step of converting CR(LF)? to LF.  Now we correctly convert (or ignore) CR inside tags, in text nodes, in attributes, and in comments.
2014-01-20 19:19:07 -08:00
David Greenspan
b2522aa1b4 re-org getSpecialTag into TemplateTag
...specifically into TemplateTag.parseCompleteTag.

Also document TemplateTag more.
2014-01-20 15:52:12 -08:00
Avital Oliver
f440a117ef Test an edge-case with template inclusion in {{#markdown}} 2014-01-20 14:24:28 -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
b3e31fc968 Merge branch 'shark-make-docs-work' into shark 2014-01-20 00:16: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
Avital Oliver
ede2e80d48 {{#better_markdown}} -> {{#markdown}} 2014-01-20 00:03:01 -08:00
Slava Kim
7a528be92d Polish canBecomeTrueByModifier operators optimization
- Fix the pruning `expectedScalarIsObject`
- Limit $gt,$lt,... to numbers only (since there needs to be more logic to support dates and strings later)
- Add comments on dubious parts
2014-01-17 13:28:14 -08:00
Slava Kim
ccdbe31356 Fallback to "YES" in a case of noticeable floating point numbers underflow 2014-01-17 13:28:14 -08:00