jsmenubuilder 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9015a21d6ec16f6a1f06b647bb7adb407699be900123a977b754997805f039a5
4
- data.tar.gz: 4c6aa4d82b0ce977127ef82dbcc5c26408b32542f534db27f953e345bcc1054b
3
+ metadata.gz: 2b20f477b9bc4e3a1ec3a489988cb01c2dec96a3487e4e38dcbae5ce73aeedc8
4
+ data.tar.gz: 187797640e08f8ce47488a67b16310406886e3fc863d6a7a9da786bf71b45e23
5
5
  SHA512:
6
- metadata.gz: e8af2787182d64270676455f8b7aeae116f75d38a24392a9e2018bb0b609be30b37e2e13fe488528f7729a1944914d1e50ed10f3ed02f732916880b39e539a96
7
- data.tar.gz: 4b52b61bbe422c8f533801db7f635ac71d92740f71becf0d890e09344859c80b20d8b5309aa433c53f871940ba0848db1f3c42fc690fd9968848b1d03e9fed85
6
+ metadata.gz: 0ab2f13ac9f5d3126517bfe48d624910442ee0e578cbb3fbae93fa91ddb6d9ec3abea6382419d19c419615e92364080df45107345e4ffdd50db407aedab9cc4f
7
+ data.tar.gz: 5474a14409548fb0b9cd77eb4804547db0576f4358f0c36c689fe1ad60a9c5b7bcc9be6b039639881125e506aa7dd89425191b1e1d5ce06350ab90430e2d4577
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/jsmenubuilder.rb CHANGED
@@ -113,6 +113,45 @@ button.active {
113
113
 
114
114
  EOF
115
115
 
116
+ ACCORDION_CSS = %q(
117
+ .accordion {
118
+ background-color: #eee;
119
+ color: #444;
120
+ cursor: pointer;
121
+ padding: 18px;
122
+ width: 100%;
123
+ border: none;
124
+ text-align: left;
125
+ outline: none;
126
+ font-size: 15px;
127
+ transition: 0.4s;
128
+ }
129
+
130
+ .active, .accordion:hover {
131
+ background-color: #ccc;
132
+ }
133
+
134
+ .accordion:after {
135
+ content: '\002B';
136
+ color: #777;
137
+ font-weight: bold;
138
+ float: right;
139
+ margin-left: 5px;
140
+ }
141
+
142
+ .active:after {
143
+ content: "\2212";
144
+ }
145
+
146
+ .panel {
147
+ padding: 0 18px;
148
+ background-color: white;
149
+ max-height: 0;
150
+ overflow: hidden;
151
+ transition: max-height 0.2s ease-out;
152
+ }
153
+ )
154
+
116
155
  FULL_PAGE_TABS_JS =<<EOF
117
156
  function openPage(pageName,elmnt) {
118
157
  var i, tabcontent;
@@ -136,6 +175,23 @@ function openPage(pageName,elmnt) {
136
175
  document.getElementById("defaultOpen").click();
137
176
  EOF
138
177
 
178
+ ACCORDION_JS =<<EOF
179
+ var acc = document.getElementsByClassName("accordion");
180
+ var i;
181
+
182
+ for (i = 0; i < acc.length; i++) {
183
+ acc[i].addEventListener("click", function() {
184
+ this.classList.toggle("active");
185
+ var panel = this.nextElementSibling;
186
+ if (panel.style.maxHeight){
187
+ panel.style.maxHeight = null;
188
+ } else {
189
+ panel.style.maxHeight = panel.scrollHeight + "px";
190
+ }
191
+ });
192
+ }
193
+
194
+ EOF
139
195
 
140
196
 
141
197
  attr_reader :html, :css, :js
@@ -150,7 +206,7 @@ EOF
150
206
 
151
207
  @debug = options[:debug]
152
208
 
153
- @types = %i(tabs full_page_tabs)
209
+ @types = %i(tabs full_page_tabs accordion)
154
210
 
155
211
  build(type, options) if type
156
212
 
@@ -243,6 +299,7 @@ EOF
243
299
  return unless @types.include? type.to_sym
244
300
 
245
301
  doc = method(type.to_sym).call(options)
302
+ puts 'doc: ' + doc.inspect if @debug
246
303
 
247
304
  @html = doc.xml(pretty: true, declaration: false)\
248
305
  .gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
@@ -258,19 +315,26 @@ EOF
258
315
  def build_xml(type, opt={})
259
316
 
260
317
  puts 'inside build_xml'.info if @debug
318
+ puts 'type: ' + type.inspect if @debug
261
319
 
262
- options = {active: '1'}.merge(opt)
320
+ options = if type.to_s =~ /tabs\b/ then
321
+ {active: '1'}.merge(opt)
322
+ else
323
+ opt
324
+ end
263
325
 
264
- tabs = if options[:headings] then
326
+ entries = if options[:headings] then
265
327
  headings = options[:headings]
266
328
  headings.zip(headings.map {|heading| ['h3', {}, heading]}).to_h
267
329
  else
268
- options[:tabs]
330
+ options[type.to_sym]
269
331
  end
332
+
333
+ puts 'entries: ' + entries.inspect if @debug
270
334
 
271
335
  a = RexleBuilder.build do |xml|
272
336
  xml.tags({mode: type}) do
273
- tabs.each do |heading, content|
337
+ entries.each do |heading, content|
274
338
  xml.tag({title: heading}, content )
275
339
  end
276
340
  end
@@ -278,8 +342,10 @@ EOF
278
342
 
279
343
  doc = Rexle.new(a)
280
344
 
281
- e = doc.root.element("tag[#{options[:active]}]")
282
- e.attributes[:mode] = 'active' if e
345
+ if options[:active] then
346
+ e = doc.root.element("tag[#{options[:active]}]")
347
+ e.attributes[:mode] = 'active' if e
348
+ end
283
349
 
284
350
  return doc.xml(pretty: true)
285
351
 
@@ -361,5 +427,25 @@ EOF
361
427
 
362
428
  end
363
429
 
430
+ def accordion(opt={})
431
+
432
+ panels = opt[:accordion]
433
+
434
+
435
+ a = RexleBuilder.build do |xml|
436
+ xml.html do
437
+
438
+ panels.each do |heading, inner_html|
439
+ xml.button({class:'accordion'}, heading.to_s)
440
+ xml.div({class:'panel'}, inner_html)
441
+ end
442
+
443
+ end
444
+ end
445
+
446
+ return Rexle.new(a)
447
+
448
+ end
449
+
364
450
 
365
451
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsmenubuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  haYJPATx3zs+9jtQoiFg+keM0CPYk/5LgCv9jxxzQcSS20C8O9MWRVvYfIr47ak7
36
36
  yXrDPmRvbJLTNjDv6Tkg3vU6
37
37
  -----END CERTIFICATE-----
38
- date: 2019-07-19 00:00:00.000000000 Z
38
+ date: 2019-09-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.0.1
86
+ rubygems_version: 3.0.3
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: Generates HTML based tabs using HTML, CSS, and JavaScript.
metadata.gz.sig CHANGED
Binary file