dom-rb 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bea94521028abe3b88220fd369b2ed399d49094
4
- data.tar.gz: 2fd651272b2923fb793a1b38d2c46ce814ce6856
3
+ metadata.gz: 4094aecbbafbb4c2a1dd1ef9fdc792654ee33ae6
4
+ data.tar.gz: e559c378becd4619c814853b4450ecbcb79a8d1b
5
5
  SHA512:
6
- metadata.gz: 2c72e3408c30567670e74eecd2461bc22b4d72606b19dcfb282664451c5feba2abbbf34b408633875c5cd0c09ee91dfce4a1779a2754484127ba7e9c6bf948af
7
- data.tar.gz: ee2775001232bf81ea60da2d4b5c0b985b38857384369efeba9eccab04a501fb6d3f1ef6a232a3a9125fe581c73e94ea3171a2218680c637e4ecf98de27538e1
6
+ metadata.gz: cd0d3f612e5d765e75aae4739cfb80a9a95520b58222062f4d498b3a674da96e1ecff2d64afa8eb507f18f17cf1c671226dc53971db6f51e73ccbb1450c913f0
7
+ data.tar.gz: 56c46eff3826114066929e5ffa50e0176c3716735a182d253649c78f85e76866b99970073d547b6cf7067f64fd7c52d94ff0c5073e294ec945310aa8ab47db7a
@@ -25,6 +25,10 @@ end
25
25
  class Browser
26
26
  class DOM
27
27
  class Node
28
+ def as_native
29
+ @native
30
+ end
31
+
28
32
  # requires jquery and bootstrap.js - will fail otherwise
29
33
  def check_jquery
30
34
  %x(
@@ -72,7 +72,7 @@ module CSR
72
72
  end
73
73
 
74
74
  def resolve_value(element, value, bindings, id, attr, tag_name)
75
- # debug 1, ->{[ __FILE__, __LINE__, __method__, "tag=#{tag_name} value=#{value} bindings=#{bindings} id=#{id} attr=#{attr}" ]}
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
- # debug 1, ->{[ __FILE__, __LINE__, __method__, "result=#{result}" ]}
98
+ debug 1, ->{[ __FILE__, __LINE__, __method__, "result=#{result}" ]}
99
99
  result
100
100
  end
101
101
 
@@ -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, css: nil, float: nil, margins: nil, style: nil)
12
- _style = {
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
- if margins
20
- _style =_style.merge(margins)
21
- elsif float
22
- _style = _style.merge(
23
- case float.to_sym
24
- when :left
25
- { margin_right: '0.5em' } # { margin_top: '0.2em', margin_right: '0.5em' }
26
- when :right
27
- { margin_left: '0.5em' } # { margin_top: '0.2em', margin_right: '0.5em' }
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: _class,
40
- style: _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, float: nil, margins: nil, icon_css: nil, anchor_css: nil, icon_style: nil, anchor_style: nil)
51
- _icon = icon(icon_name, css: icon_css, float: float, margins: margins, style: icon_style)
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
- href: href,
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 plus_sign_icon(href = nil)
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
- icon_style: { color: 'lightgreen'}
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. content: of the div (apart from the icon)
109
- # 4. pull: which side of div to pull the span, 'right' or 'left'
110
- # 5. style: any additional styling fro the span/icon
111
- def drop_down_icon(icon: 'menu-hamburger', items: [], pull: 'right', style: {})
112
- pull = pull.to_s
113
- right = pull == 'right'
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
- :span,
116
+ :div,
116
117
  attributes: {
117
- class: "pull-#{pull}"
118
+ class: 'dropdown',
118
119
  },
119
- content: tag(
120
- :div,
121
- attributes: {
122
- class: 'dropdown',
123
- },
124
- content: [
125
- tag(
126
- :div,
127
- attributes: {
128
- class: 'dropdown-toggle',
129
- # type: 'button',
130
- data_toggle: 'dropdown',
131
- style: {
132
- font_size: 'smaller',
133
- # margin_top: '0.2em',
134
- # margin_bottom: '0.1em',
135
- margin_left: right ? '0.5em' : '0.3em',
136
- margin_right: right ? '0.3em' : '0.5em',
137
- vertical_align: 'middle',
138
- color: 'inherit',
139
- background_color: 'inherit',
140
- }.merge(
141
- style
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
- tag(
161
- :ul,
162
- attributes: {
163
- class: "dropdown-menu#{right ? ' dropdown-menu-right' : nil}"
164
- },
165
- content: items.map { |item|
166
- content = item[:content]
167
- `console.log(#{"#{__FILE__}[#{__LINE__}]: adding item #{content} to menu icon #{icon}"})`
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
- end
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
- drop_down_icon(icon: icon, items: items, pull: pull),
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
  )
@@ -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
@@ -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 :head_content # Content or String or nil.
15
- attr_reader :body_content # Content or String or nil.
16
- attr_reader :foot_content # Content or String or nil.
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 # 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 # Content or String or nil for column head
24
- # :body_content # Content or String or nil for column body
25
- # :foot_content # Content or String or nil for column foot
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
- @head_content = options[:head_content]
36
- @body_content = options[:body_content]
37
- @foot_content = options[:foot_content]
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(:"#{section}_content")
70
+ send(section.to_sym)
71
71
  end
72
72
 
73
73
  # Returns a (probably) unique column id.
@@ -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
- cell(column)
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 = cell_attributes_content(column)
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 cell_attributes_content(column)
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}" ]}
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module CSR
2
2
  module DOM
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
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.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-25 00:00:00.000000000 Z
11
+ date: 2016-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal-browser