Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix+refactor: some errors in the new class

  • Loading branch information...
commit 761e52e58c9975ef621f4c84d473608e9cc7126c 1 parent 58047a3
@thomaspierson authored
Showing with 11 additions and 6 deletions.
  1. +11 −6 css2less.rb
View
17 css2less.rb
@@ -8,6 +8,7 @@ class Converter
def initialize(css)
@css = css
@tree = {}
+ @less = ''
end
def add_rule(tree, selectors, style)
@@ -21,7 +22,7 @@ def add_rule(tree, selectors, style)
end
end
- def generate
+ def generate_tree
@css.split("\n").map { |l| l.strip }.join.gsub(/\/\*+[^\*]*\*+\//, '').split(/[\{\}]/).each_slice(2) do |style|
rules = style[0].strip
if rules.include?(',') # leave multiple rules alone
@@ -32,21 +33,25 @@ def generate
end
end
- def print(tree=nil, indent=0)
+ def render_less(tree=nil, indent=0)
if tree.nil?
tree = @tree
end
tree.each do |element, children|
- puts ' ' * indent + element + " {\n"
+ @less = @less + ' ' * indent + element + " {\n"
style = children.delete(:style)
if style
- puts style.split(';').map { |s| s.strip }.reject { |s| s.empty? }.map { |s| ' ' * (indent+2) + s + ';' }.join("\n")
+ @less = @less + style.split(';').map { |s| s.strip }.reject { |s| s.empty? }.map { |s| ' ' * (indent+2) + s + ';' }.join("\n")
end
- print(children, indent + 2)
- puts ' ' * indent + "}\n"
+ render_less(children, indent + 2)
+ @less = @less + ' ' * indent + "}\n"
end
end
+ def get_less
+ return @less
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.