css2stylus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/css2stylus +10 -10
  2. data/lib/css2stylus.rb +64 -64
  3. metadata +4 -4
data/bin/css2stylus CHANGED
@@ -1,11 +1,11 @@
1
- #!/usr/bin/env ruby
2
- require 'css2stylus'
3
-
4
- file = File.basename(ARGV[0])
5
- filename = File.basename(file, File.extname(file))
6
- css = File.read(file)
7
-
8
- converter = Css2Stylus::Converter.new(css)
9
- converter.process
10
-
1
+ #!/usr/bin/env ruby
2
+ require 'css2stylus'
3
+
4
+ file = File.basename(ARGV[0])
5
+ filename = File.basename(file, File.extname(file))
6
+ css = File.read(file)
7
+
8
+ converter = Css2Stylus::Converter.new(css)
9
+ converter.process
10
+
11
11
  File.open(filename + '.styl', 'w') { |file| file.write(converter.get) }
data/lib/css2stylus.rb CHANGED
@@ -1,65 +1,65 @@
1
- module Css2Stylus
2
-
3
- class Converter
4
-
5
- def initialize(css=nil)
6
- if not css.nil?
7
- @css = css
8
- end
9
- end
10
-
11
- def process
12
- if @css.nil? || @css.empty?
13
- return false
14
- end
15
- @tree = {}
16
- @stylus = ''
17
- generate_tree
18
- render
19
- return true
20
- end
21
-
22
- def get
23
- return @stylus
24
- end
25
-
26
- private
27
-
28
- def add_rule(tree, selectors, style)
29
- return if style.nil? || style.empty?
30
- if selectors.empty?
31
- (tree[:style] ||= '') << style
32
- else
33
- first, rest = selectors.first, selectors[1..-1]
34
- node = (tree[first] ||= {})
35
- add_rule(node, rest, style)
36
- end
37
- end
38
-
39
- def generate_tree
40
- @css.split("\n").map { |l| l.strip }.join.gsub(/\/\*+[^\*]*\*+\//, '').split(/[\{\}]/).each_slice(2) do |style|
41
- rules = style[0].strip
42
- if rules.include?(',')
43
- add_rule(@tree, [rules], style[1])
44
- else
45
- add_rule(@tree, rules.split(/\s+/), style[1])
46
- end
47
- end
48
- end
49
-
50
- def render(tree=nil, indent=0)
51
- if tree.nil?
52
- tree = @tree
53
- end
54
- tree.each do |element, children|
55
- @stylus = @stylus + ' ' * indent + element + "\n"
56
- style = children.delete(:style)
57
- if style
58
- @stylus = @stylus + style.split(';').map { |s| s.strip }.reject { |s| s.empty? }.map { |s| ' ' * (indent + 2) + s.gsub(/:(\s)*/, ' ') }.join("\n") + "\n"
59
- end
60
- render(children, indent + 2)
61
- end
62
- end
63
-
64
- end
1
+ module Css2Stylus
2
+
3
+ class Converter
4
+
5
+ def initialize(css=nil)
6
+ if not css.nil?
7
+ @css = css
8
+ end
9
+ end
10
+
11
+ def process
12
+ @stylus = ''
13
+ if @css.nil? || @css.empty?
14
+ return @stylus
15
+ end
16
+ @tree = {}
17
+ generate_tree
18
+ render
19
+ return true
20
+ end
21
+
22
+ def get
23
+ return @stylus
24
+ end
25
+
26
+ private
27
+
28
+ def add_rule(tree, selectors, style)
29
+ return if style.nil? || style.empty?
30
+ if selectors.empty?
31
+ (tree[:style] ||= '') << style
32
+ else
33
+ first, rest = selectors.first, selectors[1..-1]
34
+ node = (tree[first] ||= {})
35
+ add_rule(node, rest, style)
36
+ end
37
+ end
38
+
39
+ def generate_tree
40
+ @css.split("\n").map { |line| line.strip }.join.gsub(/\/\*+[^\*]*\*+\//, '').split(/[\{\}]/).each_slice(2) do |style|
41
+ rules = style[0].strip
42
+ if rules.include?(',')
43
+ add_rule(@tree, [rules], style[1])
44
+ else
45
+ add_rule(@tree, rules.split(/\s+/), style[1])
46
+ end
47
+ end
48
+ end
49
+
50
+ def render(tree=nil, indent=0)
51
+ if tree.nil?
52
+ tree = @tree
53
+ end
54
+ tree.each do |element, children|
55
+ @stylus = @stylus + ' ' * indent + element + "\n"
56
+ style = children.delete(:style)
57
+ if style
58
+ @stylus = @stylus + style.split(';').map { |s| s.strip }.reject { |s| s.empty? }.map { |s| ' ' * (indent + 2) + s.gsub(/:(\s)*/, ' ') }.join("\n") + "\n"
59
+ end
60
+ render(children, indent + 2)
61
+ end
62
+ end
63
+
64
+ end
65
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css2stylus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-22 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A ruby library to convert CSS into Stylus.
15
15
  email:
@@ -21,7 +21,7 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - lib/css2stylus.rb
23
23
  - bin/css2stylus
24
- homepage: https://github.com/dciccale/css2stylus
24
+ homepage: https://github.com/dciccale/css2stylus.gem
25
25
  licenses:
26
26
  - MIT
27
27
  post_install_message:
@@ -45,5 +45,5 @@ rubyforge_project:
45
45
  rubygems_version: 1.8.24
46
46
  signing_key:
47
47
  specification_version: 3
48
- summary: CSS to Stylus converter
48
+ summary: CSS to Stylus converter.
49
49
  test_files: []