Skip to content

Commit 3c63da5

Browse files
committed
Initial commit
0 parents  commit 3c63da5

24 files changed

+355
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
support
2+
test
3+
examples
4+
*.sock

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
0.0.1 / 2010-01-03
3+
==================
4+
5+
* Initial release

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
test:
3+
@./node_modules/.bin/mocha \
4+
--require should \
5+
--reporter spec
6+
7+
.PHONY: test

Readme.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
# css-stringify
3+
4+
CSS compiler using the AST provided by [css-parse](https://github.com/visionmedia/node-css-parse).
5+
6+
## License
7+
8+
(The MIT License)
9+
10+
Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
11+
12+
Permission is hereby granted, free of charge, to any person obtaining
13+
a copy of this software and associated documentation files (the
14+
'Software'), to deal in the Software without restriction, including
15+
without limitation the rights to use, copy, modify, merge, publish,
16+
distribute, sublicense, and/or sell copies of the Software, and to
17+
permit persons to whom the Software is furnished to do so, subject to
18+
the following conditions:
19+
20+
The above copyright notice and this permission notice shall be
21+
included in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
24+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

examples/dialog.css

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#dialog {
2+
position: fixed;
3+
left: 50%;
4+
top: 150px;
5+
max-width: 600px;
6+
min-width: 250px;
7+
border: 1px solid #eee;
8+
background: white;
9+
z-index: 1000;
10+
}
11+
12+
#dialog .content {
13+
padding: 15px 20px;
14+
}
15+
16+
#dialog h1 {
17+
margin: 0 0 5px 0;
18+
font-size: 16px;
19+
font-weight: normal;
20+
}
21+
22+
#dialog p {
23+
margin: 0;
24+
padding: 0;
25+
font-size: .9em;
26+
}
27+
28+
#dialog.modal {
29+
box-shadow: 0 1px 8px 0 black;
30+
}
31+
32+
/* close */
33+
34+
#dialog .close {
35+
position: absolute;
36+
top: 3px;
37+
right: 10px;
38+
text-decoration: none;
39+
color: #888;
40+
font-size: 16px;
41+
font-weight: bold;
42+
display: none;
43+
}
44+
45+
#dialog.closable .close {
46+
display: block;
47+
}
48+
49+
#dialog .close:hover {
50+
color: black;
51+
}
52+
53+
#dialog .close:active {
54+
margin-top: 1px;
55+
}
56+
57+
/* slide */
58+
59+
#dialog.slide {
60+
-webkit-transition: opacity 300ms, top 300ms;
61+
-moz-transition: opacity 300ms, top 300ms;
62+
}
63+
64+
#dialog.slide.hide {
65+
opacity: 0;
66+
top: -500px;
67+
}
68+
69+
/* fade */
70+
71+
#dialog.fade {
72+
-webkit-transition: opacity 300ms;
73+
-moz-transition: opacity 300ms;
74+
}
75+
76+
#dialog.fade.hide {
77+
opacity: 0;
78+
}
79+
80+
/* scale */
81+
82+
#dialog.scale {
83+
-webkit-transition: -webkit-transform 300ms;
84+
-moz-transition: -moz-transform 300ms;
85+
-webkit-transform: scale(1);
86+
-moz-transform: scale(1);
87+
}
88+
89+
#dialog.scale.hide {
90+
-webkit-transform: scale(0);
91+
-moz-transform: scale(0);
92+
}

examples/dialog.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var parse = require('..')
7+
, fs = require('fs')
8+
, read = fs.readFileSync
9+
, css = read('examples/dialog.css', 'utf8');
10+
11+
console.log(JSON.stringify(parse(css), null, 2));

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
module.exports = function(node){
3+
4+
};

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "css-parse",
3+
"version": "0.0.1",
4+
"description": "CSS parser",
5+
"keywords": ["css", "parser", "stylesheet"],
6+
"author": "TJ Holowaychuk <tj@vision-media.ca>",
7+
"devDependencies": {
8+
"mocha": "*",
9+
"should": "*",
10+
"css-parse": "1.0.0"
11+
},
12+
"main": "index"
13+
}

