Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 56eb4d2

Browse files
Inject upgrade: take an injection object instead of string
1 parent 32740c5 commit 56eb4d2

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

‎package-lock.json‎

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
},
99
"devDependencies": {
1010
"eslint": "^4.7.1",
11+
"he": "^1.1.1",
1112
"json-stable-stringify": "^1.0.1",
12-
"mocha": "^3.5.3"
13+
"mocha": "^3.5.3",
14+
"underscore": "^1.8.3"
1315
},
1416
"scripts": {
1517
"test": "mocha --recursive test/unit/",

‎st.js‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,8 @@
607607
if (serialized) SELECT.$injected = JSON.parse(obj);
608608
} catch (error) { }
609609

610-
if (SELECT.$injected.length > 0) {
611-
// inject variables from 'this' context by name
612-
SELECT.$injected.forEach(function(key) {
613-
var o = {};
614-
o[key] = $context[key];
615-
SELECT.select(o);
616-
});
610+
if (Object.keys(SELECT.$injected).length > 0) {
611+
SELECT.select(SELECT.$injected);
617612
}
618613
return SELECT;
619614
},

‎test/unit/transform/inject.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var assert = require('assert');
2+
var ST = require('../../../st.js');
3+
var stringify = require('json-stable-stringify');
4+
var compare = function(actual, expected){
5+
assert.equal(stringify(actual), stringify(expected));
6+
};
7+
8+
describe("SELECT.inject", function() {
9+
it('underscore', function() {
10+
const _ = require('underscore')
11+
const data = {
12+
data: [1,2,3,3,3,4,4,4,4,5]
13+
}
14+
const res = ST.select(data).inject({_:_}).transformWith({
15+
"result": "{{_.uniq(data)}}"
16+
}).root()
17+
compare(res, {"result": [1,2,3,4,5]})
18+
})
19+
it('multiple libraries: underscore + he', function() {
20+
const _ = require('underscore')
21+
const he = require('he');
22+
const data = {
23+
data: [1,2,3,3,3,4,4,4,4,5]
24+
}
25+
const res = ST.select(data).inject({
26+
_:_,
27+
he: he
28+
}).transformWith({
29+
"_": "{{_.uniq(data)}}",
30+
"he": "{{he.decode('no man's land')}}"
31+
}).root()
32+
compare(res, {"_": [1,2,3,4,5], "he": "no man's land"})
33+
})
34+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /