style_train 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LISENCE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +27 -0
- data/VERSION +1 -0
- data/lib/style_train/color.rb +103 -0
- data/lib/style_train/color_types/color_type.rb +218 -0
- data/lib/style_train/color_types/hex_color.rb +44 -0
- data/lib/style_train/color_types/hsl_color.rb +5 -0
- data/lib/style_train/color_types/keyword_color.rb +192 -0
- data/lib/style_train/color_types/rgb_color.rb +57 -0
- data/lib/style_train/sheet.rb +234 -0
- data/lib/style_train/support/gnash.rb +143 -0
- data/lib/style_train/support/numbers.rb +23 -0
- data/lib/style_train/support/string.rb +24 -0
- data/lib/style_train.rb +22 -0
- data/spec/color/color_spec.rb +224 -0
- data/spec/color/color_type_spec.rb +370 -0
- data/spec/color/hex_color_spec.rb +160 -0
- data/spec/color/keyword_color_spec.rb +56 -0
- data/spec/color/rgb_color_spec.rb +75 -0
- data/spec/numbers_spec.rb +25 -0
- data/spec/sheet_spec.rb +549 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +11 -0
- data/style_train.gemspec +74 -0
- data/utils/alexch_color_gist/color.rb +160 -0
- data/utils/alexch_color_gist/color_test.rb +176 -0
- data/utils/overview.txt +151 -0
- data/utils/stylesheet.txt +161 -0
- metadata +102 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
HexColor = StyleTrain::HexColor unless defined?( HexColor )
|
4
|
+
|
5
|
+
describe HexColor do
|
6
|
+
describe 'class methods' do
|
7
|
+
it 'should expand a 3-digit hex' do
|
8
|
+
HexColor.expand('333').should == 0x333333
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'initialization' do
|
13
|
+
describe 'from another color' do
|
14
|
+
it 'should convert correctly from a RGB color' do
|
15
|
+
color = StyleTrain::RGBcolor.new(:color => [20, 40, 60])
|
16
|
+
hex = HexColor.new(color)
|
17
|
+
hex.r.should == color.r
|
18
|
+
hex.g.should == color.g
|
19
|
+
hex.b.should == color.b
|
20
|
+
hex.hex.upcase.should == '14283C'
|
21
|
+
hex.hex_6.should == 0x14283C
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'from a hex without a hash and possibly a number' do
|
26
|
+
before do
|
27
|
+
@gray = HexColor.new(:color => 666)
|
28
|
+
@red = HexColor.new(:color => '993300')
|
29
|
+
@gold = HexColor.new(:color => 'FC0')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should set the #hex attribute' do
|
33
|
+
@gray.hex.should == '666'
|
34
|
+
@red.hex.should == '993300'
|
35
|
+
@gold.hex.should == 'FC0'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should set the #hex_6 attribute' do
|
39
|
+
@gray.hex_6.should == 0x666666
|
40
|
+
@red.hex_6.should == 0x993300
|
41
|
+
@gold.hex_6.should == 0xFFCC00
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should set the #r attribute' do
|
45
|
+
@gray.r.should == 102
|
46
|
+
@red.r.should == 153
|
47
|
+
@gold.r.should == 255
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should set the #g attribute' do
|
51
|
+
@gray.g.should == 102
|
52
|
+
@red.g.should == 51
|
53
|
+
@gold.g.should == 204
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should set the #b attribute' do
|
57
|
+
@gray.b.should == 102
|
58
|
+
@red.b.should == 0
|
59
|
+
@gold.b.should == 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'from a three digit hex' do
|
64
|
+
before do
|
65
|
+
@gray = HexColor.new(:color =>'#666')
|
66
|
+
@red = HexColor.new(:color => '#930')
|
67
|
+
@gold = HexColor.new(:color => '#FC0')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should set the #hex attribute' do
|
71
|
+
@gray.hex.should == '666'
|
72
|
+
@red.hex.should == '930'
|
73
|
+
@gold.hex.should == 'FC0'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should set the #hex_6 attribute' do
|
77
|
+
@gray.hex_6.should == 0x666666
|
78
|
+
@red.hex_6.should == 0x993300
|
79
|
+
@gold.hex_6.should == 0xFFCC00
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should set the #r attribute' do
|
83
|
+
@gray.r.should == 102
|
84
|
+
@red.r.should == 153
|
85
|
+
@gold.r.should == 255
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should set the #g attribute' do
|
89
|
+
@gray.g.should == 102
|
90
|
+
@red.g.should == 51
|
91
|
+
@gold.g.should == 204
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should set the #b attribute' do
|
95
|
+
@gray.b.should == 102
|
96
|
+
@red.b.should == 0
|
97
|
+
@gold.b.should == 0
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'from a 6 digit hex' do
|
102
|
+
before do
|
103
|
+
@gray = HexColor.new(:color => '#666666')
|
104
|
+
@red = HexColor.new(:color =>'#993300')
|
105
|
+
@gold = HexColor.new(:color => '#FFCC00')
|
106
|
+
@mix = HexColor.new(:color => '#6b602f')
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should set the #hex attribute' do
|
110
|
+
@gray.hex.should == '666666'
|
111
|
+
@red.hex.should == '993300'
|
112
|
+
@gold.hex.should == 'FFCC00'
|
113
|
+
@mix.hex.should == '6b602f'
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should set the #hex_6 attribute' do
|
117
|
+
@gray.hex_6.should == 0x666666
|
118
|
+
@red.hex_6.should == 0x993300
|
119
|
+
@gold.hex_6.should == 0xFFCC00
|
120
|
+
@mix.hex_6.should == 0x6b602f
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should set the #r attribute' do
|
124
|
+
@gray.r.should == 102
|
125
|
+
@red.r.should == 153
|
126
|
+
@gold.r.should == 255
|
127
|
+
@mix.r.should == 107
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should set the #g attribute' do
|
131
|
+
@gray.g.should == 102
|
132
|
+
@red.g.should == 51
|
133
|
+
@gold.g.should == 204
|
134
|
+
@mix.g.should == 96
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should set the #b attribute' do
|
138
|
+
@gray.b.should == 102
|
139
|
+
@red.b.should == 0
|
140
|
+
@gold.b.should == 0
|
141
|
+
@mix.b.should == 47
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#to_s' do
|
147
|
+
before do
|
148
|
+
@color = HexColor.new(:color => '666')
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should render with the original passed in value if no alpha is present' do
|
152
|
+
@color.to_s.should == "#666"
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should render as rgba if alpha is present' do
|
156
|
+
@color.alpha = 0.5
|
157
|
+
@color.to_s.should == "rgba( 102, 102, 102, 0.5 )"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
KeywordColor = StyleTrain::KeywordColor unless defined?( KeywordColor )
|
4
|
+
|
5
|
+
describe KeywordColor do
|
6
|
+
describe 'accessors' do
|
7
|
+
it 'should have methods for #keyword= and #keyword' do
|
8
|
+
KeywordColor.instance_methods.should include( 'keyword=', 'keyword' )
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should raise an error if the keyword is not found' do
|
12
|
+
lambda{ KeywordColor.new(:color => :puke) }.should raise_error( KeywordColor::KeywordError)
|
13
|
+
color = KeywordColor.new(:color => :lightyellow)
|
14
|
+
lambda{ color.keyword = :puke }.should raise_error(KeywordColor::KeywordError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should set the keyword attribute' do
|
18
|
+
color = KeywordColor.new(:color => :lightyellow)
|
19
|
+
color.keyword.should == :lightyellow
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'initialization' do
|
24
|
+
describe 'from a color' do
|
25
|
+
it 'should find a keyword if it maps' do
|
26
|
+
rgb = StyleTrain::RGBcolor.new(:color => [255,255,224])
|
27
|
+
light_yellow = KeywordColor.new( rgb )
|
28
|
+
light_yellow.r.should == 255
|
29
|
+
light_yellow.g.should == 255
|
30
|
+
light_yellow.b.should == 224
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an error if it does not map' do
|
34
|
+
rgb = StyleTrain::RGBcolor.new(:color => [255,255,220])
|
35
|
+
lambda{ KeywordColor.new( rgb ) }.should raise_error( KeywordColor::KeywordError )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'from a keyword' do
|
40
|
+
it 'should have the right rgb values' do
|
41
|
+
light_yellow = KeywordColor.new(:color => :lightyellow)
|
42
|
+
light_yellow.r.should == 255
|
43
|
+
light_yellow.g.should == 255
|
44
|
+
light_yellow.b.should == 224
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'rendering' do
|
50
|
+
it 'should render as given by default' do
|
51
|
+
light_yellow = KeywordColor.new(:color => :lightyellow)
|
52
|
+
light_yellow.render.should == 'lightyellow'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
RGBcolor = StyleTrain::RGBcolor unless defined?( RGBcolor )
|
4
|
+
|
5
|
+
describe RGBcolor do
|
6
|
+
|
7
|
+
it 'should have methods for #red=, #green= and #blue=' do
|
8
|
+
RGBcolor.instance_methods.should include( 'red=', 'green=', 'blue=' )
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'array initialization' do
|
12
|
+
it '#red #green and #blue should be set to passed values' do
|
13
|
+
color = RGBcolor.new(:color => [20, 40, 60])
|
14
|
+
color.red.should == 20
|
15
|
+
color.green.should == 40
|
16
|
+
color.blue.should == 60
|
17
|
+
|
18
|
+
color = RGBcolor.new(:color => ['20', '40', '60'])
|
19
|
+
color.red.should == '20'
|
20
|
+
color.green.should == '40'
|
21
|
+
color.blue.should == '60'
|
22
|
+
|
23
|
+
color = RGBcolor.new(:color => ['0%', '50%', '100%'])
|
24
|
+
color.red.should == '0%'
|
25
|
+
color.green.should == '50%'
|
26
|
+
color.blue.should == '100%'
|
27
|
+
end
|
28
|
+
|
29
|
+
it '#r #g and #b (the internal storage ) should be set' do
|
30
|
+
color = RGBcolor.new(:color => [20, 40, 60])
|
31
|
+
color.r.should == 20
|
32
|
+
color.g.should == 40
|
33
|
+
color.b.should == 60
|
34
|
+
|
35
|
+
color = RGBcolor.new(:color => ['20', '40', '60'])
|
36
|
+
color.r.should == 20
|
37
|
+
color.g.should == 40
|
38
|
+
color.b.should == 60
|
39
|
+
|
40
|
+
color = RGBcolor.new(:color => ['0%', '50%', '100%'])
|
41
|
+
color.r.should == 0
|
42
|
+
color.g.should == 127
|
43
|
+
color.b.should == 255
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# This should be a shared example
|
48
|
+
describe 'alpha' do
|
49
|
+
it 'should be 1.0 by default' do
|
50
|
+
color = RGBcolor.new(:color => ['0%', '50%', '100%'])
|
51
|
+
color.alpha.should == 1.0
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should be set by the alpha parameter' do
|
55
|
+
color = RGBcolor.new(:color => ['0%', '50%', '100%'], :alpha => 0.5 )
|
56
|
+
color.alpha.should == 0.5
|
57
|
+
|
58
|
+
color = RGBcolor.new(:color => ['0%', '50%', '100%'], :alpha => '0.5' )
|
59
|
+
color.alpha.should == 0.5
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'render should output rgb css tag' do
|
64
|
+
RGBcolor.new(:color => ['0%', '50%', '100%'] ).render.should ==
|
65
|
+
"rgb( 0%, 50%, 100% )"
|
66
|
+
|
67
|
+
RGBcolor.new(:color => [255, 255, 255] ).render.should ==
|
68
|
+
"rgb( 255, 255, 255 )"
|
69
|
+
|
70
|
+
RGBcolor.new(:color => ['255', '255', '255'] ).render.should ==
|
71
|
+
"rgb( 255, 255, 255 )"
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Fixnum do
|
4
|
+
it '#em converts to a string with em at the end' do
|
5
|
+
42.em.should == '42em'
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#px converts to a string with px at the end' do
|
9
|
+
42.px.should == '42px'
|
10
|
+
end
|
11
|
+
|
12
|
+
it '#percent converts to a string with % at the end' do
|
13
|
+
42.percent.should == '42%'
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#pt converts to a string with % at the end' do
|
17
|
+
42.pt.should == '42pt'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Float do
|
22
|
+
it '#em converts to a string with em at the end' do
|
23
|
+
1.5.em.should == '1.5em'
|
24
|
+
end
|
25
|
+
end
|
data/spec/sheet_spec.rb
ADDED
@@ -0,0 +1,549 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
Sheet = StyleTrain::Sheet unless defined?( Sheet )
|
4
|
+
|
5
|
+
describe Sheet do
|
6
|
+
describe 'attributes' do
|
7
|
+
before :all do
|
8
|
+
@sheet = Sheet.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should have an output' do
|
12
|
+
@sheet.output = 'foo'
|
13
|
+
@sheet.output.should == 'foo'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'output gets set to an empty string on initialize' do
|
17
|
+
Sheet.new.output.should == ''
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have an indent_level that is initialized to 0' do
|
21
|
+
Sheet.new.indent_level.should == 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#render' do
|
26
|
+
before :all do
|
27
|
+
@sheet = Sheet.new
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'resets the output' do
|
31
|
+
@sheet.should_receive(:output=).with('')
|
32
|
+
@sheet.render
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'calls #content by default' do
|
36
|
+
@sheet.should_receive(:content)
|
37
|
+
@sheet.render
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'calls an alterate content method' do
|
41
|
+
@sheet.should_not_receive(:content)
|
42
|
+
@sheet.should_receive(:foo)
|
43
|
+
@sheet.render :foo
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the output' do
|
47
|
+
@sheet.output = "bar"
|
48
|
+
@sheet.stub(:output=)
|
49
|
+
@sheet.stub(:content).and_return('foo')
|
50
|
+
@sheet.render.should == "bar"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#style' do
|
55
|
+
before do
|
56
|
+
@sheet = Sheet.new
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'adds an entry to the output' do
|
60
|
+
@sheet.output.should == ""
|
61
|
+
@sheet.style(:foo)
|
62
|
+
@sheet.output.should_not == ""
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'renders the right style when passed a string' do
|
66
|
+
@sheet.style('.foo')
|
67
|
+
@sheet.output.should include '.foo'
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'renders the right selecter when passed a non-tag symbol' do
|
71
|
+
@sheet.style(:bar)
|
72
|
+
@sheet.output.should include '.bar'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'renders the right style when passed a tag symbol' do
|
76
|
+
@sheet.style(:body)
|
77
|
+
@sheet.output.should include 'body'
|
78
|
+
@sheet.output.should_not include '.body'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'renders {} when not passed a block' do
|
82
|
+
@sheet.style(:body)
|
83
|
+
@sheet.output.should include "body {\n}"
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'receiving a block' do
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'nesting' do
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'tags' do
|
94
|
+
before do
|
95
|
+
@sheet = Sheet.new
|
96
|
+
end
|
97
|
+
|
98
|
+
Sheet::TAGS.each do |tag|
|
99
|
+
it "should have a method for '#{tag}'" do
|
100
|
+
@sheet.should respond_to(tag)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should add a style for '#{tag}'" do
|
104
|
+
@sheet.send(tag)
|
105
|
+
@sheet.output.should include "#{tag} {\n}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should pass the block on to the style method' do
|
110
|
+
str = @sheet.instance_eval <<-RUBY
|
111
|
+
body do
|
112
|
+
margin [2.em, :auto]
|
113
|
+
end
|
114
|
+
RUBY
|
115
|
+
str.should include 'margin: 2em auto'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'properties' do
|
120
|
+
before :all do
|
121
|
+
@sheet = Sheet.new
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#property' do
|
125
|
+
before :all do
|
126
|
+
@sheet.indent_level = 4
|
127
|
+
@property = @sheet.property('border', '1px solid #ccc' )
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'returns a string' do
|
131
|
+
@property.is_a?(String).should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'adds a line break and an indent to the front of the string' do
|
135
|
+
@property.match(/^\W{5}/).should_not be_nil
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'includes the property name' do
|
139
|
+
@property.should include 'border'
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'includes punctuation' do
|
143
|
+
@property.should include ':', ';'
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'includes the value' do
|
147
|
+
@property.should include '1px solid #ccc'
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'puts it all together correctly' do
|
151
|
+
@property.should == "\n border: 1px solid #ccc;"
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'adds the string to the output' do
|
155
|
+
@sheet.output.should include @property
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'converts an array to a space separated string' do
|
159
|
+
@sheet.property('margin', [0,0,0,0]).should include '0 0 0 0'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'background' do
|
164
|
+
it ':color will create a background-color property' do
|
165
|
+
@sheet.background(:color => :white).should include 'background-color: white;'
|
166
|
+
end
|
167
|
+
|
168
|
+
it ':image will create a background-image property' do
|
169
|
+
@sheet.background(:image => "url('ok.png')").should include "background-image: url('ok.png');"
|
170
|
+
end
|
171
|
+
|
172
|
+
it ':position will create a background-position property' do
|
173
|
+
@sheet.background(:position => "center").should include 'background-position: center;'
|
174
|
+
end
|
175
|
+
|
176
|
+
it ':attachment will create a background-attachment property' do
|
177
|
+
@sheet.background(:attachment => 'fixed').should include 'background-attachment: fixed;'
|
178
|
+
end
|
179
|
+
|
180
|
+
it ':repeat will create a background-repeat property with the correct value' do
|
181
|
+
@sheet.background(:repeat => :x).should include "background-repeat: repeat-x;"
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'will create a background-color property if it receives a string that converts to a color'
|
185
|
+
it 'will create a background-color property if it receives a color'
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'border' do
|
189
|
+
it 'it defaults to 1px solid black' do
|
190
|
+
@sheet.border.should include 'border: 1px solid black;'
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'takes the width it is passed in' do
|
194
|
+
@sheet.border(:width => 3.px).should include 'border: 3px solid black;'
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'takes in the color when it is passed in' do
|
198
|
+
@sheet.border(:color => StyleTrain::Color.new('#333')).should include 'border: 1px solid #333'
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'takes in the style when it is passed in' do
|
202
|
+
@sheet.border(:style => 'dashed').should include 'border: 1px dashed black'
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'makes a declaration for only a certain type of border when requested' do
|
206
|
+
@sheet.border(:only => :bottom).should include 'border-bottom: 1px solid black'
|
207
|
+
end
|
208
|
+
|
209
|
+
it ':only option works as an array too' do
|
210
|
+
@sheet.border(:only => [:bottom, :left]).should include(
|
211
|
+
'border-bottom: 1px solid black', 'border-left: 1px solid black'
|
212
|
+
)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe 'outline' do
|
217
|
+
it 'it defaults to 1px solid black' do
|
218
|
+
@sheet.outline.should include 'outline: 1px solid black;'
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'takes the width it is passed in' do
|
222
|
+
@sheet.outline(:width => 3.px).should include 'outline: 3px solid black;'
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'takes in the color when it is passed in' do
|
226
|
+
@sheet.outline(:color => StyleTrain::Color.new('#333')).should include 'outline: 1px solid #333'
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'takes in the style when it is passed in' do
|
230
|
+
@sheet.outline(:style => 'dashed').should include 'outline: 1px dashed black'
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe 'dimensions' do
|
235
|
+
describe '#height' do
|
236
|
+
it 'makes a height declaration' do
|
237
|
+
@sheet.height(320.px).should include 'height: 320px;'
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'will make a max declaration too' do
|
241
|
+
@sheet.max_height(400.px).should include 'max-height: 400px'
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'will make a min width declaration' do
|
245
|
+
@sheet.min_height(200.px).should include 'min-height: 200px'
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe '#height' do
|
250
|
+
it 'makes a height declaration' do
|
251
|
+
@sheet.width(320.px).should include 'width: 320px;'
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'will make a max declaration too' do
|
255
|
+
@sheet.max_width(400.px).should include 'max-width: 400px'
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'will make a min width declaration' do
|
259
|
+
@sheet.min_width(200.px).should include 'min-width: 200px'
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'position' do
|
265
|
+
it 'takes a string argument and makes a position declaration' do
|
266
|
+
@sheet.position( 'absolute' ).should include 'position: absolute'
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'take a symbol and makes a position declaration' do
|
270
|
+
@sheet.position( :relative ).should include 'position: relative'
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'takes a option for type and makes a position declaration' do
|
274
|
+
@sheet.position(:type => :fixed).should include 'position: fixed'
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'makes a bottom declaration' do
|
278
|
+
@sheet.position(:bottom => 5.px).should include 'bottom: 5px'
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'makes a right declaration' do
|
282
|
+
@sheet.position(:right => 15.px).should include 'right: 15px'
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'makes a top declaration' do
|
286
|
+
@sheet.position(:top => 25.px).should include 'top: 25px'
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'makes a left declaration' do
|
290
|
+
@sheet.position(:left => 35.px).should include 'left: 35px'
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'floats' do
|
294
|
+
@sheet.position(:float => :left).should include 'float: left'
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'clears' do
|
298
|
+
@sheet.position(:clear => :both).should include 'clear: both'
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'has a display declaration' do
|
302
|
+
@sheet.position(:display => :inline).should include 'display: inline'
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'constructs visibility' do
|
306
|
+
@sheet.position(:visibility => :hidden).should include 'visibility: hidden'
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'has a z-index' do
|
310
|
+
@sheet.position(:z_index => 5).should include 'z-index: 5'
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'has overflow declarations' do
|
314
|
+
@sheet.position(:overflow => :scroll).should include 'overflow: scroll'
|
315
|
+
@sheet.position(:overflow_x => :hidden).should include 'overflow-x: hidden'
|
316
|
+
@sheet.position(:overflow_y => :visible).should include 'overflow-y: visible'
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'has a clip declaration' do
|
320
|
+
@sheet.position(:clip => [10.px, 20.px, 30.px, 40.px]).should include 'clip: rect(10px 20px 30px 40px)'
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
describe 'text' do
|
325
|
+
it 'adds a font-family declaration when passed a font option' do
|
326
|
+
@sheet.text(:font => 'arial').should include 'font-family: arial;'
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'adds a font-size declaration whet passed' do
|
330
|
+
@sheet.text(:size => 23.pt).should include 'font-size: 23pt;'
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'adds a style declaration' do
|
334
|
+
@sheet.text(:style => :italic).should include 'font-style: italic;'
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'adds a variant declaration' do
|
338
|
+
@sheet.text(:variant => 'small-caps').should include 'font-variant: small-caps;'
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'adds a weight declaration' do
|
342
|
+
@sheet.text(:weight => 'bold').should include 'font-weight: bold;'
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'adds color' do
|
346
|
+
@sheet.text(:color => '#444').should include 'color: #444;'
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'adds direction' do
|
350
|
+
@sheet.text(:direction => :rtl).should include 'text-direction: rtl'
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'adds letter spacing' do
|
354
|
+
@sheet.text(:spacing => -2.px).should include 'letter-spacing: -2px'
|
355
|
+
end
|
356
|
+
|
357
|
+
it 'adds line height' do
|
358
|
+
@sheet.text(:line_height => 2).should include 'line-height: 2'
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'aligns' do
|
362
|
+
@sheet.text(:align => :center).should include 'text-align: center'
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'adds decoration' do
|
366
|
+
@sheet.text(:decoration => :underline).should include 'text-decoration: underline'
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'indents' do
|
370
|
+
@sheet.text(:indent => 20.px).should include 'text-indent: 20px'
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'adds a transform' do
|
374
|
+
@sheet.text(:transform => :uppercase).should include 'text-transform: uppercase'
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'adds a vertical align' do
|
378
|
+
@sheet.text(:vertical_align => :top).should include 'vertical-align: top'
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'adds white space declaration' do
|
382
|
+
@sheet.text(:white_space => :nowrap).should include 'white-space: nowrap'
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'specifies word spacing' do
|
386
|
+
@sheet.text(:word_spacing => 25.px).should include 'word-spacing: 25px'
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe 'list' do
|
391
|
+
it 'sets the image' do
|
392
|
+
@sheet.list(:image => 'url("foo.gif")').should include 'list-style-image: url("foo.gif")'
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'sets the position' do
|
396
|
+
@sheet.list(:position => :inside).should include 'list-style-position: inside'
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'sets the type' do
|
400
|
+
@sheet.list(:type => :square).should include 'list-style-type: square'
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe 'margin' do
|
405
|
+
it 'takes an array' do
|
406
|
+
@sheet.margin( [10.px, 20.px, 13.px] ).should include 'margin: 10px 20px 13px'
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'takes :left and just makes that declaration' do
|
410
|
+
@sheet.margin( :left => 30.px ).should include 'margin-left: 30px'
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'takes :left and just makes that declaration' do
|
414
|
+
@sheet.margin( :right => 20.px ).should include 'margin-right: 20px'
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'takes :left and just makes that declaration' do
|
418
|
+
@sheet.margin( :top => 10.px ).should include 'margin-top: 10px'
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'takes :left and just makes that declaration' do
|
422
|
+
@sheet.margin( :bottom => 15.px ).should include 'margin-bottom: 15px'
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
describe 'padding' do
|
427
|
+
it 'takes an array' do
|
428
|
+
@sheet.padding( [10.px, 20.px, 13.px] ).should include 'padding: 10px 20px 13px'
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'takes :left and just makes that declaration' do
|
432
|
+
@sheet.padding( :left => 30.px ).should include 'padding-left: 30px'
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'takes :left and just makes that declaration' do
|
436
|
+
@sheet.padding( :right => 20.px ).should include 'padding-right: 20px'
|
437
|
+
end
|
438
|
+
|
439
|
+
it 'takes :left and just makes that declaration' do
|
440
|
+
@sheet.padding( :top => 10.px ).should include 'padding-top: 10px'
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'takes :left and just makes that declaration' do
|
444
|
+
@sheet.padding( :bottom => 15.px ).should include 'padding-bottom: 15px'
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
describe 'table_options' do
|
449
|
+
it 'has border option' do
|
450
|
+
@sheet.table_options(:border => :collapse).should include 'border-collapse: collapse'
|
451
|
+
end
|
452
|
+
|
453
|
+
it 'border spacing option' do
|
454
|
+
@sheet.table_options(:border_spacing => [20.px, 30.px]).should include 'border-spacing: 20px 30px'
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'has a caption option' do
|
458
|
+
@sheet.table_options(:caption => :bottom).should include 'caption-side: bottom'
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'has empty option' do
|
462
|
+
@sheet.table_options(:empty => :hide).should include 'empty-cells: hide'
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'has a layout' do
|
466
|
+
@sheet.table_options(:layout => :fixed).should include 'table-layout: fixed'
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
describe 'print' do
|
471
|
+
# orphans Sets the minimum number of lines that must be left at the bottom of a page when a page break occurs inside an element 2
|
472
|
+
# page-break-after Sets the page-breaking behavior after an element 2
|
473
|
+
# page-break-before Sets the page-breaking behavior before an element 2
|
474
|
+
# page-break-inside Sets the page-breaking behavior inside an element 2
|
475
|
+
# widows Sets the minimum number of lines that must be left at the top of a page when a page break occurs inside an element 2
|
476
|
+
end
|
477
|
+
|
478
|
+
describe 'misc' do
|
479
|
+
# content Used with the :before and :after pseudo-elements, to insert generated content 2
|
480
|
+
# counter-increment Increments one or more counters 2
|
481
|
+
# counter-reset Creates or resets one or more counters 2
|
482
|
+
# quotes Sets the type of quotation marks for embedded quotations 2
|
483
|
+
# cursor Specifies the type of cursor to be displayed 2
|
484
|
+
it 'has a cursor declaration' do
|
485
|
+
@sheet.cursor(:crosshair).should include 'cursor: crosshair'
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
describe 'duplicate declarations' do
|
490
|
+
it 'color' do
|
491
|
+
@sheet.color(StyleTrain::Color.new('#456')).should include 'color: #456'
|
492
|
+
end
|
493
|
+
|
494
|
+
it 'overflows' do
|
495
|
+
@sheet.overflow(:hidden).should include 'overflow: hidden'
|
496
|
+
@sheet.overflow(:x => :scroll).should include 'overflow-x: scroll'
|
497
|
+
@sheet.overflow(:y => :auto).should include 'overflow-y: auto'
|
498
|
+
end
|
499
|
+
|
500
|
+
it 'display' do
|
501
|
+
@sheet.display(:block).should include 'display: block'
|
502
|
+
end
|
503
|
+
|
504
|
+
it 'float' do
|
505
|
+
@sheet.float(:left).should include 'float: left'
|
506
|
+
end
|
507
|
+
|
508
|
+
it 'clear' do
|
509
|
+
@sheet.clear(:both).should include 'clear: both'
|
510
|
+
end
|
511
|
+
|
512
|
+
it 'visibility' do
|
513
|
+
@sheet.visibility(:hidden).should include 'visibility: hidden'
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
describe 'subclassing' do
|
519
|
+
class StyleSheet < StyleTrain::Sheet
|
520
|
+
def content
|
521
|
+
body {
|
522
|
+
background :color => '#666'
|
523
|
+
text :font => 'verdana'
|
524
|
+
}
|
525
|
+
|
526
|
+
style('#wrapper'){
|
527
|
+
background :color => :white
|
528
|
+
margin [1.em, :auto]
|
529
|
+
}
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
it 'works' do
|
534
|
+
StyleSheet.render.should include(
|
535
|
+
<<-CSS
|
536
|
+
body {
|
537
|
+
background-color: #666;
|
538
|
+
font-family: verdana;
|
539
|
+
}
|
540
|
+
|
541
|
+
#wrapper {
|
542
|
+
background-color: white;
|
543
|
+
margin: 1em auto;
|
544
|
+
}
|
545
|
+
CSS
|
546
|
+
)
|
547
|
+
end
|
548
|
+
end
|
549
|
+
end
|