test/cases/empty.css

Whitespace-only changes.

test/cases/empty.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"stylesheet": {
3+
"rules": []
4+
}
5+
}

test/cases/invalid.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
3+
asdfasdfasdfasd

test/cases/invalid.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"stylesheet": {
3+
"rules": []
4+
}
5+
}

test/cases/messed-up.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
body { foo
2+
:
3+
'bar' }
4+
5+
body{foo:bar;bar:baz}
6+
body
7+
{
8+
foo
9+
:
10+
bar
11+
;
12+
bar
13+
:
14+
baz
15+
}

test/cases/messed-up.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"selector": "body",
6+
"declarations": [
7+
{
8+
"property": "foo\n ",
9+
"value": "'bar'"
10+
}
11+
]
12+
},
13+
{
14+
"selector": "body",
15+
"declarations": [
16+
{
17+
"property": "foo",
18+
"value": "bar"
19+
},
20+
{
21+
"property": "bar",
22+
"value": "baz"
23+
}
24+
]
25+
},
26+
{
27+
"selector": "body",
28+
"declarations": [
29+
{
30+
"property": "foo\n ",
31+
"value": "bar"
32+
},
33+
{
34+
"property": "bar\n ",
35+
"value": "baz"
36+
}
37+
]
38+
}
39+
]
40+
}
41+
}

test/cases/no-semi.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
tobi loki jane {
3+
are: 'all';
4+
the-species: called "ferrets"
5+
}

test/cases/no-semi.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"selector": "tobi loki jane",
6+
"declarations": [
7+
{
8+
"property": "are",
9+
"value": "'all'"
10+
},
11+
{
12+
"property": "the-species",
13+
"value": "called \"ferrets\""
14+
}
15+
]
16+
}
17+
]
18+
}
19+
}

test/cases/props.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
tobi loki jane {
3+
are: 'all';
4+
the-species: called "ferrets";
5+
}

test/cases/props.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"selector": "tobi loki jane",
6+
"declarations": [
7+
{
8+
"property": "are",
9+
"value": "'all'"
10+
},
11+
{
12+
"property": "the-species",
13+
"value": "called \"ferrets\""
14+
}
15+
]
16+
}
17+
]
18+
}
19+
}

test/cases/rule.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo {
2+
bar: 'baz';
3+
}

test/cases/rule.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"selector": "foo",
6+
"declarations": [
7+
{
8+
"property": "bar",
9+
"value": "'baz'"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
}

test/cases/rules.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tobi {
2+
name: 'tobi';
3+
}
4+
loki {
5+
name: 'loki';
6+
}

test/cases/rules.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"selector": "tobi",
6+
"declarations": [
7+
{
8+
"property": "name",
9+
"value": "'tobi'"
10+
}
11+
]
12+
},
13+
{
14+
"selector": "loki",
15+
"declarations": [
16+
{
17+
"property": "name",
18+
"value": "'loki'"
19+
}
20+
]
21+
}
22+
]
23+
}
24+
}

test/css-parse.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var stringify = require('..')
7+
, parse = require('css-parse')
8+
, fs = require('fs')
9+
, path = require('path')
10+
, read = fs.readFileSync
11+
, readdir = fs.readdirSync;
12+
13+
describe('stringify(obj)', function(){
14+
readdir('test/cases').forEach(function(file){
15+
if (~file.indexOf('css')) return;
16+
file = path.basename(file, '.json');
17+
it('should stringify ' + file, function(){
18+
var css = read(path.join('test', 'cases', file + '.css'), 'utf8');
19+
var json = read(path.join('test', 'cases', file + '.json'), 'utf8');
20+
var ret = stringify(parse(css));
21+
ret.should.equal(css);
22+
})
23+
});
24+
})

0 commit comments

Comments
 (0)