ionfish-stylish 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- === Version 0.1.3 (TODO)
1
+ === Version 0.1.4 (2009-04-25)
2
+
3
+ Bug fixes
4
+ * Fix variable and selector serialisation bugs
5
+
6
+
7
+ === Version 0.1.3 (2009-04-24)
2
8
 
3
9
  Variables in the DSL
4
10
  * Selector and property variables
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 3
3
+ :patch: 4
4
4
  :major: 0
@@ -214,7 +214,7 @@ module Stylish
214
214
  #
215
215
  # Otherwise it will produce an unordered list of individual background
216
216
  # declarations.
217
- def to_s(symbols = {})
217
+ def to_s(symbols = {}, scope = "")
218
218
  if @compressed
219
219
  "background:#{self.value(true).map {|p, v| v }.compact.join(" ")};"
220
220
  else
data/lib/stylish/color.rb CHANGED
@@ -373,7 +373,7 @@ module Stylish #:nodoc:
373
373
  # color.type = :rgb
374
374
  # color.to_s # => "rgb(0, 0, 0)"
375
375
  #
376
- def to_s(symbols = {})
376
+ def to_s(symbols = {}, scope = "")
377
377
  return "inherit" if @type == :inherit
378
378
 
379
379
  self.send(:"to_#{self.type.to_s}")
data/lib/stylish/core.rb CHANGED
@@ -192,8 +192,7 @@ module Stylish
192
192
  # The Selector class is also used internally by the Tree::SelectorScope
193
193
  # class, to store its scope value.
194
194
  def to_s(symbols = {}, scope = "")
195
- (scope.empty? ? "" : scope + " ") +
196
- (@selector.is_a?(String) ? @selector.to_s : @selector.to_s(symbols))
195
+ (scope.empty? ? "" : scope + " ") + @selector
197
196
  end
198
197
  end
199
198
 
@@ -109,16 +109,16 @@ module Stylish
109
109
  # the tree is traversed. Nodes must then serialise themselves, and if
110
110
  # they contain Variables they must pass them the symbol table so that
111
111
  # they can be resolved to a given value.
112
- def to_s(symbols)
112
+ def to_s(symbols, scope = "")
113
113
  if @constructor.nil?
114
114
  symbols[@name]
115
115
  elsif @name.is_a? Symbol
116
- @constructor.new(symbols[@name]).to_s
116
+ @constructor.new(symbols[@name]).to_s(symbols, scope)
117
117
  else
118
118
  @constructor.new(@name.to_a.inject({}) {|a, e|
119
119
  a[e.first] = symbols[e.last]
120
120
  a
121
- }).to_s
121
+ }).to_s(symbols, scope)
122
122
  end
123
123
  end
124
124
  end
@@ -219,7 +219,7 @@ module Stylish
219
219
 
220
220
  selectors = [selectors] unless selectors.is_a?(Array)
221
221
  selectors.map! do |s|
222
- Selector.new(s.is_a?(Symbol) ? Variable.new(s) : s)
222
+ s.is_a?(Symbol) ? Variable.new(s, Selector) : Selector.new(s)
223
223
  end
224
224
 
225
225
  declarations = Generate.parse_declarations(declarations)
data/lib/stylish/tree.rb CHANGED
@@ -45,8 +45,8 @@ module Stylish
45
45
  def initialize(selector)
46
46
  accept_format(/\s*/m, "\n")
47
47
 
48
- @scope = Selector.new(selector)
49
48
  @nodes = []
49
+ @scope = selector
50
50
  end
51
51
 
52
52
  # Return the child node at the given index.
@@ -86,8 +86,10 @@ module Stylish
86
86
  # Recursively serialise the selector tree.
87
87
  def to_s(symbols = {}, scope = "")
88
88
  return "" if @nodes.empty?
89
- scope = scope.empty? ? @scope.to_s : scope + " " + @scope.to_s
90
- @nodes.map {|node| node.to_s(symbols, scope) }.join(@format)
89
+
90
+ @nodes.map {|node|
91
+ node.to_s(symbols, @scope.to_s(symbols, scope))
92
+ }.join(@format)
91
93
  end
92
94
 
93
95
  # Return the node's child nodes.
@@ -2,8 +2,8 @@ class StylesheetTest < Test::Unit::TestCase
2
2
 
3
3
  def setup
4
4
  @style = Stylish::Stylesheet.new
5
- @node = Stylish::Tree::SelectorScope.new("div")
6
- @onde = Stylish::Tree::SelectorScope.new("span")
5
+ @node = Stylish::Tree::SelectorScope.new(Stylish::Selector.new("div"))
6
+ @onde = Stylish::Tree::SelectorScope.new(Stylish::Selector.new("span"))
7
7
  @rule = Stylish::Rule.new([Stylish::Selector.new("em")],
8
8
  [Stylish::Declaration.new("font-weight", "bold")])
9
9
  end
data/test/tree_test.rb CHANGED
@@ -2,7 +2,7 @@ class TreeTest < Test::Unit::TestCase
2
2
 
3
3
  def setup
4
4
  @tree = Stylish::Stylesheet.new
5
- @node = Stylish::Tree::SelectorScope.new(".test")
5
+ @node = Stylish::Tree::SelectorScope.new(Stylish::Selector.new(".test"))
6
6
  @rule = Stylish::Rule.new([Stylish::Selector.new("p")],
7
7
  [Stylish::Declaration.new("font-weight", "bold")])
8
8
  @comment = Stylish::Comment.new("Comment header",
@@ -45,7 +45,8 @@ class TreeTest < Test::Unit::TestCase
45
45
  end
46
46
 
47
47
  def test_selector_serialisation
48
- onde = Stylish::Tree::SelectorScope.new(".parent > .child")
48
+ selector = Stylish::Selector.new(".parent > .child")
49
+ onde = Stylish::Tree::SelectorScope.new(selector)
49
50
  @node << @rule
50
51
  onde << @rule
51
52
  @tree << @node
@@ -19,10 +19,22 @@ class VariableTest < Test::Unit::TestCase
19
19
  def test_selector_variables
20
20
  style = Stylish.generate do
21
21
  rule :some_selector, :line_height => 1.5
22
+
23
+ rule :some_other_selector do
24
+ em :font_weight => "bold"
25
+ end
26
+
27
+ form do
28
+ rule :third_selector, :text_transform => "uppercase"
29
+ end
22
30
  end
23
31
 
24
- assert_equal("body p {line-height:1.5;}",
25
- style.to_s({:some_selector => "body p"}))
32
+ assert_equal("body p {line-height:1.5;}\n" +
33
+ "div em {font-weight:bold;}\n" +
34
+ "form legend {text-transform:uppercase;}",
35
+ style.to_s({:some_selector => "body p",
36
+ :some_other_selector => "div",
37
+ :third_selector => "legend"}))
26
38
  end
27
39
 
28
40
  def test_color_variables
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ionfish-stylish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benedict Eastaugh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-24 00:00:00 -07:00
12
+ date: 2009-04-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -73,7 +73,7 @@ requirements: []
73
73
  rubyforge_project:
74
74
  rubygems_version: 1.2.0
75
75
  signing_key:
76
- specification_version: 2
76
+ specification_version: 3
77
77
  summary: Write CSS with Ruby
78
78
  test_files:
79
79
  - test/background_test.rb