1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Add RootNode#to_sass for users to use.

This commit is contained in:
Nathan Weizenbaum 2010-01-26 23:37:37 -08:00
parent 650528554b
commit f83c68825e
3 changed files with 10 additions and 8 deletions

View file

@ -40,7 +40,7 @@ module Sass
raise Sass::SyntaxError.new(msg, :line => line) raise Sass::SyntaxError.new(msg, :line => line)
end end
build_tree.to_sass(0, @options).strip + "\n" build_tree.to_sass(@options).strip + "\n"
rescue Sass::SyntaxError => err rescue Sass::SyntaxError => err
err.modify_backtrace(:filename => @options[:filename] || '(css)') err.modify_backtrace(:filename => @options[:filename] || '(css)')
raise err raise err

View file

@ -190,13 +190,7 @@ module Sass
# @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}) # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
# @return [String] The Sass code corresponding to the node # @return [String] The Sass code corresponding to the node
def to_sass(tabs = 0, opts = {}) def to_sass(tabs = 0, opts = {})
result = '' raise NotImplementedError.new("All static-node subclasses of Sass::Tree::Node must override #to_sass.")
children.each do |child|
result << "#{' ' * tabs}#{child.to_sass(0, opts)}\n"
end
result.rstrip + "\n"
end end
protected protected

View file

@ -44,6 +44,14 @@ module Sass
super super
end end
# Converts a node to Sass code that will generate it.
#
# @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
# @return [String] The Sass code corresponding to the node
def to_sass(opts = {})
children.map {|child| child.to_sass(0, opts) + "\n"}.join.rstrip + "\n"
end
protected protected
# Destructively converts this static Sass node into a static CSS node, # Destructively converts this static Sass node into a static CSS node,