5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/sinatra/bootstrap/helpers.rb', line 5
def cols(tag, attrb = {}, &block)
cols = attrb[:cols] || ''
offset = attrb[:offset] || ''
extr_class = attrb[:class].nil? ? '' : " #{attrb[:class]}"
attrb.delete :cols
attrb.delete :offset
attrb.delete :class
extr_attrb = ''
attrb.each do |key, value|
extr_attrb << " #{key}=\"#{value}\""
end
unless /^([abcd]{1}\d+){1,}$/ === cols || /^([abcd]{1}\d+){1,}$/ === offset then return '' end
unless /^([abcd]{1}\d+){1,}$/ === cols then cols = '' end
unless /^([abcd]{1}\d+){1,}$/ === offset then offset = '' end
values = { cols: [], offset: [] }
/a{1}(\d+)/.match(cols) do |m|
values[:cols] << ['xs', m.captures.first]
end
/b{1}(\d+)/.match(cols) do |m|
values[:cols] << ['sm', m.captures.first]
end
/c{1}(\d+)/.match(cols) do |m|
values[:cols] << ['md', m.captures.first]
end
/d{1}(\d+)/.match(cols) do |m|
values[:cols] << ['lg', m.captures.first]
end
/a{1}(\d+)/.match(offset) do |m|
values[:offset] << ['xs', m.captures.first]
end
/b{1}(\d+)/.match(offset) do |m|
values[:offset] << ['sm', m.captures.first]
end
/c{1}(\d+)/.match(offset) do |m|
values[:offset] << ['md', m.captures.first]
end
/d{1}(\d+)/.match(offset) do |m|
values[:offset] << ['lg', m.captures.first]
end
classes = ''
values[:cols].each do |type, number|
classes << "col-#{type}-#{number} "
end
values[:offset].each do |type, number|
classes << "col-#{type}-offset-#{number} "
end
classes.strip!
concat_content "<#{tag} class=\"#{classes}#{extr_class}\"#{extr_attrb}>"
concat_content "#{ capture_html &block }</#{tag}>"
end
|