Skip to content
This repository was archived by the owner on Jun 5, 2018. It is now read-only.

Commit 8158119

Browse files
committed
v0.3.1
1 parent 48e9cb8 commit 8158119

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

dist/powcss.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,34 @@ class Context {
216216
}
217217
return this.rule.decls[key] || '';
218218
}
219+
220+
/**
221+
* 输出 this.rules 为 CSS 源码
222+
* @return {string} css
223+
*/
224+
toCSS() {
225+
let toCSS = (css, rule)=> {
226+
if (rule.decls) {
227+
css += rule.name + ' {\n';
228+
for (let key in rule.decls) {
229+
if (typeof rule.decls[key] === 'string')
230+
css += key + ': ' + rule.decls[key] + ';\n';
231+
else if (Array.isArray(rule.decls[key])) {
232+
css += rule.decls[key].reduce(toCSS, '') + '\n';
233+
}else {
234+
throw new Error('decls must be a string or array: ' + rule.name + '{' + key + '}');
235+
}
236+
}
237+
css += '}\n';
238+
}else if (rule.name[0] === '/') // comment
239+
css += rule.name + '\n';
240+
else
241+
css += rule.name + ';\n';
242+
return css;
243+
};
244+
245+
return this.rules.reduce(toCSS, '');
246+
}
219247
}
220248

221249
module.exports = function(...extend) {

dist/powcss.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/context.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,34 @@ class Context {
9696
}
9797
return this.rule.decls[key] || '';
9898
}
99+
100+
/**
101+
* 输出 this.rules 为 CSS 源码
102+
* @return {string} css
103+
*/
104+
toCSS() {
105+
let toCSS = (css, rule)=> {
106+
if (rule.decls) {
107+
css += rule.name + ' {\n';
108+
for (let key in rule.decls) {
109+
if (typeof rule.decls[key] === 'string')
110+
css += key + ': ' + rule.decls[key] + ';\n';
111+
else if (Array.isArray(rule.decls[key])) {
112+
css += rule.decls[key].reduce(toCSS, '') + '\n';
113+
}else {
114+
throw new Error('decls must be a string or array: ' + rule.name + '{' + key + '}');
115+
}
116+
}
117+
css += '}\n';
118+
}else if (rule.name[0] === '/') // comment
119+
css += rule.name + '\n';
120+
else
121+
css += rule.name + ';\n';
122+
return css;
123+
};
124+
125+
return this.rules.reduce(toCSS, '');
126+
}
99127
}
100128

101129
module.exports = function(...extend) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "powcss",
33
"description": "Modern preprocessor for transforming styles based on ES6 template Strings",
4-
"version": "0.3.0",
4+
"version": "0.3.1",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/powjs/powcss.git"

0 commit comments

Comments
 (0)