1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/sass/engine.rb
hcatlin fa5048ba40 Adding in the initial sasstastic stuff.
git-svn-id: svn://hamptoncatlin.com/haml/branches/1.5dev@174 7063305b-7217-0410-af8c-cdc13e5119b9
2006-11-28 19:43:58 +00:00

40 lines
1,016 B
Ruby

require File.dirname(__FILE__) + '/css/parser'
module Sass
class Engine
def render(input)
buffer, stack, last_level, first = "", [], 0, true
input.each do |line|
line, level = [line.strip, line.scan(/[ ]*/)[0].length / 2]
unless line.empty?
if '%.#'.index line[0..0]
if !first
buffer << "}\n"
end
if level <= last_level
stack.delete_at(stack.size - 1)
if stack.empty?
buffer << "\n"
end
end
stack << line
buffer << stack.join(" ") + " { "
last_level, first = level, false
elsif ':' == line[0..0]
attribute, *value = line.scan(/[^ ]*/)
value = value.join(" ") if value.is_a? Array
buffer << "#{attribute[1..-1]}: #{value.strip}; "
end
end
end
unless stack.empty?
buffer << "}"
end
buffer
end
end
end