jsmenubuilder 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 90c199cc14c95c758c56e60926884e0728750da3dfe2c75ba1a35fd8ac001d64
4
- data.tar.gz: a4f64e2a769dd9a159011394a420404d746897621fd274f69b689fa6ba6f815e
3
+ metadata.gz: 2f303aa79ef11bb30ff2289012d37c775e7ff786331240f2284455166f9aac30
4
+ data.tar.gz: 4160d4d6bfb62fd333e694c03c455f2061dad62aa50f69b8ff6281f31ac4c60d
5
5
  SHA512:
6
- metadata.gz: d2df2af5486c48a9c21df9b3211f0a763bb2f2c893c2ba770c3e296a705e009690e8233852b136ba65903ff8471adcfca4576b22c2fb22680a8cf5d4ccccf9a2
7
- data.tar.gz: 349510de80b99681503a3f476f4a2c45e2fccf706d484771f5cd41cd0eb9877f10069aa2015dd4f9772418f46523050ae3779ed6647fc603a68ca64d6ca13d83
6
+ metadata.gz: ae6a8105f95911bc57cc108494b879314a5af1c310e72201db8b2f351278b7f6e71e4e6a8fc33350876cfa8998358fa0bd2dfb59e7cfe75ba90f69c16e7236c6
7
+ data.tar.gz: 7ce31bcbacefd42b138ec5767fbb63c1cafb628a8ff4ed1153d9d44b8a16e6b37d95f2c659bc17cbb45e4b399c0b33caf32d6bf241db5e7107a0951eb571de03
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/jsmenubuilder.rb CHANGED
@@ -6,6 +6,7 @@ require 'rexle'
6
6
  require 'rexle-builder'
7
7
 
8
8
  class JsMenuBuilder
9
+ using ColouredText
9
10
 
10
11
  TABS_CSS =<<EOF
11
12
  /* Style the tab */
@@ -139,20 +140,47 @@ EOF
139
140
 
140
141
  attr_reader :html, :css, :js
141
142
 
142
- def initialize(type, options={})
143
+ def initialize(unknown=nil, options={})
144
+
145
+ if unknown.is_a? String then
146
+ type = unknown
147
+ else
148
+ options = unknown
149
+ end
150
+
151
+ @debug = options[:debug]
143
152
 
144
- @type = type
145
- types = %i(tabs full_page_tabs)
146
- doc = method(type.to_sym).call(options) if types.include? type
147
- @html = doc.xml(pretty: true, declaration: false)\
148
- .gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
149
- .map {|x| x.sub(/^ /,'') }.join
153
+ @types = %i(tabs full_page_tabs)
150
154
 
151
- @css = Object.const_get 'JsMenuBuilder::' + @type.to_s.upcase + '_CSS'
152
- @js = Object.const_get 'JsMenuBuilder::' + @type.to_s.upcase + '_JS'
155
+ build(type, options) if type
153
156
 
154
157
  end
155
158
 
159
+ def import(xml)
160
+
161
+ puts 'inside import'.info if @debug
162
+ doc = Rexle.new(xml)
163
+ type = doc.root.attributes[:mode]
164
+ type = 'full_page_tabs' if type == 'fullpage'
165
+
166
+ tabs = doc.root.xpath('tab').inject({}) do |r, tab|
167
+ r.merge(tab.attributes[:title] => tab.children.join.strip)
168
+ end
169
+
170
+ e = doc.root.element('tab[@mode="active"]')
171
+
172
+ default_tab = if e then
173
+ title = e.attributes[:title]
174
+ (tabs.keys.index(title) + 1).to_s
175
+ else
176
+ '1'
177
+ end
178
+
179
+ h = { active: default_tab, tabs: tabs}
180
+ build(type, h)
181
+
182
+ end
183
+
156
184
  def to_css()
157
185
  @css
158
186
  end
@@ -193,6 +221,24 @@ EOF
193
221
  end
194
222
 
195
223
  private
224
+
225
+ def build(type, options)
226
+
227
+ puts 'inside build'.info if @debug
228
+ puts "type: %s\noptions: %s".debug % [type, options] if @debug
229
+
230
+ return unless @types.include? type.to_sym
231
+
232
+ doc = method(type.to_sym).call(options)
233
+
234
+ @html = doc.xml(pretty: true, declaration: false)\
235
+ .gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
236
+ .map {|x| x.sub(/^ /,'') }.join
237
+
238
+ @css = Object.const_get 'JsMenuBuilder::' + type.to_s.upcase + '_CSS'
239
+ @js = Object.const_get 'JsMenuBuilder::' + type.to_s.upcase + '_JS'
240
+
241
+ end
196
242
 
197
243
  def tabs(opt={})
198
244
 
@@ -204,9 +250,6 @@ EOF
204
250
  else
205
251
  options[:tabs]
206
252
  end
207
-
208
-
209
- ## build the HTML
210
253
 
211
254
  a = RexleBuilder.build do |xml|
212
255
  xml.html do
@@ -246,10 +289,7 @@ EOF
246
289
  headings.zip(headings.map {|heading| ['h3', {}, heading]}).to_h
247
290
  else
248
291
  options[:tabs]
249
- end
250
-
251
-
252
- ## build the HTML
292
+ end
253
293
 
254
294
  a = RexleBuilder.build do |xml|
255
295
  xml.html do
@@ -276,4 +316,5 @@ EOF
276
316
 
277
317
  end
278
318
 
319
+
279
320
  end
data.tar.gz.sig CHANGED
Binary file
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.0
4
+ version: 0.2.1
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-13 00:00:00.000000000 Z
38
+ date: 2019-07-14 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: '1.5'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.5.1
49
+ version: 1.5.2
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: '1.5'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.5.1
59
+ version: 1.5.2
60
60
  description:
61
61
  email: james@jamesrobertson.eu
62
62
  executables: []
metadata.gz.sig CHANGED
Binary file