mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Sass style-setting.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@348 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
c882f79c78
commit
edb938e324
6 changed files with 32 additions and 12 deletions
|
@ -37,7 +37,9 @@ module Sass
|
|||
#++
|
||||
#
|
||||
def initialize(template, options={})
|
||||
@options = options
|
||||
@options = {
|
||||
:style => :compact
|
||||
}.merge! options
|
||||
@template = template.split("\n")
|
||||
@lines = []
|
||||
@constants = {}
|
||||
|
@ -48,7 +50,7 @@ module Sass
|
|||
begin
|
||||
split_lines
|
||||
|
||||
root = Tree::Node.new
|
||||
root = Tree::Node.new(@options[:style])
|
||||
index = 0
|
||||
while @lines[index]
|
||||
child, index = build_tree(index)
|
||||
|
@ -144,7 +146,7 @@ module Sass
|
|||
when Constant::CONSTANT_CHAR
|
||||
parse_constant(line)
|
||||
else
|
||||
Tree::RuleNode.new(line)
|
||||
Tree::RuleNode.new(line, @options[:style])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -163,7 +165,7 @@ module Sass
|
|||
value = Sass::Constant.parse(value, @constants, @line).to_s
|
||||
end
|
||||
|
||||
Tree::AttrNode.new(name, value)
|
||||
Tree::AttrNode.new(name, value, @options[:style])
|
||||
end
|
||||
|
||||
def parse_constant(line)
|
||||
|
|
|
@ -4,9 +4,9 @@ module Sass::Tree
|
|||
class AttrNode < ValueNode
|
||||
attr_accessor :name
|
||||
|
||||
def initialize(name, value)
|
||||
def initialize(name, value, style)
|
||||
@name = name
|
||||
super(value)
|
||||
super(value, style)
|
||||
end
|
||||
|
||||
def to_s(parent_name = nil)
|
||||
|
@ -17,7 +17,13 @@ module Sass::Tree
|
|||
real_name = "#{parent_name}-#{real_name}" if parent_name
|
||||
if children.size > 0
|
||||
to_return = String.new
|
||||
children.each { |kid| to_return += "#{kid.to_s(real_name)} " }
|
||||
children.each do |kid|
|
||||
if @style == :expanded
|
||||
to_return << "#{kid.to_s(real_name)}\n "
|
||||
else
|
||||
to_return << "#{kid.to_s(real_name)} "
|
||||
end
|
||||
end
|
||||
to_return[0...-1]
|
||||
else
|
||||
if value.length < 1
|
||||
|
|
|
@ -4,7 +4,8 @@ module Sass
|
|||
attr_accessor :children
|
||||
attr_accessor :line
|
||||
|
||||
def initialize
|
||||
def initialize(style)
|
||||
@style = style
|
||||
@children = []
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,11 @@ module Sass::Tree
|
|||
|
||||
to_return = ''
|
||||
unless attributes.empty?
|
||||
to_return << "#{total_rule} { #{attributes.join(' ')} }\n"
|
||||
if @style == :expanded
|
||||
to_return << "#{total_rule} {\n #{attributes.join("\n ").rstrip}\n}\n"
|
||||
else
|
||||
to_return << "#{total_rule} { #{attributes.join(' ')} }\n"
|
||||
end
|
||||
end
|
||||
|
||||
sub_rules.each { |sub| to_return << sub.to_s(total_rule) }
|
||||
|
|
|
@ -4,9 +4,9 @@ module Sass::Tree
|
|||
class ValueNode < Node
|
||||
attr_accessor :value
|
||||
|
||||
def initialize(value)
|
||||
def initialize(value, style)
|
||||
@value = value
|
||||
super()
|
||||
super(style)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ class SassPluginTest < Test::Unit::TestCase
|
|||
:template_location => File.dirname(__FILE__) + '/templates',
|
||||
:css_location => File.dirname(__FILE__) + '/tmp',
|
||||
}
|
||||
Sass::Plugin.options[:always_update] = true
|
||||
Sass::Plugin.options[:always_update] = true
|
||||
|
||||
Sass::Plugin.update_stylesheets
|
||||
end
|
||||
|
@ -24,6 +24,13 @@ class SassPluginTest < Test::Unit::TestCase
|
|||
File.delete(*Dir[tempfile_loc('*')])
|
||||
end
|
||||
|
||||
def test_expanded_style
|
||||
engine = Sass::Engine.new(File.read(File.dirname(__FILE__) + '/templates/expanded.sass'),
|
||||
{ :style => :expanded })
|
||||
File.open(tempfile_loc('expanded'), 'w') { |f| f.write(engine.render) }
|
||||
assert_renders_correctly('expanded')
|
||||
end
|
||||
|
||||
def test_templates_should_render_correctly
|
||||
@@templates.each { |name| assert_renders_correctly(name) }
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue