style_train 0.3.1 → 0.3.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -112,11 +112,15 @@ CSS
112
112
 
113
113
  def background( opts )
114
114
  str = ""
115
- str << property('background-color', Color.new(opts[:color])) if opts[:color]
116
- str << property('background-image', "url('#{opts[:image]}')") if opts[:image]
117
- str << property('background-position', opts[:position]) if opts[:position]
118
- str << property('background-attachment', opts[:attachment]) if opts[:attachment]
119
- str << property('background-repeat', background_repeat_value(opts[:repeat])) if opts[:repeat]
115
+ if opts.is_a?(Hash)
116
+ str << property('background-color', Color.new(opts[:color])) if opts[:color]
117
+ str << property('background-image', "url('#{opts[:image]}')") if opts[:image]
118
+ str << property('background-position', opts[:position]) if opts[:position]
119
+ str << property('background-attachment', opts[:attachment]) if opts[:attachment]
120
+ str << property('background-repeat', background_repeat_value(opts[:repeat])) if opts[:repeat]
121
+ else
122
+ str << property('background', opts )
123
+ end
120
124
  str
121
125
  end
122
126
 
@@ -131,32 +135,51 @@ CSS
131
135
  end
132
136
  end
133
137
 
134
- def border(opts={})
138
+ def border(*args)
139
+ str = ""
140
+ if args.size == 1
141
+ opts = args.first
142
+ else
143
+ opts = args.last || {}
144
+ none = true
145
+ end
146
+
147
+
135
148
  if opts.is_a?(Hash)
136
149
  value = border_value(opts)
137
150
  if only = opts[:only]
138
- if only.is_a?(Array)
139
- str = ""
140
- only.each do |type|
141
- str << property( "border-#{type}", value )
142
- end
143
- str
144
- else
145
- property "border-#{only}", value
151
+ Array(only).flatten.each do |side|
152
+ value = :none if none
153
+ str << property("border-#{side}", value)
146
154
  end
147
- else
148
- property "border", value
155
+ else
156
+ str << property( "border", value )
149
157
  end
150
158
  else
151
- property "border", opts
159
+ str << property( "border", opts )
152
160
  end
161
+
162
+ str
163
+ end
164
+
165
+ ['left', 'right', 'top', 'bottom'].each do |side|
166
+ class_eval <<-RUBY
167
+ def border_#{side}(opts={})
168
+ property('border-#{side}', border_value(opts))
169
+ end
170
+ RUBY
153
171
  end
154
172
 
173
+
155
174
  def border_value(opts)
156
- color = opts[:color] || 'black'
157
- style = opts[:style] || 'solid'
158
- width = opts[:width] || '1px'
159
- "#{width} #{style} #{color}"
175
+ if opts.is_a?(Hash)
176
+ color = opts[:color] || 'black'
177
+ style = opts[:style] || 'solid'
178
+ width = opts[:width] || opts[:size] || '1px'
179
+ "#{width} #{style} #{color}"
180
+ else
181
+ opts.to_s
182
+ end
160
183
  end
161
184
 
162
185
  def outline(opts={})
@@ -201,33 +224,29 @@ CSS
201
224
 
202
225
  def margin(*opts)
203
226
  opts = opts.size == 1 ? opts.first : opts
204
- if opts.is_a?(Array)
205
- property('margin', opts)
206
- elsif opts.is_a?(String)
207
- property('margin', opts)
227
+ if opts.is_a?(Hash)
228
+ str = ""
229
+ str << property('margin-left', opts[:left]) if opts[:left]
230
+ str << property('margin-top', opts[:top]) if opts[:top]
231
+ str << property('margin-bottom', opts[:bottom]) if opts[:bottom]
232
+ str << property('margin-right', opts[:right]) if opts[:right]
233
+ str
208
234
  else
209
- str = ""
210
- str << property('margin-left', opts[:left]) if opts[:left]
211
- str << property('margin-top', opts[:top]) if opts[:top]
212
- str << property('margin-bottom', opts[:bottom]) if opts[:bottom]
213
- str << property('margin-right', opts[:right]) if opts[:right]
214
- str
235
+ property('margin', opts)
215
236
  end
216
237
  end
217
238
 
218
239
  def padding(*opts)
219
240
  opts = opts.size == 1 ? opts.first : opts
220
- if opts.is_a?(Array)
221
- property('padding', opts)
222
- elsif opts.is_a?(String)
223
- property('padding', opts)
224
- else
241
+ if opts.is_a?(Hash)
225
242
  str = ""
226
243
  str << property('padding-left', opts[:left]) if opts[:left]
227
244
  str << property('padding-top', opts[:top]) if opts[:top]
228
245
  str << property('padding-bottom', opts[:bottom]) if opts[:bottom]
229
246
  str << property('padding-right', opts[:right]) if opts[:right]
230
247
  str
248
+ else
249
+ property('padding', opts)
231
250
  end
232
251
  end
233
252
 
@@ -275,9 +294,18 @@ CSS
275
294
  end
276
295
  end
277
296
 
297
+ def opacity(value)
298
+ value = value.to_f
299
+ str = ""
300
+ str << property( 'opacity', value )
301
+ str << property( 'filter', "alpha(opacity=#{(value*100).to_i})")
302
+ str
303
+ end
304
+
278
305
  [
279
- 'color', 'display', 'float', 'clear', 'visibility', 'cursor', 'opacity',
280
- 'height', 'width', 'max_height', 'max_width', 'min_height', 'min_width'
306
+ 'color', 'display', 'float', 'clear', 'visibility', 'cursor',
307
+ 'height', 'width', 'max_height', 'max_width', 'min_height', 'min_width',
308
+ "overflow_x", 'overflow_y', 'z_index'
281
309
  ].each do |meth|
