Skip to content

Commit

Permalink
Merge 65e145a into 73c1881
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Oct 16, 2013
2 parents 73c1881 + 65e145a commit c749cee
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/actions/wiring.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ wiring.prepend = function prepend(html, tagName, content) {
wiring.appendToFile = function appendToFile(path, tagName, content) {
var html = this.readFileAsString(path);
var updatedContent = this.append(html, tagName, content);
this.writeFileFromString(path, updatedContent);
this.writeFileFromString(updatedContent, path);
};

/**
Expand All @@ -95,7 +95,7 @@ wiring.appendToFile = function appendToFile(path, tagName, content) {
wiring.prependToFile = function prependToFile(path, tagName, content) {
var html = this.readFileAsString(path);
var updatedContent = this.prepend(html, tagName, content);
this.writeFileFromString(path, updatedContent);
this.writeFileFromString(updatedContent, path);
};

/**
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/append-prepend-to-file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><section><span></span></section></body></html>
58 changes: 58 additions & 0 deletions test/wiring.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,62 @@ describe('yeoman.generator.lib.actions.wiring', function () {

assert.equal(res, res2);
});

it('should append content in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section><span></span>TEST</section></body></html>';
assert.equal(wiring.append(html, 'section', 'TEST'), expected);
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'a'), expected);
});

it('should prepend content in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section>TEST<span></span></section></body></html>';
assert.equal(wiring.prepend(html, 'section', 'TEST'), expected);
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'p'), expected);
});

it('should replace content correctly', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section>TEST</section></body></html>';
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'r'), expected);
});

it('should delete content correctly', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body></body></html>';
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'd'), expected);
});

it('should append to files in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section><span></span>TEST</section></body></html>';
var filepath = path.join(this.fixtures, 'append-prepend-to-file.html');

fs.writeFileSync(filepath, html, 'utf-8');

wiring.appendToFile(filepath, 'section', 'TEST');

var actual = fs.readFileSync(filepath, 'utf-8').trim();

assert.equal(actual, expected);

fs.writeFileSync(filepath, html, 'utf-8');
});

it('should prepend to files in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section>TEST<span></span></section></body></html>';
var filepath = path.join(this.fixtures, 'append-prepend-to-file.html');

fs.writeFileSync(filepath, html, 'utf-8');

wiring.prependToFile(filepath, 'section', 'TEST');

var actual = fs.readFileSync(filepath, 'utf-8').trim();

assert.equal(actual, expected);

fs.writeFileSync(filepath, html, 'utf-8');
});
});

0 comments on commit c749cee

Please sign in to comment.