csso-rails 0.0.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,128 +0,0 @@
1
- function CSSOTranslator() {}
2
-
3
- CSSOTranslator.prototype.translate = function(tree) {
4
- // console.trace('--------');
5
- // console.log(tree);
6
- return this._t(tree);
7
- };
8
-
9
- CSSOTranslator.prototype._m_simple = {
10
- 'unary': 1, 'nth': 1, 'combinator': 1, 'ident': 1, 'number': 1, 's': 1,
11
- 'string': 1, 'attrselector': 1, 'operator': 1, 'raw': 1, 'unknown': 1
12
- };
13
-
14
- CSSOTranslator.prototype._m_composite = {
15
- 'simpleselector': 1, 'dimension': 1, 'selector': 1, 'property': 1, 'value': 1,
16
- 'filterv': 1, 'progid': 1, 'ruleset': 1, 'atruleb': 1, 'atrulerq': 1, 'atrulers': 1,
17
- 'stylesheet': 1
18
- };
19
-
20
- CSSOTranslator.prototype._m_primitive = {
21
- 'cdo': 'cdo', 'cdc': 'cdc', 'decldelim': ';', 'namespace': '|', 'delim': ','
22
- };
23
-
24
- CSSOTranslator.prototype._t = function(tree) {
25
- var t = tree[0];
26
- if (t in this._m_primitive) return this._m_primitive[t];
27
- else if (t in this._m_simple) return this._simple(tree);
28
- else if (t in this._m_composite) return this._composite(tree);
29
- return this[t](tree);
30
- };
31
-
32
- CSSOTranslator.prototype._composite = function(t, i) {
33
- var s = '';
34
- i = i === undefined ? 1 : i;
35
- for (; i < t.length; i++) s += this._t(t[i]);
36
- return s;
37
- };
38
-
39
- CSSOTranslator.prototype._simple = function(t) {
40
- return t[1];
41
- };
42
-
43
- CSSOTranslator.prototype.percentage = function(t) {
44
- return this._t(t[1]) + '%';
45
- };
46
-
47
- CSSOTranslator.prototype.comment = function(t) {
48
- return '/*' + t[1] + '*/';
49
- };
50
-
51
- CSSOTranslator.prototype.clazz = function(t) {
52
- return '.' + this._t(t[1]);
53
- };
54
-
55
- CSSOTranslator.prototype.atkeyword = function(t) {
56
- return '@' + this._t(t[1]);
57
- };
58
-
59
- CSSOTranslator.prototype.shash = function(t) {
60
- return '#' + t[1];
61
- };
62
-
63
- CSSOTranslator.prototype.vhash = function(t) {
64
- return '#' + t[1];
65
- };
66
-
67
- CSSOTranslator.prototype.attrib = function(t) {
68
- return '[' + this._composite(t) + ']';
69
- };
70
-
71
- CSSOTranslator.prototype.important = function(t) {
72
- return '!' + this._composite(t) + 'important';
73
- };
74
-
75
- CSSOTranslator.prototype.nthselector = function(t) {
76
- return ':' + this._simple(t[1]) + '(' + this._composite(t, 2) + ')';
77
- };
78
-
79
- CSSOTranslator.prototype.funktion = function(t) {
80
- return this._simple(t[1]) + '(' + this._composite(t[2]) + ')';
81
- };
82
-
83
- CSSOTranslator.prototype.declaration = function(t) {
84
- return this._t(t[1]) + ':' + this._t(t[2]);
85
- };
86
-
87
- CSSOTranslator.prototype.filter = function(t) {
88
- return this._t(t[1]) + ':' + this._t(t[2]);
89
- };
90
-
91
- CSSOTranslator.prototype.block = function(t) {
92
- return '{' + this._composite(t) + '}';
93
- };
94
-
95
- CSSOTranslator.prototype.braces = function(t) {
96
- return t[1] + this._composite(t, 3) + t[2];
97
- };
98
-
99
- CSSOTranslator.prototype.atrules = function(t) {
100
- return this._composite(t) + ';';
101
- };
102
-
103
- CSSOTranslator.prototype.atruler = function(t) {
104
- return this._t(t[1]) + this._t(t[2]) + '{' + this._t(t[3]) + '}';
105
- };
106
-
107
- CSSOTranslator.prototype.pseudoe = function(t) {
108
- return '::' + this._t(t[1]);
109
- };
110
-
111
- CSSOTranslator.prototype.pseudoc = function(t) {
112
- return ':' + this._t(t[1]);
113
- };
114
-
115
- CSSOTranslator.prototype.uri = function(t) {
116
- return 'url(' + this._composite(t) + ')';
117
- };
118
-
119
- CSSOTranslator.prototype.functionExpression = function(t) {
120
- return 'expression(' + t[1] + ')';
121
- };
122
- exports.translate = function(tree) {
123
- return new CSSOTranslator().translate(tree);
124
- };
125
-
126
- exports.translator = function() {
127
- return new CSSOTranslator();
128
- };
data/lib/csso/js/util.js DELETED
@@ -1,41 +0,0 @@
1
- var $util = {};
2
-
3
- $util.cleanInfo = function(tree) {
4
- var r = [];
5
- tree = tree.slice(1);
6
-
7
- tree.forEach(function(e) {
8
- r.push(Array.isArray(e) ? $util.cleanInfo(e) : e);
9
- });
10
-
11
- return r;
12
- };
13
-
14
- $util.treeToString = function(tree, level) {
15
- var spaces = $util.dummySpaces(level),
16
- level = level ? level : 0,
17
- s = (level ? '\n' + spaces : '') + '[';
18
-
19
- tree.forEach(function(e) {
20
- s += (Array.isArray(e) ? $util.treeToString(e, level + 1) : e.f !== undefined ? $util.ircToString(e) : ('\'' + e.toString() + '\'')) + ', ';
21
- });
22
-
23
- return s.substr(0, s.length - 2) + ']';
24
- };
25
-
26
- $util.ircToString = function(o) {
27
- return '{' + o.f + ',' + o.l + '}';
28
- };
29
-
30
- $util.dummySpaces = function(num) {
31
- return ' '.substr(0, num * 2);
32
- };
33
- $util.printTree = function(tree) {
34
- require('sys').print($util.treeToString(tree));
35
- };
36
-
37
- exports.cleanInfo = $util.cleanInfo;
38
-
39
- exports.treeToString = $util.treeToString;
40
-
41
- exports.printTree = $util.printTree;
data/lib/csso/loader.rb DELETED
@@ -1,74 +0,0 @@
1
- require 'commonjs'
2
- require 'pathname'
3
-
4
- module Csso
5
- class Loader
6
- include CallJS
7
-
8
- attr_reader :environment
9
-
10
- class ModifiedEnvironment < CommonJS::Environment
11
- # CommonJS' require does append .js to modules no matter if it is there already
12
- def require module_id
13
- path = module_id.gsub(/^\.\//, "")
14
- path = path.gsub(/\.js$/, "")
15
- super path
16
- end
17
- end
18
-
19
- def initialize js_path=nil
20
- @js_path = js_path || Pathname(__FILE__).dirname.join('js').to_s
21
- @cxt = V8::Context.new
22
- @environment = ModifiedEnvironment.new(@cxt, :path => @js_path)
23
-
24
- [Util, Path, Fs].each do |native|
25
- @environment.native(native.to_s.downcase, native.new)
26
- end
27
-
28
- [Process, Console].each do|replace|
29
- @cxt[replace.to_s.downcase] = replace.new
30
- end
31
- end
32
-
33
- def require(module_id)
34
- @environment.require(module_id)
35
- end
36
-
37
- class Path
38
- def join(*components)
39
- File.join(*components)
40
- end
41
-
42
- def dirname(path)
43
- File.dirname(path)
44
- end
45
- end
46
-
47
- class Util # sys
48
- def error(*errors)
49
- raise errors.join(' ')
50
- end
51
- end
52
-
53
- class Fs
54
- def statSync(path)
55
- File.stat(path)
56
- end
57
-
58
- def readFile(path, encoding, callback)
59
- callback.call(nil, File.read(path))
60
- end
61
- end
62
-
63
- class Process
64
- def exit(*args)
65
- end
66
- end
67
-
68
- class Console
69
- def log(*msgs)
70
- puts msgs.join(',')
71
- end
72
- end
73
- end
74
- end
data/lib/csso/utils.rb DELETED
@@ -1,53 +0,0 @@
1
- module Csso
2
- # Utility for calling into the JavaScript runtime.
3
- module CallJS
4
-
5
- # @private
6
- # Wrap JavaScript invocations with uniform error handling
7
- #
8
- # @yield code to wrap
9
- def calljs err_cls=WrappedError
10
- lock do
11
- yield
12
- end
13
- rescue V8::JSError => e
14
- raise err_cls.new(e)
15
- end
16
-
17
- # @private
18
- # Ensure proper locking before entering the V8 API
19
- #
20
- # @yield code to wrap in lock
21
- def lock
22
- result, exception = nil, nil
23
- V8::C::Locker() do
24
- begin
25
- result = yield
26
- rescue Exception => e
27
- exception = e
28
- end
29
- end
30
- if exception
31
- raise exception
32
- else
33
- result
34
- end
35
- end
36
- end
37
-
38
- class WrappedError < StandardError
39
-
40
- # Copies over `error`'s message and backtrace
41
- # @param [V8::JSError] error native error
42
- def initialize(error)
43
- super(error.message)
44
- @backtrace = error.backtrace
45
- end
46
-
47
- # @return [Array] the backtrace frames
48
- def backtrace
49
- @backtrace
50
- end
51
- end
52
-
53
- end
data/spec/spec_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- $:.unshift Pathname(__FILE__).dirname.join('..','lib')
2
-
3
- require 'csso'