ionfish-stylish 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Rakefile +1 -1
- data/VERSION.yml +1 -1
- data/lib/stylish/core.rb +11 -0
- data/lib/stylish/extended.rb +26 -2
- data/lib/stylish/formattable.rb +2 -0
- data/lib/stylish/generate.rb +6 -1
- data/lib/stylish.rb +2 -0
- data/test/background_test.rb +7 -0
- data/test/generate_test.rb +10 -0
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== Version 0.1.6 (2009-06-02)
|
2
|
+
|
3
|
+
API polish
|
4
|
+
* New Stylesheet#print method to serialise a tree to a file.
|
5
|
+
* Avoid incomprehensible stack traces by raising an explicit error if a user
|
6
|
+
fails to define a variable when serialising a stylesheet.
|
7
|
+
* Add support for the background-clip property to the Background class.
|
8
|
+
|
9
|
+
|
1
10
|
=== Version 0.1.5 (2009-05-03)
|
2
11
|
|
3
12
|
Improved background support
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
s.name = "stylish"
|
7
7
|
s.summary = "Write CSS with Ruby"
|
8
8
|
s.email = "benedict@eastaugh.net"
|
9
|
-
s.homepage = "http://github.com/
|
9
|
+
s.homepage = "http://ionfish.github.com/stylish/"
|
10
10
|
s.description = "A Ruby library for generating cascading stylesheets."
|
11
11
|
s.authors = ["Benedict Eastaugh"]
|
12
12
|
end
|
data/VERSION.yml
CHANGED
data/lib/stylish/core.rb
CHANGED
@@ -37,6 +37,17 @@ module Stylish
|
|
37
37
|
return "" if @nodes.empty?
|
38
38
|
@nodes.map {|node| node.to_s(symbols) }.join(self.class.format)
|
39
39
|
end
|
40
|
+
|
41
|
+
# A convenience method to print the stylesheet to a file.
|
42
|
+
def print(filename, symbols = {})
|
43
|
+
serialised = self.to_s(symbols)
|
44
|
+
|
45
|
+
File.open(filename, "w+") do |f|
|
46
|
+
f.puts(serialised)
|
47
|
+
end
|
48
|
+
|
49
|
+
serialised
|
50
|
+
end
|
40
51
|
end
|
41
52
|
|
42
53
|
# Rule objects represent CSS rules, and serialise to them. They possess one
|
data/lib/stylish/extended.rb
CHANGED
@@ -54,6 +54,7 @@ module Stylish
|
|
54
54
|
[:repeat, "background-repeat"],
|
55
55
|
[:position, "background-position"],
|
56
56
|
[:attachment, "background-attachment"],
|
57
|
+
[:clip, "background-clip"],
|
57
58
|
[:origin, "background-origin"],
|
58
59
|
[:break, "background-break"],
|
59
60
|
[:compressed]]
|
@@ -63,6 +64,7 @@ module Stylish
|
|
63
64
|
ATTACHMENT_VALUES = ["scroll", "fixed", "local"]
|
64
65
|
ORIGIN_VALUES = ["border-box", "padding-box", "content-box"]
|
65
66
|
BREAK_VALUES = ["bounding-box", "each-box", "continuous"]
|
67
|
+
CLIP_VALUES = ORIGIN_VALUES | ["no-clip"]
|
66
68
|
|
67
69
|
PROPERTIES.each do |name, value|
|
68
70
|
attr_reader name
|
@@ -170,10 +172,32 @@ module Stylish
|
|
170
172
|
end
|
171
173
|
end
|
172
174
|
|
175
|
+
# The background-clip property specifies the background painting area.
|
176
|
+
#
|
177
|
+
# clipped = Background.new :clip => "no-clip"
|
178
|
+
# clipped.to_s # => "background-clip:no-clip;"
|
179
|
+
#
|
180
|
+
def clip=(clip)
|
181
|
+
@clip = clip if CLIP_VALUES.include? clip
|
182
|
+
end
|
183
|
+
|
184
|
+
# The background-clip property is a CSS3 property and can take multiple
|
185
|
+
# values.
|
186
|
+
#
|
187
|
+
# clipper = Background.new :clips => ["border-box", "padding-box"]
|
188
|
+
# clipper.to_s # => "background-clip:border-box, padding-box;"
|
189
|
+
#
|
190
|
+
def clips=(clips)
|
191
|
+
@clip = clips.inject(PropertyBundle.new) do |cs, c|
|
192
|
+
cs << c if CLIP_VALUES.include? c
|
193
|
+
cs
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
173
197
|
# The background-origin property specifies the background positioning area.
|
174
198
|
#
|
175
199
|
# original = Background.new :origin => "content-box"
|
176
|
-
# original.to_s # => background-origin:content-box;
|
200
|
+
# original.to_s # => "background-origin:content-box;"
|
177
201
|
#
|
178
202
|
def origin=(origin)
|
179
203
|
@origin = origin if ORIGIN_VALUES.include? origin
|
@@ -183,7 +207,7 @@ module Stylish
|
|
183
207
|
# values.
|
184
208
|
#
|
185
209
|
# origs = Background.new :origin => ["padding-box", "content-box"]
|
186
|
-
# origs.to_s # => background-origin:padding-box, content-box;
|
210
|
+
# origs.to_s # => "background-origin:padding-box, content-box;"
|
187
211
|
#
|
188
212
|
def origins=(origins)
|
189
213
|
@origin = origins.inject(PropertyBundle.new) do |os, o|
|
data/lib/stylish/formattable.rb
CHANGED
data/lib/stylish/generate.rb
CHANGED
@@ -138,7 +138,12 @@ module Stylish
|
|
138
138
|
replaceable = name_or_hash || @name
|
139
139
|
|
140
140
|
if replaceable.is_a? Symbol
|
141
|
-
symbol_table[replaceable]
|
141
|
+
if symbol_table[replaceable]
|
142
|
+
symbol_table[replaceable]
|
143
|
+
else
|
144
|
+
raise UndefinedVariable,
|
145
|
+
":#{replaceable.to_s} could not be located in the symbol table."
|
146
|
+
end
|
142
147
|
elsif replaceable.is_a?(Hash) || replaceable.is_a?(Array)
|
143
148
|
replaceable.to_a.inject(replaceable.class.new) do |acc, el|
|
144
149
|
if acc.is_a? Hash
|
data/lib/stylish.rb
CHANGED
data/test/background_test.rb
CHANGED
@@ -77,6 +77,13 @@ class BackgroundTest < Test::Unit::TestCase
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def test_clips
|
81
|
+
clipper = Stylish::Background.new :clips => ["no-clip", "content-box"]
|
82
|
+
|
83
|
+
assert_equal(2, clipper.clip.length)
|
84
|
+
assert_equal("background-clip:no-clip, content-box;", clipper.to_s)
|
85
|
+
end
|
86
|
+
|
80
87
|
def test_origins
|
81
88
|
original = Stylish::Background.new :origins => ["border-box", "padding-box"]
|
82
89
|
|
data/test/generate_test.rb
CHANGED
@@ -94,4 +94,14 @@ class GenerateTest < Test::Unit::TestCase
|
|
94
94
|
"background-position:left top, right top, right bottom, left bottom;}",
|
95
95
|
style.to_s({:pos => "bottom"}))
|
96
96
|
end
|
97
|
+
|
98
|
+
def test_undefined_variables
|
99
|
+
style = Stylish.generate do
|
100
|
+
body :color => :super_colour
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_raise Stylish::UndefinedVariable do
|
104
|
+
style.to_s({})
|
105
|
+
end
|
106
|
+
end
|
97
107
|
end
|
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.
|
4
|
+
version: 0.1.6
|
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-
|
12
|
+
date: 2009-06-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -51,7 +51,7 @@ files:
|
|
51
51
|
- test/tree_test.rb
|
52
52
|
- test/variable_test.rb
|
53
53
|
has_rdoc: true
|
54
|
-
homepage: http://github.com/
|
54
|
+
homepage: http://ionfish.github.com/stylish/
|
55
55
|
post_install_message:
|
56
56
|
rdoc_options:
|
57
57
|
- --charset=UTF-8
|