-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly set file path for discovered tag + tests
- Loading branch information
1 parent
fc77a1a
commit 7c01a46
Showing
9 changed files
with
111 additions
and
14 deletions.
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
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions
17
...-compiler/createCompileContext-getTagDef/components/code-generator-only/code-generator.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,17 @@ | ||
const marked = require('marked'); | ||
|
||
function removeIndentation (str) { | ||
var indentMatches = /\s*\n(\s+)/.exec(str); | ||
if (indentMatches) { | ||
var indent = indentMatches[1]; | ||
str = str.replace(new RegExp('^' + indent, 'mg'), ''); | ||
} | ||
return str; | ||
} | ||
|
||
module.exports = function (el, codegen) { | ||
var bodyText = removeIndentation(el.bodyText); | ||
var builder = codegen.builder; | ||
var html = marked(bodyText); | ||
return builder.html(builder.literal(html)); | ||
}; |
17 changes: 17 additions & 0 deletions
17
test/autotests/api-compiler/createCompileContext-getTagDef/components/foo/code-generator.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,17 @@ | ||
const marked = require('marked'); | ||
|
||
function removeIndentation (str) { | ||
var indentMatches = /\s*\n(\s+)/.exec(str); | ||
if (indentMatches) { | ||
var indent = indentMatches[1]; | ||
str = str.replace(new RegExp('^' + indent, 'mg'), ''); | ||
} | ||
return str; | ||
} | ||
|
||
module.exports = function (el, codegen) { | ||
var bodyText = removeIndentation(el.bodyText); | ||
var builder = codegen.builder; | ||
var html = marked(bodyText); | ||
return builder.html(builder.literal(html)); | ||
}; |
4 changes: 4 additions & 0 deletions
4
test/autotests/api-compiler/createCompileContext-getTagDef/components/foo/marko-tag.json
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,4 @@ | ||
{ | ||
"body": "static-text", | ||
"preserve-whitespace": true | ||
} |
27 changes: 27 additions & 0 deletions
27
test/autotests/api-compiler/createCompileContext-getTagDef/expected.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,27 @@ | ||
"use strict"; | ||
|
||
var marko_template = module.exports = require("marko/src/vdom").t(), | ||
components_helpers = require("marko/src/components/helpers"), | ||
marko_registerComponent = components_helpers.rc, | ||
marko_componentType = marko_registerComponent("/marko-test$1.0.0/autotests/api-compiler/compileFileForBrowser.js/template.marko", function() { | ||
return module.exports; | ||
}), | ||
marko_renderer = components_helpers.r, | ||
marko_defineComponent = components_helpers.c; | ||
|
||
function render(input, out, __component, component, state) { | ||
var data = input; | ||
|
||
out.t("Hello "); | ||
|
||
out.t(data.name); | ||
|
||
out.t("!"); | ||
} | ||
|
||
marko_template._ = marko_renderer(render, { | ||
___implicit: true, | ||
___type: marko_componentType | ||
}); | ||
|
||
marko_template.Component = marko_defineComponent({}, marko_template._); |
1 change: 1 addition & 0 deletions
1
test/autotests/api-compiler/createCompileContext-getTagDef/template.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 @@ | ||
-- Hello ${data.name}! |
28 changes: 28 additions & 0 deletions
28
test/autotests/api-compiler/createCompileContext-getTagDef/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,28 @@ | ||
var path = require('path'); | ||
|
||
exports.check = function(marko, markoCompiler, expect, helpers, done) { | ||
var compiler = require('marko/compiler'); | ||
var templatePath = path.join(__dirname, 'template.marko'); | ||
|
||
var compileContext = compiler.createCompileContext(templatePath); | ||
|
||
var tagDef; | ||
|
||
tagDef = compileContext.getTagDef('foo'); | ||
expect(tagDef.filePath).to.equal(path.join(__dirname, 'components/foo/marko-tag.json')); | ||
expect(tagDef.dir).to.equal(path.join(__dirname, 'components/foo')); | ||
|
||
tagDef = compileContext.getTagDef('bar'); | ||
expect(tagDef.filePath).to.equal(path.join(__dirname, 'components/bar/index.marko')); | ||
expect(tagDef.dir).to.equal(path.join(__dirname, 'components/bar')); | ||
|
||
tagDef = compileContext.getTagDef('baz'); | ||
expect(tagDef.filePath).to.equal(path.join(__dirname, 'components/baz.marko')); | ||
expect(tagDef.dir).to.equal(path.join(__dirname, 'components')); | ||
|
||
tagDef = compileContext.getTagDef('code-generator-only'); | ||
expect(tagDef.filePath).to.equal(path.join(__dirname, 'components/code-generator-only/code-generator.js')); | ||
expect(tagDef.dir).to.equal(path.join(__dirname, 'components/code-generator-only')); | ||
|
||
done(); | ||
}; |