Skip to content

Commit d96c0b6

Browse files
author
Jeff Escalante
committed
es6 fixes, standard.js style
1 parent 74dec46 commit d96c0b6

File tree

13 files changed

+41
-146
lines changed

13 files changed

+41
-146
lines changed

index.js

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
1-
// ------------------------------------
2-
// #POSTHTML - EXPS
3-
// ------------------------------------
4-
5-
'use strict'
6-
7-
let get = require('./lib/get')
8-
let locals = require('./lib/local')
9-
10-
let attrs = require('./lib/attrs')
11-
let exps = require('./lib/exps')
12-
let pipe = require('./lib/pipe')
13-
let each = require('./lib/each')
14-
let partial = require('./lib/part')
15-
// let condition = require('./lib/if')
16-
17-
exports = module.exports = function (options) {
18-
options = options || {}
1+
const attrs = require('./lib/attrs')
2+
const exps = require('./lib/exps')
3+
const pipe = require('./lib/pipe')
4+
const each = require('./lib/each')
5+
const partial = require('./lib/part')
196

7+
exports = module.exports = function (options = {}) {
208
if (typeof options.locals === 'string') {
219
options.locals = require(options.locals)
2210
}
2311

24-
let style = options.style || '{'
25-
let local = options.locals || {}
12+
const style = options.style || '{'
13+
const local = options.locals || {}
2614

2715
return function PostHTMLExps (tree) {
2816
tree.walk((node) => {
29-
let attributes = node.attrs || {}
30-
let content = node.content || []
17+
const attributes = node.attrs || {}
18+
const content = node.content || []
3119

3220
let exp
3321

3422
Object.keys(attributes).forEach(attr => {
3523
exp = attributes[attr]
3624

3725
if (exp.includes(style)) {
38-
3926
if (!exp.includes('.')) {
4027
node.attrs[attr] = attrs(local, style, exp)
4128
}
@@ -44,18 +31,14 @@ exports = module.exports = function (options) {
4431
node.attrs[attr] = attrs(local, style, exp)
4532
}
4633
}
47-
4834
})
4935

5036
if (content.length === 1) {
5137
if (typeof content[0] === 'string') {
52-
5338
exp = content[0].trim()
5439

5540
if (content[0].includes(exp)) {
56-
5741
if (!exp.includes('.')) {
58-
5942
if (exp.includes(`${style}`) ||
6043
exp.includes(` ${style}`) &&
6144
!exp.includes(`>`) &&
@@ -84,13 +67,11 @@ exports = module.exports = function (options) {
8467
}
8568

8669
if (exp.includes('.')) {
87-
8870
if (exp.includes(`${style}`) &&
8971
!exp.includes(`|`) &&
9072
!exp.includes(`>`) &&
9173
!exp.includes(`...`)
9274
) {
93-
9475
node.content = exps(local, style, exp, node.content[0])
9576
}
9677

lib/attrs.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
1+
const get = require('./get')
2+
const locals = require('./local')
23

3-
let get = require('./get')
4-
let locals = require('./local')
5-
6-
exports = module.exports = function (local, style, exp) {
4+
module.exports = function (local, style, exp) {
75
let exps, attr
86

97
if (!exp.includes('.')) {

lib/each.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
'use strict'
1+
const get = require('./get')
2+
const locals = require('./local')
23

3-
let get = require('./get')
4-
let locals = require('./local')
5-
6-
exports = module.exports = function (node, local, style, exp) {
4+
module.exports = function (node, local, style, exp) {
75
let exps = locals(style, exp).replace('... ', '').trim()
86

97
let nodes = []
108

119
if (!exp.includes('.')) {
1210
for (let i = 0; i < get(local, exps).length; i++) {
13-
1411
if (typeof get(local, exps)[i] === 'object') {
15-
1612
Object.keys(get(local, exps)[i]).forEach(key => {
1713
node.content = get(local, exps)[i][key]
1814
nodes.push(' ', Object.assign({}, node), '\n ')
@@ -28,11 +24,9 @@ exports = module.exports = function (node, local, style, exp) {
2824

2925
if (exp.includes('.')) {
3026
exps = locals(style, exp).replace('...', '').trim().split('.')
31-
32-
for (let i = 0; i < get(local, exps).length; i++) {
3327

28+
for (let i = 0; i < get(local, exps).length; i++) {
3429
if (typeof get(local, exps)[i] === 'object') {
35-
3630
Object.keys(get(local, exps)[i]).forEach(key => {
3731
node.content = get(local, exps)[i][key]
3832
nodes.push(' ', Object.assign({}, node), '\n ')

lib/exps.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict'
2-
3-
let get = require('./get')
4-
let locals = require('./local')
1+
const get = require('./get')
2+
const locals = require('./local')
53

64
exports = module.exports = function (local, style, exp, content) {
7-
let exps = exp.split(' ')
5+
const exps = exp.split(' ')
86

97
function isExp (element, index, array) {
108
if (element.match(/^{|{{|{%|@/)) {
@@ -22,12 +20,10 @@ exports = module.exports = function (local, style, exp, content) {
2220
let exprs
2321

2422
exps.filter(isExp).forEach(ex => {
25-
2623
exprs = locals(style, ex).split('.')
27-
2824
content = content.replace(ex, get(local, exprs))
2925
})
3026
}
31-
27+
3228
return content
3329
}

lib/get.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
module.exports = function (locals, el) {
42
if (Array.isArray(el)) {
53
if (el.length === 2) return locals[el[0]][el[1]]

lib/if.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
'use strict'
2-
3-
let get = require('./get')
4-
let locals = require('./local')
5-
6-
exports = module.exports = function (local, style, exp) {
7-
let exps
8-
9-
exps = locals(style, exp).replace('?', '').split(':')
1+
const get = require('./get')
2+
const locals = require('./local')
103

4+
module.exports = function (local, style, exp) {
5+
const exps = locals(style, exp).replace('?', '').split(':')
116
let condition
127

138
function isDefined (element, index, array) {
@@ -18,11 +13,9 @@ exports = module.exports = function (local, style, exp) {
1813

1914
exps.filter(isDefined).map(ex => {
2015
console.log(ex)
21-
2216
condition = get(local, ex)
23-
2417
console.log(condition)
25-
2618
})
19+
2720
return condition
2821
}

lib/local.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
'use strict'
2-
31
module.exports = function (style, el) {
42
if (style === '{{') {
5-
63
return el.replace('{{', '').replace('}}', '')
7-
84
} else if (style === '{%') {
9-
105
return el.replace('{%', '').replace('%}', '')
11-
126
} else if (style === '@') {
13-
147
return el.replace('@', '')
15-
168
}
179

1810
return el.replace('{', '').replace('}', '')

lib/part.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
'use strict'
2-
3-
let fs = require('fs')
4-
let get = require('./get')
5-
let locals = require('./local')
6-
7-
exports = module.exports = function (local, style, exp) {
8-
let exps = exp.replace('> ', '').split(' ')
1+
const fs = require('fs')
2+
const get = require('./get')
3+
const locals = require('./local')
94

5+
module.exports = function (local, style, exp) {
6+
const exps = exp.replace('> ', '').split(' ')
107
let exprs, replace, partial
118

129
function isExp (element, index, array) {
@@ -18,23 +15,17 @@ exports = module.exports = function (local, style, exp) {
1815
if (!exp.includes('.')) {
1916
exps.filter(isExp).forEach(ex => {
2017
exprs = locals(style, ex).replace('> ', '')
21-
2218
replace = ex.replace(`${style}`, `${style}> `)
23-
2419
partial = fs.readFileSync(get(local, locals(style, exprs)), 'utf8')
25-
2620
partial = exp.replace(replace, partial)
2721
})
2822
}
2923

3024
if (exp.includes('.')) {
3125
exps.filter(isExp).forEach(ex => {
3226
replace = ex.replace(`${style}`, `${style}> `)
33-
3427
exprs = locals(style, ex).replace('>', '').split('.')
35-
3628
partial = fs.readFileSync(get(local, exprs), 'utf8').trim()
37-
3829
partial = exp.replace(replace, partial)
3930
})
4031
}

lib/pipe.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
'use strict'
2-
3-
let get = require('./get')
4-
let locals = require('./local')
5-
6-
exports = module.exports = function (local, style, exp) {
7-
let exps = locals(style, exp).split('|')
1+
const get = require('./get')
2+
const locals = require('./local')
83

4+
module.exports = function (local, style, exp) {
5+
const exps = locals(style, exp).split('|')
96
let pipe = ''
107

118
if (!exp.includes('.')) {
@@ -24,7 +21,6 @@ exports = module.exports = function (local, style, exp) {
2421

2522
test.push(ex)
2623
console.log(test)
27-
// let test_slice = test.slice(-1)
2824
let result = exprs.concat(test)
2925
console.log(result)
3026

lib/style.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
exports = module.exports = function (style, el) {
1+
module.exports = function (style, el) {
22
if (el) {
33
if (style === '$') {
4-
54
return `\${${el}}`
6-
75
} else if (style === '{{') {
8-
96
return `{{${el}}}`
10-
117
} else if (style === '{%') {
12-
138
return `{%${el}%}`
14-
159
} else if (style === '@') {
16-
1710
return `@${el}`
1811
}
1912
return `{${el}}`

0 commit comments

Comments
 (0)