Class: Less2Sass::Sass::ASTHandler
- Inherits:
-
Object
- Object
- Less2Sass::Sass::ASTHandler
- Defined in:
- lib/less2sass/sass/ast_handler.rb
Overview
Wrapped Sass AST
Instance Method Summary collapse
-
#<<(child) ⇒ Object
Appends child notes to the empty Sass AST.
-
#code_gen(destination = nil, syntax) ⇒ Object
Outputs the transformed and converted AST in the form of Sass code.
-
#initialize(tree) ⇒ ASTHandler
constructor
Creates an empty Sass AST.
- #open_file(filename, flag = 'r') {|File.open(filename, flag)| ... } ⇒ Object
- #to_css ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(tree) ⇒ ASTHandler
Creates an empty Sass AST.
8 9 10 |
# File 'lib/less2sass/sass/ast_handler.rb', line 8 def initialize(tree) @tree = tree end |
Instance Method Details
#<<(child) ⇒ Object
Appends child notes to the empty Sass AST.
Note, that this should be called only once.
18 19 20 21 22 |
# File 'lib/less2sass/sass/ast_handler.rb', line 18 def <<(child) # TODO: check if child.is_a?(::Sass::Tree::Node) and raise some error, if not @tree << child self end |
#code_gen(destination = nil, syntax) ⇒ Object
TODO:
method cannot handle import nodes, yet - single files only
Outputs the transformed and converted AST in the form of Sass code.
36 37 38 39 40 41 42 43 44 |
# File 'lib/less2sass/sass/ast_handler.rb', line 36 def code_gen(destination = nil, syntax) code = syntax == :scss ? @tree.to_scss : @tree.to_sass return code unless destination if destination.is_a?(String) open_file(destination, 'w') { |file| file.write(code) } else destination.write(code) end end |
#open_file(filename, flag = 'r') {|File.open(filename, flag)| ... } ⇒ Object
46 47 48 49 50 |
# File 'lib/less2sass/sass/ast_handler.rb', line 46 def open_file(filename, flag = 'r') return if filename.nil? return File.open(filename, flag) unless block_given? yield File.open(filename, flag) end |
#to_css ⇒ Object
24 25 26 |
# File 'lib/less2sass/sass/ast_handler.rb', line 24 def to_css @tree.render end |
#to_yaml ⇒ Object
52 53 54 |
# File 'lib/less2sass/sass/ast_handler.rb', line 52 def to_yaml @tree.to_yaml end |