Skip to content

Commit 95ebc33

Browse files
author
Aaron Chambers
committed
Merge pull request #9 from strange-studios/make-html-selectors-configurable
Make html selectors configurable
2 parents 21bdb49 + 33720a0 commit 95ebc33

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,25 @@ module.exports = {
2727
return context.project.root;
2828
},
2929
distDir: function(context) {
30-
return context.distDir;
30+
return context.distDir || 'tmp/deploy-dist';
31+
},
32+
jsonBlueprint: {
33+
base: {
34+
selector: 'base',
35+
attributes: ['href']
36+
},
37+
meta: {
38+
selector: 'meta[name*="/config/environment"]',
39+
attributes: ['name', 'content']
40+
},
41+
link: {
42+
selector: 'link',
43+
attributes: ['rel', 'href']
44+
},
45+
script: {
46+
selector: 'script',
47+
attributes: ['src']
48+
}
3149
}
3250
},
3351

lib/utilities/extract-index-config.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ function _get($, selector, attributes) {
2323

2424
module.exports = function(data) {
2525
var $ = cheerio.load(data.toString());
26-
var json = {
27-
base: _get($, 'base', ['href']),
28-
meta: _get($, 'meta[name*="/config/environment"]', ['name', 'content']),
29-
link: _get($, 'link', ['rel', 'href']),
30-
script: _get($, 'script', ['src'])
31-
};
26+
var blueprint = this.readConfig('jsonBlueprint');
27+
var json = {};
28+
29+
for(var prop in blueprint) {
30+
var value = blueprint[prop];
31+
32+
if (value.selector && value.attributes) {
33+
json[prop] = _get($, value.selector, value.attributes);
34+
}
35+
}
3236

3337
return RSVP.resolve(JSON.stringify(json));
3438
};

tests/unit/index-nodetest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('the deploy plugin object', function() {
5353
});
5454

5555
it('implements the correct hooks', function() {
56+
assert.equal(typeof plugin.configure, 'function');
5657
assert.equal(typeof plugin.didBuild, 'function');
5758
});
5859

tests/unit/lib/utilities/extract-index-config-nodetest.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,28 @@ describe('extract-index-config', function() {
1212
it('extracts the correct config', function() {
1313
var contents = fs.readFileSync(process.cwd() + '/tests/fixtures/dist/index.html');
1414

15-
return assert.isFulfilled(subject(contents))
15+
var plugin = {
16+
readConfig: function(key) {
17+
return {
18+
base: {
19+
selector: 'base',
20+
attributes: ['href']
21+
},
22+
script: {
23+
selector: 'script',
24+
attributes: ['src']
25+
}
26+
};
27+
}
28+
};
29+
30+
return assert.isFulfilled(subject.call(plugin, contents))
1631
.then(function(config) {
1732
var json = JSON.parse(config);
1833

19-
assert.equal(Object.keys(json).length, 4);
34+
assert.equal(Object.keys(json).length, 2);
2035

2136
assert.deepEqual(json.base[0], { href: '/' });
22-
assert.deepEqual(json.meta[0], { name: 'my-app/config/environment', content: 'some-config-values' });
23-
assert.deepEqual(json.link[0], { rel: 'stylesheet', href: 'assets/vendor.css' });
24-
assert.deepEqual(json.link[1], { rel: 'stylesheet', href: 'assets/app.css' });
2537
assert.deepEqual(json.script[0], { src: 'assets/vendor.js' });
2638
assert.deepEqual(json.script[1], { src: 'assets/app.js' });
2739
});

0 commit comments

Comments
 (0)