Skip to content

Commit

Permalink
⬆️ Update jdists-util@0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zswang committed Dec 5, 2017
1 parent c945c62 commit dfcb585
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 70 deletions.
6 changes: 1 addition & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"use strict";
var swig = require("swig");
var jsyaml = require("js-yaml");
module.exports = (function (content, attrs, scope) {
if (!content) {
return content;
}
var data = null;
if (attrs.data) {
data = scope.execImport(attrs.data);
if (typeof data === 'string') {
data = jsyaml.safeLoad(data);
}
data = scope.execImport(attrs.data, true);
}
var render = swig.compile(content);
return render(data);
Expand Down
22 changes: 1 addition & 21 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as swig from 'swig'
import * as jdistsUtil from 'jdists-util'
import * as jsyaml from 'js-yaml'
interface IswigAttrs extends jdistsUtil.IAttrs {
/**
* 数据来源
Expand All @@ -17,22 +16,6 @@ interface IswigAttrs extends jdistsUtil.IAttrs {
* @param scope.execImport 导入数据
* @return 返回渲染后的结果
* @example processor():base
```js
let attrs = {
data: '#name'
}
let scope = {
execImport: function (importion) {
return `
name: tom
age: 13
`
},
}
console.log(processor('<b>{{name}} - {{age}}</b>', attrs, scope))
// > <b>tom - 13</b>
```
* @example processor():execImport is object
```js
let attrs = {
data: '#name',
Expand Down Expand Up @@ -67,10 +50,7 @@ export = (function (content: string, attrs: IswigAttrs, scope: jdistsUtil.IScope
}
let data = null
if (attrs.data) {
data = scope.execImport(attrs.data)
if (typeof data === 'string') {
data = jsyaml.safeLoad(data)
}
data = scope.execImport(attrs.data, true)
}
let render = swig.compile(content)
return render(data)
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jdists/swig",
"version": "0.0.2",
"version": "0.0.3",
"description": "swig as jdists processor",
"main": "lib/index",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -32,8 +32,7 @@
},
"homepage": "https://github.com/jdists/swig#readme",
"dependencies": {
"jdists-util": "^0.0.7",
"js-yaml": "^3.10.0",
"jdists-util": "^0.1.2",
"swig": "^1.4.2"
},
"devDependencies": {
Expand Down
28 changes: 4 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as swig from 'swig'
import * as jdistsUtil from 'jdists-util'
import * as jsyaml from 'js-yaml'

interface IswigAttrs extends jdistsUtil.IAttrs {
interface ISwigAttrs extends jdistsUtil.IAttrs {
/**
* 数据来源
*/
Expand All @@ -19,28 +18,12 @@ interface IswigAttrs extends jdistsUtil.IAttrs {
* @param scope.execImport 导入数据
* @return 返回渲染后的结果
* @example processor():base
```js
let attrs = {
data: '#name'
}
let scope = {
execImport: function (importion) {
return `
name: tom
age: 13
`
},
}
console.log(processor('<b>{{name}} - {{age}}</b>', attrs, scope))
// > <b>tom - 13</b>
```
* @example processor():execImport is object
```js
let attrs = {
data: '#name',
}
let scope = {
execImport: function (importion) {
execImport: function (importion, isYaml) {
return {
name: 'tom',
age: 13,
Expand All @@ -63,16 +46,13 @@ interface IswigAttrs extends jdistsUtil.IAttrs {
// > null
```
*/
export = (function (content: string, attrs: IswigAttrs, scope: jdistsUtil.IScope): string {
export = (function (content: string, attrs: ISwigAttrs, scope: jdistsUtil.IScope): string {
if (!content) {
return content
}
let data = null
if (attrs.data) {
data = scope.execImport(attrs.data)
if (typeof data === 'string') {
data = jsyaml.safeLoad(data)
}
data = scope.execImport(attrs.data, true)
}
let render = swig.compile(content)
return render(data)
Expand Down
17 changes: 0 additions & 17 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,6 @@ describe("src/index.ts", function () {

it("processor():base", function () {
examplejs_printLines = [];
let attrs = {
data: '#name'
}
let scope = {
execImport: function (importion) {
return `
name: tom
age: 13
`
},
}
examplejs_print(processor('<b>{{name}} - {{age}}</b>', attrs, scope))
assert.equal(examplejs_printLines.join("\n"), "<b>tom - 13</b>"); examplejs_printLines = [];
});

it("processor():execImport is object", function () {
examplejs_printLines = [];
let attrs = {
data: '#name',
}
Expand Down

0 comments on commit dfcb585

Please sign in to comment.