divygrid 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/divy/div_generator.rb +9 -9
- data/lib/divy/grid.rb +38 -2
- data/lib/divy/version.rb +1 -1
- data/test/lib/divy/div_generator_test.rb +3 -3
- data/test/lib/divy/grid_test.rb +65 -0
- data/test/lib/divy/html_examples.yml +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b4eeb20f434b517a67a0626b7a3fea6129ca493
|
4
|
+
data.tar.gz: df0548b8228d09f9225a659c8c3c145b977e5ee0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9052b49613a019c02e5de80ea05850145943aa720b73bbdfe1233d861f542bcab34bddeea3a1a35920b5262815097be70dfe0389cc46d4a8c8a0dc289f6f6b0d
|
7
|
+
data.tar.gz: 79a6f1ccdc2795c020c4040e9cffcace38bc3df81d453f78dc1596b6b650cf34a2ec68a4bc89ca4a0261385f9073551f50725e523dbe01927dc882f3dc6e8353
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/divy/div_generator.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Divy
|
2
2
|
class DivGenerator
|
3
3
|
def divy_container(container_size, container_content)
|
4
|
-
style = "style=\"width: #{size_and_unit(container_size[0])}; height: #{size_and_unit(container_size[1])};\""
|
4
|
+
style = "style=\"position:relative; width: #{size_and_unit(container_size[0])}; height: #{size_and_unit(container_size[1])};\""
|
5
5
|
begin_tag = "<div class=\"divycontainer\" #{style}>\n"
|
6
6
|
end_tag = "</div>\n"
|
7
7
|
begin_tag + container_content + end_tag
|
@@ -28,7 +28,7 @@ module Divy
|
|
28
28
|
when :html
|
29
29
|
divy_box(content[:location][0], content[:location][1], grid_size, content[:value], content[:size], options)
|
30
30
|
when :image
|
31
|
-
divy_box(content[:location][0], content[:location][1], grid_size, image_html(content[:value]), content[:size],options)
|
31
|
+
divy_box(content[:location][0], content[:location][1], grid_size, image_html(content[:value]), content[:size], options)
|
32
32
|
when :none
|
33
33
|
''
|
34
34
|
end
|
@@ -39,7 +39,7 @@ module Divy
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def grid_html(grid_dimensions, options = {})
|
42
|
-
div_grid_html =
|
42
|
+
div_grid_html = ''
|
43
43
|
(0..(grid_dimensions[0] - 1)).each do |x|
|
44
44
|
(0..(grid_dimensions[1] - 1)).each do |y|
|
45
45
|
div_grid_html += divy_box(x, y, grid_dimensions, nil, nil, options)
|
@@ -55,13 +55,13 @@ module Divy
|
|
55
55
|
|
56
56
|
def divy_box_stylez(x, y, grid_size, content_size = nil, options = {})
|
57
57
|
if content_size
|
58
|
-
content_divy_box_stylez(x, y, grid_size, content_size
|
58
|
+
content_divy_box_stylez(x, y, grid_size, content_size)
|
59
59
|
else
|
60
|
-
general_divy_box_stylez(x, y, grid_size,
|
60
|
+
general_divy_box_stylez(x, y, grid_size, options)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def general_divy_box_stylez(x, y, grid_size,
|
64
|
+
def general_divy_box_stylez(x, y, grid_size, options = {})
|
65
65
|
bottom = scaled_value(grid_size[1], y)
|
66
66
|
left = scaled_value(grid_size[0], x)
|
67
67
|
width = scaled_percentage(grid_size[0])
|
@@ -69,12 +69,12 @@ module Divy
|
|
69
69
|
"bottom: #{bottom}%; left: #{left}%; width: #{width}%; height: #{height}%; #{default_stylez(options)}"
|
70
70
|
end
|
71
71
|
|
72
|
-
def content_divy_box_stylez(x, y, grid_size, content_size = nil
|
72
|
+
def content_divy_box_stylez(x, y, grid_size, content_size = nil)
|
73
73
|
bottom = scaled_value(grid_size[1], (y - 0.5))
|
74
74
|
left = scaled_value(grid_size[0], (x - 0.5))
|
75
75
|
width = scaled_value(grid_size[0], content_size[0])
|
76
76
|
height = scaled_value(grid_size[1], content_size[1])
|
77
|
-
"bottom: #{bottom}%; left: #{left}%; width: #{width}%; height: #{height}%; #{default_stylez(
|
77
|
+
"bottom: #{bottom}%; left: #{left}%; width: #{width}%; height: #{height}%; #{default_stylez(nil)}"
|
78
78
|
end
|
79
79
|
|
80
80
|
def scaled_value(total_units, val)
|
@@ -86,7 +86,7 @@ module Divy
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def default_stylez(options = {})
|
89
|
-
if options[:show_grid]
|
89
|
+
if options && options[:show_grid]
|
90
90
|
color = options[:grid_color] || '#000000'
|
91
91
|
"position: absolute; border-style:solid; border-color:#{color};"
|
92
92
|
else
|
data/lib/divy/grid.rb
CHANGED
@@ -11,6 +11,42 @@ module Divy
|
|
11
11
|
@div_generator = Divy::DivGenerator.new
|
12
12
|
end
|
13
13
|
|
14
|
+
def content=(input)
|
15
|
+
if input.kind_of?(Array)
|
16
|
+
@content = validated_content_arr(input)
|
17
|
+
elsif input.kind_of?(Hash)
|
18
|
+
@content = [validated_content_hsh(input)]
|
19
|
+
end
|
20
|
+
rescue
|
21
|
+
@content = @content
|
22
|
+
end
|
23
|
+
|
24
|
+
def container_size=(input)
|
25
|
+
@container_size = validated_container_size(input)
|
26
|
+
rescue
|
27
|
+
@container_size = @container_size
|
28
|
+
end
|
29
|
+
|
30
|
+
def grid_dimensions=(input)
|
31
|
+
@grid_dimensions = validated_number_array(input)
|
32
|
+
rescue
|
33
|
+
@grid_dimensions = @grid_dimensions
|
34
|
+
end
|
35
|
+
|
36
|
+
def grid_color=(input)
|
37
|
+
@grid_color = validated_hex_color(input)
|
38
|
+
rescue
|
39
|
+
@grid_color = @grid_color
|
40
|
+
end
|
41
|
+
|
42
|
+
def show_grid=(input)
|
43
|
+
if input.kind_of?(TrueClass) || input.kind_of?(FalseClass)
|
44
|
+
@show_grid = input
|
45
|
+
else
|
46
|
+
@show_grid = @show_grid
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
14
50
|
def add_content(input_content)
|
15
51
|
@content += validated_content_arr(input_content)
|
16
52
|
end
|
@@ -43,8 +79,8 @@ module Divy
|
|
43
79
|
|
44
80
|
def validated_content_hsh(content_hsh)
|
45
81
|
if valid_content_type?(content_hsh)
|
46
|
-
content_hsh[:location] = validated_number_array(content_hsh[:location] || [0,0])
|
47
|
-
content_hsh[:size] = validated_number_array(content_hsh[:size] || [1,1])
|
82
|
+
content_hsh[:location] = validated_number_array(content_hsh[:location] || [0, 0])
|
83
|
+
content_hsh[:size] = validated_number_array(content_hsh[:size] || [1, 1])
|
48
84
|
content_hsh[:value] ||= ''
|
49
85
|
content_hsh
|
50
86
|
else
|
data/lib/divy/version.rb
CHANGED
@@ -70,7 +70,7 @@ describe Divy::DivGenerator do
|
|
70
70
|
|
71
71
|
it 'should return modified content styles if content size is passed' do
|
72
72
|
options = {show_grid: true, grid_color: '#00FFFF'}
|
73
|
-
style = 'bottom: 15.0%; left: 5.0%; width: 20.0%; height: 20.0%; position: absolute;
|
73
|
+
style = 'bottom: 15.0%; left: 5.0%; width: 20.0%; height: 20.0%; position: absolute;'
|
74
74
|
@test_div.divy_box_stylez(1, 2, [10, 10], [2, 2], options).must_equal style
|
75
75
|
end
|
76
76
|
end
|
@@ -89,12 +89,12 @@ describe Divy::DivGenerator do
|
|
89
89
|
|
90
90
|
describe '#divy_container' do
|
91
91
|
it 'should wrap the given content in a divycontainer div with %' do
|
92
|
-
div_content = "<div class=\"divycontainer\" style=\"width: 100%; height: 100%;\">\ntest content</div>\n"
|
92
|
+
div_content = "<div class=\"divycontainer\" style=\"position:relative; width: 100%; height: 100%;\">\ntest content</div>\n"
|
93
93
|
@test_div.divy_container(['100%', '100%'], 'test content').must_equal div_content
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should wrap the given content in a divycontainer div with as px' do
|
97
|
-
div_content = "<div class=\"divycontainer\" style=\"width: 100px; height: 100px;\">\ntest content</div>\n"
|
97
|
+
div_content = "<div class=\"divycontainer\" style=\"position:relative; width: 100px; height: 100px;\">\ntest content</div>\n"
|
98
98
|
@test_div.divy_container([100, 100], 'test content').must_equal div_content
|
99
99
|
end
|
100
100
|
|
data/test/lib/divy/grid_test.rb
CHANGED
@@ -203,4 +203,69 @@ describe Divy::Grid do
|
|
203
203
|
@grid.html.must_equal (@html_results[4] + "\n")
|
204
204
|
end
|
205
205
|
end
|
206
|
+
|
207
|
+
describe '#content=' do
|
208
|
+
it 'sets content if valid array' do
|
209
|
+
@grid.content = [{type: :html, value: 'totally valid', location: [1, 3], size: [1, 1]}]
|
210
|
+
@grid.content.must_equal([{type: :html, value: 'totally valid', location: [1, 3], size: [1, 1]}])
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'sets content if valid hash' do
|
214
|
+
@grid.content = {type: :html, value: 'totally valid', location: [1, 3], size: [1, 1]}
|
215
|
+
@grid.content.must_equal([{type: :html, value: 'totally valid', location: [1, 3], size: [1, 1]}])
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'does not change content if invalid' do
|
219
|
+
@grid.content = 'not quite right'
|
220
|
+
@grid.content.wont_equal 'not quite right'
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe '#container_size=' do
|
225
|
+
it 'sets container size if valid' do
|
226
|
+
@grid.container_size = [4, 5]
|
227
|
+
@grid.container_size.must_equal [4, 5]
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'does not set container size if invalid' do
|
231
|
+
@grid.container_size = [4, 5, 6, 7]
|
232
|
+
@grid.container_size.wont_equal [4, 5, 6, 7]
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe '#grid_dimensions=' do
|
237
|
+
it 'sets grid dimensions if valid' do
|
238
|
+
@grid.grid_dimensions = [4, 5]
|
239
|
+
@grid.grid_dimensions.must_equal [4, 5]
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'does not set grid dimensions if invalid' do
|
243
|
+
@grid.grid_dimensions = [4, 5, 6, 7]
|
244
|
+
@grid.grid_dimensions.wont_equal [4, 5, 6, 7]
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe '#grid_color=' do
|
249
|
+
it 'sets grid color if valid' do
|
250
|
+
@grid.grid_color = '#FFFFFF'
|
251
|
+
@grid.grid_color.must_equal '#FFFFFF'
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'does not set grid color if invalid' do
|
255
|
+
@grid.grid_color = 'notacolor'
|
256
|
+
@grid.grid_color.wont_equal 'notacolor'
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe '#show_grid=' do
|
261
|
+
it 'sets show grid if a boolean' do
|
262
|
+
@grid.show_grid = true
|
263
|
+
@grid.show_grid.must_equal true
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'does not set show grid if not a boolean' do
|
267
|
+
@grid.show_grid = 'bunnies!'
|
268
|
+
@grid.show_grid.wont_equal 'bunnie!'
|
269
|
+
end
|
270
|
+
end
|
206
271
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
---
|
2
2
|
- |-
|
3
|
-
<div class="divycontainer" style="width: 100px; height: 100px;">
|
4
|
-
<div class="divybox" style="bottom: 50.0%; left: 10.0%; width: 20.0%; height: 20.0%; position: absolute;
|
5
|
-
<div class="divybox" style="bottom: 50.0%; left: 10.0%; width: 40.0%; height: 40.0%; position: absolute;
|
3
|
+
<div class="divycontainer" style="position:relative; width: 100px; height: 100px;">
|
4
|
+
<div class="divybox" style="bottom: 50.0%; left: 10.0%; width: 20.0%; height: 20.0%; position: absolute;">coolhtmlstuff</div>
|
5
|
+
<div class="divybox" style="bottom: 50.0%; left: 10.0%; width: 40.0%; height: 40.0%; position: absolute;"><img src="someimagepath" height="100%" width="100%"></img></div>
|
6
6
|
<div class="divybox" style="bottom: 0.0%; left: 0.0%; width: 20.0%; height: 20.0%; position: absolute; border-style:solid; border-color:#FF00CC;"></div>
|
7
7
|
<div class="divybox" style="bottom: 20.0%; left: 0.0%; width: 20.0%; height: 20.0%; position: absolute; border-style:solid; border-color:#FF00CC;"></div>
|
8
8
|
<div class="divybox" style="bottom: 40.0%; left: 0.0%; width: 20.0%; height: 20.0%; position: absolute; border-style:solid; border-color:#FF00CC;"></div>
|
@@ -40,13 +40,13 @@
|
|
40
40
|
<div class="divybox" style="bottom: 33.333333333333336%; left: 66.66666666666667%; width: 33.333333333333336%; height: 33.333333333333336%; position: absolute;"></div>
|
41
41
|
<div class="divybox" style="bottom: 66.66666666666667%; left: 66.66666666666667%; width: 33.333333333333336%; height: 33.333333333333336%; position: absolute;"></div>
|
42
42
|
- |
|
43
|
-
<div class="divybox" style="bottom: 25.0%; left: 5.0%; width: 10.0%; height: 10.0%; position: absolute;
|
44
|
-
<div class="divybox" style="bottom: 45.0%; left: 5.0%; width: 10.0%; height: 10.0%; position: absolute;
|
43
|
+
<div class="divybox" style="bottom: 25.0%; left: 5.0%; width: 10.0%; height: 10.0%; position: absolute;">coolhtmlstuff</div>
|
44
|
+
<div class="divybox" style="bottom: 45.0%; left: 5.0%; width: 10.0%; height: 10.0%; position: absolute;"><img src="someimagepath" height="100%" width="100%"></img></div>
|
45
45
|
- |
|
46
46
|
<div class="divybox" style="bottom: 25.0%; left: 5.0%; width: 10.0%; height: 10.0%; position: absolute;">coolhtmlstuff</div>
|
47
47
|
<div class="divybox" style="bottom: 45.0%; left: 5.0%; width: 10.0%; height: 10.0%; position: absolute;"><img src="someimagepath" height="100%" width="100%"></img></div>
|
48
48
|
- |-
|
49
|
-
<div class="divycontainer" style="width: 100%; height: 100%;">
|
49
|
+
<div class="divycontainer" style="position:relative; width: 100%; height: 100%;">
|
50
50
|
<div class="divybox" style="bottom: 0.0%; left: 0.0%; width: 10.0%; height: 10.0%; position: absolute;"></div>
|
51
51
|
<div class="divybox" style="bottom: 10.0%; left: 0.0%; width: 10.0%; height: 10.0%; position: absolute;"></div>
|
52
52
|
<div class="divybox" style="bottom: 20.0%; left: 0.0%; width: 10.0%; height: 10.0%; position: absolute;"></div>
|