Refactor code-style
This commit is contained in:
parent
399bc1ecef
commit
71af94adb5
1 changed files with 17 additions and 27 deletions
|
@ -2,21 +2,27 @@ import {decodeEntity} from 'parse-entities/decode-entity.js'
|
||||||
|
|
||||||
const own = {}.hasOwnProperty
|
const own = {}.hasOwnProperty
|
||||||
|
|
||||||
export function directiveHtml(options) {
|
export function directiveHtml(options = {}) {
|
||||||
const extensions = options || {}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
enter: {
|
enter: {
|
||||||
directiveContainer: enterContainer,
|
directiveContainer() {
|
||||||
|
return enter.call(this, 'containerDirective')
|
||||||
|
},
|
||||||
directiveContainerAttributes: enterAttributes,
|
directiveContainerAttributes: enterAttributes,
|
||||||
directiveContainerContent: enterContainerContent,
|
|
||||||
directiveContainerLabel: enterLabel,
|
directiveContainerLabel: enterLabel,
|
||||||
|
directiveContainerContent() {
|
||||||
|
this.buffer()
|
||||||
|
},
|
||||||
|
|
||||||
directiveLeaf: enterLeaf,
|
directiveLeaf() {
|
||||||
|
return enter.call(this, 'leafDirective')
|
||||||
|
},
|
||||||
directiveLeafAttributes: enterAttributes,
|
directiveLeafAttributes: enterAttributes,
|
||||||
directiveLeafLabel: enterLabel,
|
directiveLeafLabel: enterLabel,
|
||||||
|
|
||||||
directiveText: enterText,
|
directiveText() {
|
||||||
|
return enter.call(this, 'textDirective')
|
||||||
|
},
|
||||||
directiveTextAttributes: enterAttributes,
|
directiveTextAttributes: enterAttributes,
|
||||||
directiveTextLabel: enterLabel
|
directiveTextLabel: enterLabel
|
||||||
},
|
},
|
||||||
|
@ -52,18 +58,6 @@ export function directiveHtml(options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterContainer() {
|
|
||||||
return enter.call(this, 'containerDirective')
|
|
||||||
}
|
|
||||||
|
|
||||||
function enterLeaf() {
|
|
||||||
return enter.call(this, 'leafDirective')
|
|
||||||
}
|
|
||||||
|
|
||||||
function enterText() {
|
|
||||||
return enter.call(this, 'textDirective')
|
|
||||||
}
|
|
||||||
|
|
||||||
function enter(type) {
|
function enter(type) {
|
||||||
let stack = this.getData('directiveStack')
|
let stack = this.getData('directiveStack')
|
||||||
if (!stack) this.setData('directiveStack', (stack = []))
|
if (!stack) this.setData('directiveStack', (stack = []))
|
||||||
|
@ -139,10 +133,6 @@ export function directiveHtml(options) {
|
||||||
stack[stack.length - 1].attributes = cleaned
|
stack[stack.length - 1].attributes = cleaned
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterContainerContent() {
|
|
||||||
this.buffer()
|
|
||||||
}
|
|
||||||
|
|
||||||
function exitContainerContent() {
|
function exitContainerContent() {
|
||||||
const data = this.resume()
|
const data = this.resume()
|
||||||
const stack = this.getData('directiveStack')
|
const stack = this.getData('directiveStack')
|
||||||
|
@ -162,13 +152,13 @@ export function directiveHtml(options) {
|
||||||
let found
|
let found
|
||||||
let result
|
let result
|
||||||
|
|
||||||
if (own.call(extensions, directive.name)) {
|
if (own.call(options, directive.name)) {
|
||||||
result = extensions[directive.name].call(this, directive)
|
result = options[directive.name].call(this, directive)
|
||||||
found = result !== false
|
found = result !== false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found && own.call(extensions, '*')) {
|
if (!found && own.call(options, '*')) {
|
||||||
result = extensions['*'].call(this, directive)
|
result = options['*'].call(this, directive)
|
||||||
found = result !== false
|
found = result !== false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue