mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
New, nested Sass style.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@349 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
edb938e324
commit
7cd7e603b1
8 changed files with 46 additions and 20 deletions
|
@ -38,7 +38,7 @@ module Sass
|
|||
#
|
||||
def initialize(template, options={})
|
||||
@options = {
|
||||
:style => :compact
|
||||
:style => :nested
|
||||
}.merge! options
|
||||
@template = template.split("\n")
|
||||
@lines = []
|
||||
|
|
|
@ -15,8 +15,7 @@ module Sass
|
|||
:template_location => RAILS_ROOT + '/public/stylesheets/sass',
|
||||
:css_location => RAILS_ROOT + '/public/stylesheets',
|
||||
:always_update => false,
|
||||
:always_check => RAILS_ENV != "production",
|
||||
:style => :nested
|
||||
:always_check => RAILS_ENV != "production"
|
||||
}
|
||||
|
||||
# Gets various options for Sass. See README for details.
|
||||
|
|
|
@ -18,12 +18,13 @@ module Sass::Tree
|
|||
if children.size > 0
|
||||
to_return = String.new
|
||||
children.each do |kid|
|
||||
if @style == :expanded
|
||||
to_return << "#{kid.to_s(real_name)}\n "
|
||||
else
|
||||
if @style == :compact
|
||||
to_return << "#{kid.to_s(real_name)} "
|
||||
else
|
||||
to_return << "#{kid.to_s(real_name)}\n"
|
||||
end
|
||||
end
|
||||
to_return << "\n" unless @style == :compact
|
||||
to_return[0...-1]
|
||||
else
|
||||
if value.length < 1
|
||||
|
|
|
@ -20,7 +20,7 @@ module Sass
|
|||
raise SyntaxError.new('Attributes aren\'t allowed at the root of a document.', child.line)
|
||||
end
|
||||
|
||||
result += "#{child.to_s}\n"
|
||||
result += "#{child.to_s(1)}\n"
|
||||
end
|
||||
result[0...-1]
|
||||
end
|
||||
|
|
|
@ -6,11 +6,11 @@ module Sass::Tree
|
|||
alias_method :rule, :value
|
||||
alias_method :rule=, :value=
|
||||
|
||||
def to_s(super_rules = nil)
|
||||
def to_s(tabs, super_rules = nil)
|
||||
attributes = []
|
||||
sub_rules = []
|
||||
total_rule = if super_rules
|
||||
super_rules.split(/,\s*/).collect! do |s|
|
||||
super_rules.split(/,\s*/).collect! do |s|
|
||||
self.rule.split(/,\s*/).collect! {|r| "#{s} #{r}"}.join(", ")
|
||||
end.join(", ")
|
||||
else
|
||||
|
@ -27,14 +27,20 @@ module Sass::Tree
|
|||
|
||||
to_return = ''
|
||||
unless attributes.empty?
|
||||
if @style == :expanded
|
||||
to_return << "#{total_rule} {\n #{attributes.join("\n ").rstrip}\n}\n"
|
||||
else
|
||||
if @style == :compact
|
||||
to_return << "#{total_rule} { #{attributes.join(' ')} }\n"
|
||||
else
|
||||
spaces = (@style == :expanded ? 2 : tabs * 2)
|
||||
old_spaces = ' ' * (spaces - 2)
|
||||
spaces = ' ' * spaces
|
||||
|
||||
attributes = attributes.join("\n").gsub("\n", "\n#{spaces}").rstrip
|
||||
end_attrs = (@style == :expanded ? "\n" : ' ')
|
||||
to_return << "#{old_spaces}#{total_rule} {\n#{spaces}#{attributes}#{end_attrs}}\n"
|
||||
end
|
||||
end
|
||||
|
||||
sub_rules.each { |sub| to_return << sub.to_s(total_rule) }
|
||||
sub_rules.each { |sub| to_return << sub.to_s(tabs + 1, total_rule) }
|
||||
to_return
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
<style>
|
||||
p { border-style: dotted; border-width: 10px; border-color: #ff00ff; }
|
||||
p {
|
||||
border-style: dotted;
|
||||
border-width: 10px;
|
||||
border-color: #ff00ff; }
|
||||
|
||||
h1 { font-weight: normal; }
|
||||
h1 {
|
||||
font-weight: normal; }
|
||||
</style>
|
||||
TESTING HAHAHAHA!
|
||||
<h1>Foo</h1>
|
||||
|
|
|
@ -36,7 +36,13 @@ class SassEngineTest < Test::Unit::TestCase
|
|||
}
|
||||
|
||||
def test_basic_render
|
||||
renders_correctly "basic"
|
||||
renders_correctly "basic", { :style => :compact }
|
||||
end
|
||||
|
||||
def test_alternate_styles
|
||||
renders_correctly "expanded", { :style => :expanded }
|
||||
renders_correctly "compact", { :style => :compact }
|
||||
renders_correctly "nested", { :style => :nested }
|
||||
end
|
||||
|
||||
def test_exceptions
|
||||
|
@ -66,11 +72,10 @@ class SassEngineTest < Test::Unit::TestCase
|
|||
|
||||
private
|
||||
|
||||
def renders_correctly(name)
|
||||
def renders_correctly(name, options={})
|
||||
sass_file = load_file(name, "sass")
|
||||
css_file = load_file(name, "css")
|
||||
css_result = Sass::Engine.new(sass_file).render
|
||||
#puts css_result.collect { |a| a.inspect }.join("\n ")
|
||||
css_result = Sass::Engine.new(sass_file, options).render
|
||||
assert_equal css_file, css_result
|
||||
end
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ class SassPluginTest < Test::Unit::TestCase
|
|||
Sass::Plugin.options = {
|
||||
:template_location => File.dirname(__FILE__) + '/templates',
|
||||
:css_location => File.dirname(__FILE__) + '/tmp',
|
||||
:style => :compact
|
||||
}
|
||||
Sass::Plugin.options[:always_update] = true
|
||||
|
||||
|
@ -24,11 +25,21 @@ class SassPluginTest < Test::Unit::TestCase
|
|||
File.delete(*Dir[tempfile_loc('*')])
|
||||
end
|
||||
|
||||
def test_expanded_style
|
||||
def test_alternate_styles
|
||||
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')
|
||||
|
||||
engine = Sass::Engine.new(File.read(File.dirname(__FILE__) + '/templates/compact.sass'),
|
||||
{ :style => :compact })
|
||||
File.open(tempfile_loc('compact'), 'w') { |f| f.write(engine.render)}
|
||||
assert_renders_correctly('compact')
|
||||
|
||||
engine = Sass::Engine.new(File.read(File.dirname(__FILE__) + '/templates/nested.sass'),
|
||||
{ :style => :nested })
|
||||
File.open(tempfile_loc('nested'), 'w') { |f| f.write(engine.render)}
|
||||
assert_renders_correctly('nested')
|
||||
end
|
||||
|
||||
def test_templates_should_render_correctly
|
||||
|
|
Loading…
Add table
Reference in a new issue