282
310
  class_eval <<-RUBY
283
311
  def #{meth}(value)
@@ -402,7 +430,7 @@ CSS
402
430
 
403
431
  def export opts={}
404
432
  name = file_name(opts[:file_name])
405
- str = render (opts[:render_method] || :content), opts
433
+ str = render(opts[:render_method] || :content), opts
406
434
  File.open("#{StyleTrain.dir}/#{file_name}.css", 'w'){ |f| f.write(str) }
407
435
  end
408
436
 
data/spec/sheet_spec.rb CHANGED
@@ -217,8 +217,9 @@ CSS
217
217
  @sheet.background(:repeat => :none).should include 'background-repeat: no-repeat'
218
218
  end
219
219
 
220
- it 'will create a background-color property if it receives a string that converts to a color'
221
- it 'will create a background-color property if it receives a color'
220
+ it 'will create a background property if it receives a single non options argument' do
221
+ @sheet.background(:blue).should include 'background: blue'
222
+ end
222
223
  end
223
224
 
224
225
  describe 'border' do
@@ -227,7 +228,11 @@ CSS
227
228
  end
228
229
 
229
230
  it 'takes the width it is passed in' do
230
- @sheet.border(:width => 3.px).should include 'border: 3px solid black;'
231
+ @sheet.border(:width => 3.px).should include 'border: 3px solid black'
232
+ end
233
+
234
+ it 'takes in the width as size too' do
235
+ @sheet.border(:size => 5.px).should include 'border: 5px solid black'
231
236
  end
232
237
 
233
238
  it 'takes in the color when it is passed in' do
@@ -251,6 +256,21 @@ CSS
251
256
  it 'should do :none' do
252
257
  @sheet.border(:none).should include 'border: none'
253
258
  end
259
+
260
+ it 'should work with :only and :none' do
261
+ @sheet.border(:none, :only => [:bottom, :left]).should include(
262
+ 'border-bottom: none', 'border-left: none'
263
+ )
264
+ end
265
+
266
+ describe 'specific borders' do
267
+ it 'has a method for each side' do
268
+ @sheet.border_left.should include 'border-left: 1px solid black'
269
+ @sheet.border_right.should include 'border-right: 1px solid black'
270
+ @sheet.border_top.should include 'border-top: 1px solid black'
271
+ @sheet.border_bottom.should include 'border-bottom: 1px solid black'
272
+ end
273
+ end
254
274
  end
255
275
 
256
276
  describe 'outline' do
@@ -286,7 +306,7 @@ CSS
286
306
  end
287
307
  end
288
308
 
289
- describe '#height' do
309
+ describe '#width' do
290
310
  it 'makes a height declaration' do
291
311
  @sheet.width(320.px).should include 'width: 320px;'
292
312
  end
@@ -299,6 +319,13 @@ CSS
299
319
  @sheet.min_width(200.px).should include 'min-width: 200px'
300
320
  end
301
321
  end
322
+
323
+ describe '#dimensions' do
324
+ it 'takes an array'
325
+ it 'takes two arguments'
326
+ it 'takes an array and options with min and max'
327
+ it 'takes two dimension arguments and options with min and max'
328
+ end
302
329
  end
303
330
 
304
331
  describe 'position' do
@@ -560,12 +587,24 @@ CSS
560
587
  @sheet.color(StyleTrain::Color.new('#456')).should include 'color: #456'
561
588
  end
562
589
 
563
- it 'overflows' do
590
+ it 'overflow' do
564
591
  @sheet.overflow(:hidden).should include 'overflow: hidden'
565
592
  @sheet.overflow(:x => :scroll).should include 'overflow-x: scroll'
566
593
  @sheet.overflow(:y => :auto).should include 'overflow-y: auto'
567
594
  end
568
595
 
596
+ it 'overflow_x' do
597
+ @sheet.overflow_x(:auto).should include 'overflow-x: auto'
598
+ end
599
+
600
+ it 'overflow_y' do
601
+ @sheet.overflow_y(:scroll).should include 'overflow-y: scroll'
602
+ end
603
+
604
+ it 'z_index' do
605
+ @sheet.z_index(3).should include 'z-index: 3'
606
+ end
607
+
569
608
  it 'display' do
570
609
  @sheet.display(:block).should include 'display: block'
571
610
  end
@@ -583,7 +622,9 @@ CSS
583
622
  end
584
623
 
585
624
  it 'opacity' do
586
- @sheet.opacity(0.5).should include 'opacity: 0.5'
625
+ str = @sheet.opacity(0.5)
626
+ str.should include 'opacity: 0.5'
627
+ str.should include 'filter: alpha(opacity=50)'
587
628
  end
588
629
  end
589
630
  end
data/style_train.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{style_train}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kane Baccigalupi"]
12
- s.date = %q{2011-03-02}
12
+ s.date = %q{2011-03-03}
13
13
  s.description = %q{style_train builds CSS using pure Ruby, not a DSL interpreted via Ruby. This allows inheritance, modules, instance level calculations and all the goodness Ruby can offer.}
14
14
  s.email = %q{baccigalupi@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: style_train
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kane Baccigalupi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-02 00:00:00 -08:00
18
+ date: 2011-03-03 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency