Skip to content

Commit 7993829

Browse files
committed
docs for new @key unescaping and keypath helper methods
1 parent 17e8f31 commit 7993829

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed

docs/edge/Keypaths.md.hbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ ractive = new Ractive({
6666
});
6767

6868
ractive.get( 'letters[0]' ); // returns undefined
69-
```
69+
```
70+
71+
## Escaping
72+
73+
While not ideal, sometimes properties of objects have `.`s in name e.g. `foo['bar.baz']`. Note that while numbers are supported in array notation, strings are not. To access a peypath with a literal `.` in one of the keys, you can escape it with a `\` e.g. `foo.bar\.baz`. Any keys accessible in the template will be unescaped, so if you're trying to use them with simple string concatenation to access a keypath with a `.` in it, you'll need to make sure you escape it first.

docs/edge/Migrating.md.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There is now support for linking data to extra keypaths in the model. This is pa
1616

1717
You can now use ES2015 object literal shorthand in templates e.g. `{ foo }` is equivalent to `{ foo: foo }`.
1818

19-
If you have object keys with `.`s in them, you can now escape them with a `\`. So if you have a `bar` object with a `foo.baz` property, it can be accessed with `bar.foo\.baz`. Keys and keypaths in the template are given as escaped paths so that they can be used directly with Ractive methods.
19+
If you have object keys with `.`s in them, you can now escape them with a `\`. So if you have a `bar` object with a `foo.baz` property, it can be accessed with `bar.foo\.baz`. Keypaths in the template are given as escaped paths so that they can be used directly with Ractive methods. There are also a few new static methods on `Ractive` to deal with escaping, unescaping, splitting, and joining keypaths.
2020

2121
`<textarea>`s now handle HTML content as plain text to match what happens in browsers. They can now also set up two-way binding with a single interpolator as content instead of using the value attribute e.g. `<textarea>\{{someBinding}}</textarea>` is equivalent to `<textarea value="\{{someBinding}}"></textarea>`.
2222

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Ractive.escapeKey()
3+
---
4+
5+
Escapes the given key so that it can be concatenated with a keypath string e.g. `foo.bar` => `foo\.bar`.
6+
7+
> ### Ractive.escapeKey( key )
8+
> Returns the properly escaped key.
9+
10+
> > ### **key** *`String`*
11+
> > The key to escape.
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Ractive.joinKeys()
3+
---
4+
5+
Joins the given keys into a properly escaped keypath e.g. `Ractive.joinKeys( 'foo', 'bar.baz' )` => `'foo.bar\.baz'`.
6+
7+
> ### Ractive.joinKeys( ...keys )
8+
> Returns the properly joined and escaped keypath.
9+
10+
> > ### **keys** *`Strings`*
11+
> > The keys to join into an escaped keypath.
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Ractive.splitKeypath()
3+
---
4+
5+
Splits the given keypath into an array of unescaped keys e.g. `Ractive.splitKeypath( 'foo.bar\.baz' )` => `[ 'foo', 'bar.baz' ]`.
6+
7+
> ### Ractive.splitKeypath( keypath )
8+
> Returns an array of unescaped keys.
9+
10+
> > ### **keypath** *`String`*
11+
> > The keypath to split into keys.
12+
13+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Ractive.unescapeKey()
3+
---
4+
5+
Unescapes the given key e.g. `foo\.bar` => `foo.bar`.
6+
7+
> ### Ractive.unescapeKey( key )
8+
> Returns the properly unescaped key.
9+
10+
> > ### **key** *`String`*
11+
> > The key to unescape.
12+

templates/edge/partials/left-nav.md.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@
119119
</ul>
120120
<h2>Static methods</h2>
121121
<ul>
122+
<li>{{{createLink 'Ractive.escapeKey()'}}}</li>
122123
<li>{{{createLink 'Ractive.extend()'}}}</li>
123124
<li>{{{createLink 'Ractive.getNodeInfo()'}}}</li>
125+
<li>{{{createLink 'Ractive.joinKeys()'}}}</li>
124126
<li>{{{createLink 'Ractive.parse()'}}}</li>
127+
<li>{{{createLink 'Ractive.splitKeypath()'}}}</li>
128+
<li>{{{createLink 'Ractive.unescapeKey()'}}}</li>
125129
</ul>
126130
<h2>Static properties</h2>
127131
<ul>

0 commit comments

Comments
 (0)