Skip to content

Commit 4176889

Browse files
m4dzeddyerburgh
authored andcommitted
feat(haml): add support for haml (#26)
1 parent 4834985 commit 4176889

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ vue-jest compiles the script and template of SFCs into a JavaScript file that Je
5757

5858
- **pug** (`lang="pug"`)
5959
- **jade** (`lang="jade"`)
60+
- **haml** (`lang="haml"`)

lib/compilers/haml-compiler.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var ensureRequire = require('../ensure-require.js')
2+
const throwError = require('../throw-error')
3+
4+
module.exports = function (raw) {
5+
var html
6+
ensureRequire('hamljs', 'hamljs')
7+
var haml = require('hamljs')
8+
try {
9+
html = haml.render(raw)
10+
} catch (err) {
11+
throwError(err)
12+
}
13+
return html
14+
}

lib/template-compiler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var vueCompiler = require('vue-template-compiler')
33
var transpile = require('vue-template-es2015-compiler')
44
var compilePug = require('./compilers/pug-compiler')
55
var compileJade = require('./compilers/jade-compiler')
6+
var compileHaml = require('./compilers/haml-compiler')
67
const throwError = require('./throw-error')
78

89
function getTemplateContent (templatePart) {
@@ -12,6 +13,9 @@ function getTemplateContent (templatePart) {
1213
if (templatePart.lang === 'jade') {
1314
return compileJade(templatePart.content)
1415
}
16+
if (templatePart.lang === 'haml') {
17+
return compileHaml(templatePart.content)
18+
}
1519
return templatePart.content
1620
}
1721

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"eslint-plugin-html": "^3.1.1",
3636
"eslint-plugin-vue": "^2.1.0",
3737
"eslint-plugin-vue-libs": "^1.2.0",
38+
"hamljs": "^0.6.2",
3839
"jade": "^1.11.0",
3940
"jest": "^20.0.4",
4041
"pug": "^2.0.0-rc.3",

0 commit comments

Comments
 (0)