forked from marko-js/marko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes marko-js#655 - Implement renderToString in the browser.
- Loading branch information
1 parent
f957847
commit 8cdb09a
Showing
10 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/autotests/components-browser/component-renderToString-callback-sync/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var helloComponent = require('./components/hello'); | ||
|
||
module.exports = { | ||
onMount: function() { | ||
var self = this; | ||
helloComponent.renderToString({ | ||
name: this.input.name | ||
}, function (error, html) { | ||
if (error) { | ||
self.emit('renderError', error); | ||
} else { | ||
self.emit('html', html); | ||
} | ||
}); | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
...ts/components-browser/component-renderToString-callback-sync/components/hello/index.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<test-async name=input.name/> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
...mponents-browser/component-renderToString-callback-sync/components/test-async/renderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = function(input, out) { | ||
var asyncOut = out.beginAsync(); | ||
setTimeout(function() { | ||
asyncOut.write('[async] ' + input.name); | ||
asyncOut.end(); | ||
}, 10); | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/autotests/components-browser/component-renderToString-callback-sync/index.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<div name=input.name/> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
test/autotests/components-browser/component-renderToString-callback-sync/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var expect = require('chai').expect; | ||
|
||
module.exports = function(helpers, done) { | ||
var component = helpers.mount(require('./index'), { | ||
name: 'john' | ||
}); | ||
|
||
component.on('html', function(renderedHtml) { | ||
expect(renderedHtml).to.equal('<div>[async] john</div>'); | ||
done(); | ||
}); | ||
|
||
component.on('error', function (error) { | ||
done(error); | ||
}); | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/autotests/components-browser/component-renderToString/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var helloComponent = require('./components/hello'); | ||
|
||
module.exports = { | ||
onMount: function() { | ||
this.renderedHtml = helloComponent.renderToString({ | ||
name: this.input.name | ||
}); | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/autotests/components-browser/component-renderToString/components/hello.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="hello"> | ||
<div>${input.name}</div> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
test/autotests/components-browser/component-renderToString/index.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<hello name=input.name/> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
test/autotests/components-browser/component-renderToString/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var expect = require('chai').expect; | ||
|
||
module.exports = function(helpers) { | ||
var component = helpers.mount(require('./index'), { | ||
name: 'john' | ||
}); | ||
|
||
expect(component.renderedHtml).to.equal('<div class="hello"><div>john</div></div>'); | ||
}; |