dom-rb 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/csr/dom/browser_ext/node.rb +4 -0
- data/csr/dom/builder/base.rb +2 -2
- data/csr/dom/builder/helpers.rb +117 -120
- data/csr/dom/table/base.rb +12 -0
- data/csr/dom/table/column.rb +14 -14
- data/csr/dom/table/row.rb +6 -4
- data/csr/dom/table/section.rb +0 -2
- data/lib/dom/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4094aecbbafbb4c2a1dd1ef9fdc792654ee33ae6
|
4
|
+
data.tar.gz: e559c378becd4619c814853b4450ecbcb79a8d1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0d3f612e5d765e75aae4739cfb80a9a95520b58222062f4d498b3a674da96e1ecff2d64afa8eb507f18f17cf1c671226dc53971db6f51e73ccbb1450c913f0
|
7
|
+
data.tar.gz: 56c46eff3826114066929e5ffa50e0176c3716735a182d253649c78f85e76866b99970073d547b6cf7067f64fd7c52d94ff0c5073e294ec945310aa8ab47db7a
|
data/csr/dom/browser_ext/node.rb
CHANGED
data/csr/dom/builder/base.rb
CHANGED
@@ -72,7 +72,7 @@ module CSR
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def resolve_value(element, value, bindings, id, attr, tag_name)
|
75
|
-
|
75
|
+
debug 1, ->{[ __FILE__, __LINE__, __method__, "tag=#{tag_name} value=#{value} bindings=#{bindings} id=#{id} attr=#{attr}" ]}
|
76
76
|
result = case value
|
77
77
|
when BoundProc
|
78
78
|
# debug 1, ->{[ __FILE__, __LINE__, __method__, "BoundProc===value" ]}
|
@@ -95,7 +95,7 @@ module CSR
|
|
95
95
|
# debug 1, ->{[ __FILE__, __LINE__, __method__, "value=#{value}" ]}
|
96
96
|
value
|
97
97
|
end
|
98
|
-
|
98
|
+
debug 1, ->{[ __FILE__, __LINE__, __method__, "result=#{result}" ]}
|
99
99
|
result
|
100
100
|
end
|
101
101
|
|
data/csr/dom/builder/helpers.rb
CHANGED
@@ -5,39 +5,28 @@ require 'dom/builder/base'
|
|
5
5
|
module CSR
|
6
6
|
module DOM
|
7
7
|
module Builder
|
8
|
-
|
9
8
|
module_function
|
10
9
|
|
11
|
-
def icon(name, callback: nil,
|
12
|
-
|
10
|
+
def icon(name, callback: nil, attributes: nil)
|
11
|
+
style = {
|
13
12
|
text_align: 'center',
|
14
|
-
vertical_align: 'middle',
|
15
13
|
color: 'inherit',
|
16
14
|
background_color: 'inherit',
|
17
15
|
cursor: 'pointer',
|
18
16
|
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
{ } # { margin_top: '0.2em', margin_right: '0.5em' }
|
30
|
-
end
|
31
|
-
)
|
17
|
+
klass = iconify(name)
|
18
|
+
if attributes
|
19
|
+
if attributes[:style]
|
20
|
+
# arg style overrides any defaults
|
21
|
+
style = style.merge(attributes[:style])
|
22
|
+
end
|
23
|
+
if attributes[:class]
|
24
|
+
klass = klass + ' ' + attributes[:class]
|
25
|
+
end
|
32
26
|
end
|
33
|
-
# arg style overrides any defaults
|
34
|
-
_style = _style.merge(style) if style
|
35
|
-
_class = iconify(name)
|
36
|
-
_class = "#{_class} #{css}" if css
|
37
|
-
_class = "#{_class} pull-#{float}" if float
|
38
27
|
attributes = {
|
39
|
-
class:
|
40
|
-
style:
|
28
|
+
class: klass,
|
29
|
+
style: style
|
41
30
|
}.merge(
|
42
31
|
callback ? { onclick: callback } : {}
|
43
32
|
)
|
@@ -47,24 +36,33 @@ module CSR
|
|
47
36
|
)
|
48
37
|
end
|
49
38
|
|
50
|
-
def icon_with_anchor(icon_name, href,
|
51
|
-
|
39
|
+
def icon_with_anchor(icon_name, href, icon_attributes: nil, anchor_attributes: nil)
|
40
|
+
attributes = { href: href }
|
41
|
+
if anchor_attributes
|
42
|
+
attributes = anchor_attributes.merge(attributes)
|
43
|
+
end
|
52
44
|
tag(
|
53
45
|
:a,
|
54
|
-
attributes:
|
55
|
-
|
56
|
-
style: anchor_style,
|
57
|
-
class: anchor_css || '',
|
58
|
-
},
|
59
|
-
content: _icon
|
46
|
+
attributes: attributes,
|
47
|
+
content: icon(icon_name, attributes: icon_attributes)
|
60
48
|
)
|
61
49
|
end
|
62
50
|
|
63
|
-
def
|
51
|
+
def plus_sign_icon_anchor(href, icon_attributes: nil, anchor_attributes: nil)
|
52
|
+
_icon_attributes = {
|
53
|
+
style: {
|
54
|
+
color: 'lightgreen',
|
55
|
+
}
|
56
|
+
}
|
57
|
+
if icon_attributes
|
58
|
+
# argument takes precedence
|
59
|
+
_icon_attributes = _icon_attributes.merge(icon_attributes)
|
60
|
+
end
|
64
61
|
icon_with_anchor(
|
65
62
|
:plus_sign,
|
66
63
|
href,
|
67
|
-
|
64
|
+
icon_attributes: _icon_attributes,
|
65
|
+
anchor_attributes: anchor_attributes
|
68
66
|
)
|
69
67
|
end
|
70
68
|
|
@@ -72,7 +70,7 @@ module CSR
|
|
72
70
|
icon(
|
73
71
|
:remove_sign,
|
74
72
|
callback: callback,
|
75
|
-
style: {color: 'red'}
|
73
|
+
attributes: { style: {color: 'red'} }
|
76
74
|
)
|
77
75
|
end
|
78
76
|
|
@@ -80,7 +78,7 @@ module CSR
|
|
80
78
|
icon(
|
81
79
|
:refresh,
|
82
80
|
callback: callback,
|
83
|
-
style: {color: 'inherit'}
|
81
|
+
attributes: { style: {color: 'inherit'} }
|
84
82
|
)
|
85
83
|
end
|
86
84
|
|
@@ -88,7 +86,7 @@ module CSR
|
|
88
86
|
icon(
|
89
87
|
:save,
|
90
88
|
callback: callback,
|
91
|
-
style: {color: 'inherit'}
|
89
|
+
attributes: { style: {color: 'inherit'} }
|
92
90
|
)
|
93
91
|
end
|
94
92
|
|
@@ -96,7 +94,7 @@ module CSR
|
|
96
94
|
icon(
|
97
95
|
:menu_hamburger,
|
98
96
|
callback: callback,
|
99
|
-
style: {color: 'inherit'}
|
97
|
+
attributes: { style: {color: 'inherit'} }
|
100
98
|
)
|
101
99
|
end
|
102
100
|
|
@@ -105,91 +103,79 @@ module CSR
|
|
105
103
|
# 1. icon: is the name of the (bootstrap) icon
|
106
104
|
# 2. items: should be hashes containing menu items
|
107
105
|
# e.g. { callback: ->{}, href: '#', content: 'list item'}
|
108
|
-
# 3.
|
109
|
-
# 4.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
106
|
+
# 3. menu_right: set true if right of menu should go under icon
|
107
|
+
# 4. icon_attributes: any attributes for icon
|
108
|
+
def drop_down_icon(icon: 'menu-hamburger', items: [], menu_right: false, icon_attributes: nil, menu_attributes: nil)
|
109
|
+
_menu_attributes = {
|
110
|
+
class: "dropdown-menu#{menu_right ? ' dropdown-menu-right' : nil}"
|
111
|
+
}
|
112
|
+
if menu_attributes
|
113
|
+
_menu_attributes = _menu_attributes.merge(menu_attributes)
|
114
|
+
end
|
114
115
|
tag(
|
115
|
-
:
|
116
|
+
:div,
|
116
117
|
attributes: {
|
117
|
-
class:
|
118
|
+
class: 'dropdown',
|
118
119
|
},
|
119
|
-
content:
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
},
|
144
|
-
content: icon(
|
145
|
-
icon,
|
146
|
-
style: {
|
147
|
-
font_size: 'smaller',
|
148
|
-
# margin_top: '0.2em',
|
149
|
-
margin_bottom: '0.2em',
|
150
|
-
margin_left: right ? '0.5em' : '0.3em',
|
151
|
-
margin_right: right ? '0.3em' : '0.5em',
|
152
|
-
vertical_align: 'middle',
|
153
|
-
color: 'inherit',
|
154
|
-
background_color: 'inherit',
|
155
|
-
}.merge(
|
156
|
-
style
|
120
|
+
content: [
|
121
|
+
tag(
|
122
|
+
:div,
|
123
|
+
attributes: {
|
124
|
+
class: 'dropdown-toggle',
|
125
|
+
data_toggle: 'dropdown'
|
126
|
+
},
|
127
|
+
content: icon(
|
128
|
+
icon,
|
129
|
+
attributes: icon_attributes
|
130
|
+
)
|
131
|
+
),
|
132
|
+
tag(
|
133
|
+
:ul,
|
134
|
+
attributes: _menu_attributes,
|
135
|
+
content: items.map { |item|
|
136
|
+
content = item[:content]
|
137
|
+
if content == 'divider' || content == 'separator'
|
138
|
+
tag(
|
139
|
+
:li,
|
140
|
+
attributes: {
|
141
|
+
role: 'separator',
|
142
|
+
class: 'divider',
|
143
|
+
}
|
157
144
|
)
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
if content == 'divider' || content == 'separator'
|
169
|
-
tag(
|
170
|
-
:li,
|
171
|
-
attributes: {
|
172
|
-
role: 'separator',
|
173
|
-
class: 'divider',
|
174
|
-
}
|
175
|
-
)
|
176
|
-
else
|
177
|
-
attrs = {}
|
178
|
-
attrs[:href] = item[:href] if item[:href]
|
179
|
-
attrs[:onclick] = item[:callback] if item[:callback]
|
180
|
-
tag(
|
181
|
-
:li,
|
182
|
-
content: tag(
|
183
|
-
:div,
|
184
|
-
content: content,
|
185
|
-
attributes: attrs
|
186
|
-
)
|
145
|
+
else
|
146
|
+
attrs = {}
|
147
|
+
attrs[:href] = item[:href] if item[:href]
|
148
|
+
attrs[:onclick] = item[:callback] if item[:callback]
|
149
|
+
tag(
|
150
|
+
:li,
|
151
|
+
content: tag(
|
152
|
+
:div,
|
153
|
+
content: content,
|
154
|
+
attributes: attrs
|
187
155
|
)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
156
|
+
)
|
157
|
+
end
|
158
|
+
}
|
159
|
+
)
|
160
|
+
]
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
def plus_sign_drop_down(items: [], menu_right: false, icon_attributes: nil, menu_attributes: nil)
|
165
|
+
_icon_attributes = {
|
166
|
+
style: {
|
167
|
+
color: 'lightgreen'
|
168
|
+
}
|
169
|
+
}
|
170
|
+
if icon_attributes
|
171
|
+
# argument attributes take precedence
|
172
|
+
_icon_attributes = _icon_attributes.merge(icon_attributes)
|
173
|
+
end
|
174
|
+
drop_down_icon(icon: 'plus-sign',
|
175
|
+
items: items,
|
176
|
+
menu_right: menu_right,
|
177
|
+
icon_attributes: _icon_attributes,
|
178
|
+
menu_attributes: menu_attributes
|
193
179
|
)
|
194
180
|
end
|
195
181
|
|
@@ -321,11 +307,22 @@ module CSR
|
|
321
307
|
# e.g. { callback: ->{}, href: '#', content: 'list item'}
|
322
308
|
# 3. content: of the div (apart from the icon)
|
323
309
|
# 4. pull: which side of div to pull the icon, 'right' or 'left'
|
324
|
-
def div_with_dropdown_icon(icon: 'menu-hamburger', items: [], content: nil, pull: 'right')
|
310
|
+
def div_with_dropdown_icon(icon: 'menu-hamburger', items: [], attributes: nil, content: nil, pull: 'right', menu_attributes: nil)
|
325
311
|
tag(
|
326
312
|
:div,
|
313
|
+
attributes: attributes,
|
327
314
|
content: arrify(
|
328
|
-
|
315
|
+
tag(
|
316
|
+
:span,
|
317
|
+
attributes: {
|
318
|
+
class: "pull-#{pull}",
|
319
|
+
style: {
|
320
|
+
margin_left: '0.5em',
|
321
|
+
margin_right: '0.5em'
|
322
|
+
}
|
323
|
+
},
|
324
|
+
content: drop_down_icon(icon: icon, items: items, menu_right: pull.to_s == 'right', menu_attributes: menu_attributes)
|
325
|
+
),
|
329
326
|
content
|
330
327
|
)
|
331
328
|
)
|
data/csr/dom/table/base.rb
CHANGED
@@ -133,6 +133,18 @@ module CSR
|
|
133
133
|
@sections ? @sections.detect {|e| e.id == id} : nil
|
134
134
|
end
|
135
135
|
|
136
|
+
def head
|
137
|
+
section(:head)
|
138
|
+
end
|
139
|
+
|
140
|
+
def body
|
141
|
+
section(:body)
|
142
|
+
end
|
143
|
+
|
144
|
+
def foot
|
145
|
+
section(:foot)
|
146
|
+
end
|
147
|
+
|
136
148
|
def visible_columns
|
137
149
|
@visible_columns ||= visible_column_indexes.map {|i| columns[i]}
|
138
150
|
end
|
data/csr/dom/table/column.rb
CHANGED
@@ -11,18 +11,18 @@ module CSR
|
|
11
11
|
# where table is a Table; section is :head, :body or :foot; row is an element in
|
12
12
|
# head_rows, body_rows or foot_rows.
|
13
13
|
|
14
|
-
attr_reader :
|
15
|
-
attr_reader :
|
16
|
-
attr_reader :
|
14
|
+
attr_reader :head # Content or String or nil.
|
15
|
+
attr_reader :body # Content or String or nil.
|
16
|
+
attr_reader :foot # Content or String or nil.
|
17
17
|
|
18
18
|
# OPTIONS:
|
19
|
-
# :id
|
20
|
-
# :sort
|
21
|
-
# :hide
|
22
|
-
# :master
|
23
|
-
# :
|
24
|
-
# :
|
25
|
-
# :
|
19
|
+
# :id # unique in table
|
20
|
+
# :sort # column may be sorted : boolean or nil
|
21
|
+
# :hide # column may be hidden : boolean or nil
|
22
|
+
# :master # column used for grouping in accordion table
|
23
|
+
# :head # Content or String or nil for column head
|
24
|
+
# :body # Content or String or nil for column body
|
25
|
+
# :foot # Content or String or nil for column foot
|
26
26
|
|
27
27
|
# TODO:
|
28
28
|
# width:
|
@@ -32,9 +32,9 @@ module CSR
|
|
32
32
|
@sort_callback = options[:sort]
|
33
33
|
@hide = !!options[:hide]
|
34
34
|
@master = !!options[:master]
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
35
|
+
@head = options[:head]
|
36
|
+
@body = options[:body]
|
37
|
+
@foot = options[:foot]
|
38
38
|
end
|
39
39
|
|
40
40
|
def hash
|
@@ -67,7 +67,7 @@ module CSR
|
|
67
67
|
|
68
68
|
# section is :head, :body or :foot
|
69
69
|
def section_content(section)
|
70
|
-
send(
|
70
|
+
send(section.to_sym)
|
71
71
|
end
|
72
72
|
|
73
73
|
# Returns a (probably) unique column id.
|
data/csr/dom/table/row.rb
CHANGED
@@ -65,8 +65,10 @@ module CSR
|
|
65
65
|
# Returns array of cell elements in table's visible column order
|
66
66
|
def cells
|
67
67
|
unless @cells
|
68
|
+
column_index = -1
|
68
69
|
@cells = @table.visible_columns.map do |column|
|
69
|
-
|
70
|
+
column_index += 1
|
71
|
+
cell(column, column_index)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
@cells
|
@@ -80,8 +82,8 @@ module CSR
|
|
80
82
|
@section.row_source(@index)
|
81
83
|
end
|
82
84
|
|
83
|
-
def cell(column)
|
84
|
-
attributes, content =
|
85
|
+
def cell(column, column_index)
|
86
|
+
attributes, content = cell_attributes_and_content(column, column_index)
|
85
87
|
tag(
|
86
88
|
head? ? :th : :td,
|
87
89
|
attributes: attributes,
|
@@ -89,7 +91,7 @@ module CSR
|
|
89
91
|
)
|
90
92
|
end
|
91
93
|
|
92
|
-
def
|
94
|
+
def cell_attributes_and_content(column, column_index)
|
93
95
|
content = column.section_content(@section.id)
|
94
96
|
attributes = nil
|
95
97
|
debug 1, ->{[ __FILE__, __LINE__, __method__, "section.id=#{@section.id} row_index=#{@index} column.id=#{column.id} content=#{content}" ]}
|
data/csr/dom/table/section.rb
CHANGED
@@ -74,13 +74,11 @@ module CSR
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def root
|
77
|
-
debug 1, ->{[ __FILE__, __LINE__, __method__, "@id=#{@id}" ]}
|
78
77
|
@root ||= tag(
|
79
78
|
"t#{@id}",
|
80
79
|
attributes: attributes,
|
81
80
|
content: content
|
82
81
|
)
|
83
|
-
debug 1, ->{[ __FILE__, __LINE__, __method__, "@id=#{@id} @root=#{@root}" ]}
|
84
82
|
@root
|
85
83
|
end
|
86
84
|
|
data/lib/dom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dom-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Gunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal-browser
|