weaver 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/weaver.rb +327 -29
  3. data/lib/weaver/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86e4cc69b1948c31ab3a1009dc8e50f070046798
4
- data.tar.gz: abea801b287d059e8691a5d31ae81ae50ee8ddaa
3
+ metadata.gz: 658551b5f5c8d27c88a383e9b8c56d8e5a9a3dd6
4
+ data.tar.gz: 1da3a9c03c4e424f621b79499c822b0d5742c266
5
5
  SHA512:
6
- metadata.gz: fd21bda7490fad1acdf8e4ba0647c5d46e11e514649a412ab8c8637a7cdae78e9509cd8cba10829c35b30ff380f0d3f28eff53181aed3064d2445d56ce11aeac
7
- data.tar.gz: 55a8a8493579a1a81730fdc806214e7ff642cbd3208c648a6aabd7bbecd2d6ba181fa033da37b9bcb709aafffe8a5caa972be1ea3d2c0d3bc8c4d3aeea53364e
6
+ metadata.gz: a96b06fc728b9de80d0d84aa5b743d496709e2355ffbece6bd57db26f478be4eb0520232c339cf910b33bde36b9a7c70de95a239e622ae3aedc7f90c5cda2406
7
+ data.tar.gz: ab41c813e37b25dd416ff085a0fb50b0a84297b45cec00fa2c1da50cb88e6693d6ccabbbbdba5752e250bfa643669170615e2822e2b530a80eb09b230037d8c1
@@ -50,6 +50,13 @@ module Weaver
50
50
  end
51
51
  end
52
52
 
53
+ def form(options={}, &block)
54
+ theform = Form.new(@page, @anchors, options)
55
+ theform.instance_eval(&block)
56
+ @inner_content << theform.generate
57
+ @page.scripts << theform.generate_script
58
+ end
59
+
53
60
  def ibox(options={}, &block)
54
61
  panel = Panel.new(@page, @anchors, options)
55
62
  panel.instance_eval(&block)
@@ -213,7 +220,7 @@ ENDROW
213
220
  div :class => "jumbotron", style: additional_style, &block
214
221
  end
215
222
 
216
- def _button(options={})
223
+ def _button(options={}, &block)
217
224
 
218
225
  anIcon = options[:icon]
219
226
  title = options[:title]
@@ -222,12 +229,11 @@ ENDROW
222
229
  options.merge! title
223
230
  title = anIcon
224
231
  anIcon = nil
225
-
226
232
  end
227
233
 
228
234
  style = options[:style] || :primary
229
235
  size = "btn-#{options[:size]}" if options[:size]
230
- block = "btn-block" if options[:block]
236
+ blockstyle = "btn-block" if options[:block]
231
237
  outline = "btn-outline" if options[:outline]
232
238
  dim = "dim" if options[:threedee]
233
239
  dim = "dim btn-large-dim" if options[:bigthreedee]
@@ -236,9 +242,16 @@ ENDROW
236
242
 
237
243
  buttonOptions = {
238
244
  :type => "button",
239
- :class => "btn btn-#{style} #{size} #{block} #{outline} #{dim}"
245
+ :class => "btn btn-#{style} #{size} #{blockstyle} #{outline} #{dim}"
240
246
  }
241
247
 
248
+ if block
249
+ action = Action.new(@page, @anchors, &block)
250
+ buttonOptions[:onclick] = "#{action.name}(this)"
251
+ buttonOptions[:onclick] = "#{action.name}(this, #{options[:data]})" if options[:data]
252
+ @page.scripts << action.generate
253
+ end
254
+
242
255
  type = :button
243
256
 
244
257
  buttonOptions[:"data-toggle"] = "button" if options[:toggle]
@@ -256,76 +269,126 @@ ENDROW
256
269
  end
257
270
  end
258
271
 
259
- def button(anIcon, title, options={})
272
+ def button(anIcon, title={}, options={}, &block)
260
273
  options[:icon] = anIcon
261
274
  options[:title] = title
262
- _button(options)
275
+ _button(options, &block)
263
276
  end
264
277
 
265
- def block_button(anIcon, title, options={})
278
+ def block_button(anIcon, title={}, options={}, &block)
266
279
  options[:block] = true
267
280
  options[:icon] = anIcon
268
281
  options[:title] = title
269
- _button(options)
282
+ _button(options, &block)
270
283
  end
271
284
 
272
- def outline_button(anIcon, title, options={})
285
+ def outline_button(anIcon, title={}, options={}, &block)
273
286
  options[:outline] = true
274
287
  options[:icon] = anIcon
275
288
  options[:title] = title
276
- _button(options)
289
+ _button(options, &block)
277
290
  end
278
291
 
279
- def big_button(anIcon, title, options={})
292
+ def big_button(anIcon, title={}, options={}, &block)
280
293
  options[:size] = :lg
281
294
  options[:icon] = anIcon
282
295
  options[:title] = title
283
- _button(options)
296
+ _button(options, &block)
284
297
  end
285
298
 
286
- def small_button(anIcon, title, options={})
299
+ def small_button(anIcon, title={}, options={}, &block)
287
300
  options[:size] = :sm
288
301
  options[:icon] = anIcon
289
302
  options[:title] = title
290
- _button(options)
303
+ _button(options, &block)
291
304
  end
292
305
 
293
- def tiny_button(anIcon, title, options={})
306
+ def tiny_button(anIcon, title={}, options={}, &block)
294
307
  options[:size] = :xs
295
308
  options[:icon] = anIcon
296
309
  options[:title] = title
297
- _button(options)
310
+ _button(options, &block)
298
311
  end
299
312
 
300
- def embossed_button(anIcon, title, options={})
313
+ def embossed_button(anIcon, title={}, options={}, &block)
301
314
  options[:threedee] = true
302
315
  options[:icon] = anIcon
303
316
  options[:title] = title
304
- _button(options)
317
+ _button(options, &block)
305
318
  end
306
319
 
307
- def big_embossed_button(anIcon, title, options={})
320
+ def big_embossed_button(anIcon, title={}, options={}, &block)
308
321
  options[:bigthreedee] = true
309
322
  options[:icon] = anIcon
310
323
  options[:title] = title
311
- _button(options)
324
+ _button(options, &block)
312
325
  end
313
326
 
314
- def rounded_button(anIcon, title, options={})
327
+ def rounded_button(anIcon, title={}, options={}, &block)
315
328
  options[:rounded] = true
316
329
  options[:icon] = anIcon
317
330
  options[:title] = title
318
- _button(options)
331
+ _button(options, &block)
319
332
  end
320
333
 
321
- def circle_button(anIcon, title, options={})
334
+ def circle_button(anIcon, title={}, options={}, &block)
322
335
  options[:circle] = true
323
336
  options[:icon] = anIcon
324
337
  options[:title] = title
325
- _button(options)
338
+ _button(options, &block)
326
339
  end
327
340
 
328
- def table_from_hashes(hashes)
341
+ def table(options={}, &block)
342
+
343
+ if !@anchors["tables"]
344
+ @anchors["tables"] = []
345
+ end
346
+
347
+ tableArray = @anchors["tables"]
348
+
349
+ table_name = "table#{tableArray.length}"
350
+ if options[:id] != nil
351
+ table_name = options[:id]
352
+ end
353
+ tableArray << table_name
354
+
355
+ classname = "table"
356
+
357
+ classname += " table-bordered" if options[:bordered]
358
+ classname += " table-hover" if options[:hover]
359
+ classname += " table-striped" if options[:striped]
360
+
361
+ if options[:system] == :data_table
362
+ @page.request_js "js/plugins/dataTables/jquery.dataTables.js"
363
+ @page.request_js "js/plugins/dataTables/dataTables.bootstrap.js"
364
+ @page.request_js "js/plugins/dataTables/dataTables.responsive.js"
365
+ @page.request_js "js/plugins/dataTables/dataTables.tableTools.min.js"
366
+
367
+ @page.request_css "css/plugins/dataTables/dataTables.bootstrap.css"
368
+ @page.request_css "css/plugins/dataTables/dataTables.responsive.css"
369
+ @page.request_css "css/plugins/dataTables/dataTables.tableTools.min.css"
370
+
371
+ @page.scripts << <<-DATATABLE_SCRIPT
372
+ $('##{table_name}').DataTable();
373
+ DATATABLE_SCRIPT
374
+ end
375
+
376
+ if options[:system] == :foo_table
377
+ classname += " toggle-arrow-tiny"
378
+ @page.request_js "js/plugins/footable/footable.all.min.js"
379
+
380
+ @page.request_css "css/plugins/footable/footable.core.css"
381
+
382
+ @page.scripts << <<-DATATABLE_SCRIPT
383
+ $('##{table_name}').footable();
384
+ DATATABLE_SCRIPT
385
+ end
386
+
387
+
388
+ method_missing(:table, :class => classname, id: table_name, &block)
389
+ end
390
+
391
+ def table_from_hashes(hashes, options={})
329
392
 
330
393
  keys = {}
331
394
  hashes.each do |hash|
@@ -334,7 +397,7 @@ ENDROW
334
397
  end
335
398
  end
336
399
 
337
- table class: "table" do
400
+ table options do
338
401
 
339
402
  thead do
340
403
  keys.each do |key, _|
@@ -346,7 +409,7 @@ ENDROW
346
409
 
347
410
  tr do
348
411
  keys.each do |key, _|
349
- td hash[key] || "&nbsp;"
412
+ td "#{hash[key]}" || "&nbsp;"
350
413
  end
351
414
  end
352
415
  end
@@ -359,6 +422,45 @@ ENDROW
359
422
  end
360
423
  end
361
424
 
425
+ class Action
426
+ def initialize(page, anchors, &block)
427
+ @page = page
428
+ @anchors = anchors
429
+
430
+ actionsArray = @anchors["action"]
431
+
432
+ if !@anchors["action"]
433
+ @anchors["action"] = []
434
+ end
435
+
436
+ actionsArray = @anchors["action"]
437
+
438
+ @actionName = "action#{actionsArray.length}"
439
+ actionsArray << @actionName
440
+
441
+ @code = ""
442
+
443
+ self.instance_eval(&block)
444
+ end
445
+
446
+ def script(code)
447
+ @code = code
448
+ end
449
+
450
+ def generate
451
+ puts @code
452
+ <<-FUNCTION
453
+ function #{@actionName}(caller, data) {
454
+ #{@code}
455
+ }
456
+ FUNCTION
457
+ end
458
+
459
+ def name
460
+ @actionName
461
+ end
462
+ end
463
+
362
464
  class Code
363
465
  def initialize(page, anchors, lang)
364
466
  @page = page
@@ -375,7 +477,7 @@ ENDROW
375
477
  codeArray = @anchors["code"]
376
478
 
377
479
  @codeName = "code#{codeArray.length}"
378
- codeArray << @accordion_name
480
+ codeArray << @codeName
379
481
 
380
482
  @page.request_css "css/plugins/codemirror/codemirror.css"
381
483
  @page.request_js "js/plugins/codemirror/codemirror.js"
@@ -445,6 +547,174 @@ ENDROW
445
547
  end
446
548
  end
447
549
 
550
+ class Form < Elements
551
+ def initialize(page, anchors, options)
552
+ super(page, anchors)
553
+ @options = options
554
+ @scripts = []
555
+
556
+ @formName = @page.create_anchor "form"
557
+ end
558
+
559
+ def passwordfield(name, textfield_label, options={})
560
+ options[:type] = "password"
561
+ textfield(name, textfield_label, options)
562
+ end
563
+
564
+ def textfield(name, textfield_label, options={})
565
+
566
+ textfield_name = @page.create_anchor "textfield"
567
+ options[:type] ||= "text"
568
+ options[:placeholder] ||= ""
569
+ options[:name] = name
570
+
571
+ div :class => "form-group" do
572
+ label textfield_label
573
+ input type: options[:type], placeholder: options[:placeholder], id: textfield_name, name: options[:name], class: "form-control"
574
+ end
575
+
576
+ @scripts << <<-SCRIPT
577
+ object["#{name}"] = $('##{textfield_name}').val();
578
+ SCRIPT
579
+ end
580
+
581
+
582
+ def dropdown(name, dropdown_label, choice_array, options={})
583
+ select_name = @page.create_anchor "select"
584
+
585
+ div :class => "form-group" do
586
+ label dropdown_label, :class => "control-label"
587
+
588
+ options[:class] = "form-control"
589
+ options[:name] = name
590
+ options[:id] = select_name
591
+
592
+ method_missing :select, options do
593
+ choice_array.each do |choice|
594
+ option choice
595
+ end
596
+ end
597
+ end
598
+
599
+ if options[:multiple]
600
+ @scripts << <<-SCRIPT
601
+ var selections = [];
602
+ $("##{select_name} option:selected").each(function(i, selected){
603
+ selections[i] = $(selected).text();
604
+ });
605
+ object["#{name}"] = selections;
606
+ SCRIPT
607
+ else
608
+ @scripts << <<-SCRIPT
609
+ object["#{name}"] = $( "##{select_name} option:selected" ).text();
610
+ SCRIPT
611
+ end
612
+
613
+ end
614
+
615
+ def radio(name, choice_array, options={})
616
+
617
+ radio_name = @page.create_anchor "radio"
618
+
619
+ first = true
620
+ choice_array.each do |choice|
621
+
622
+ value = choice
623
+ label = choice
624
+ if choice.is_a? Hash
625
+ value = choice[:value]
626
+ label = choice[:label]
627
+ end
628
+
629
+ the_options = Hash.new(options)
630
+ if first
631
+ the_options[:checked] = ""
632
+ first = false
633
+ end
634
+ the_options[:type] = "radio"
635
+ the_options[:value] = value
636
+ the_options[:name] = name
637
+ text boolean_element(label, the_options)
638
+ end
639
+ @scripts << <<-SCRIPT
640
+ object["#{name}"] = $('input[name=#{name}]:checked', '##{@formName}').val()
641
+ SCRIPT
642
+
643
+ end
644
+
645
+ def checkbox(name, checkbox_label, options={})
646
+ checkbox_name = @page.create_anchor "checkbox"
647
+ options[:type] = "checkbox"
648
+ options[:name] = name
649
+ options[:id] = checkbox_name
650
+ text boolean_element(checkbox_label, options)
651
+ @scripts << <<-SCRIPT
652
+ object["#{name}"] = $('##{checkbox_name}').is(":checked");
653
+ SCRIPT
654
+ end
655
+
656
+
657
+ def submit(anIcon, title={}, options={}, &block)
658
+ options[:icon] = anIcon
659
+ options[:title] = title
660
+ options[:data] = "get_#{@formName}_object()"
661
+ _button(options, &block)
662
+ end
663
+
664
+ def generate_script
665
+ <<-SCRIPT
666
+ function get_#{@formName}_object()
667
+ {
668
+ var object = {}
669
+ #{@scripts.join "\n"}
670
+ return object;
671
+ }
672
+ SCRIPT
673
+ end
674
+
675
+ def boolean_element(checkbox_label, options={})
676
+
677
+ @page.request_css "css/plugins/iCheck/custom.css"
678
+ @page.request_js "js/plugins/iCheck/icheck.min.js"
679
+
680
+ @page.write_script_once <<-SCRIPT
681
+ $(document).ready(function () {
682
+ $('.i-checks').iCheck({
683
+ checkboxClass: 'icheckbox_square-green',
684
+ radioClass: 'iradio_square-green',
685
+ });
686
+ });
687
+ SCRIPT
688
+
689
+ elem = Elements.new(@page, @anchors)
690
+ elem.instance_eval do
691
+ div class: "i-checks" do
692
+ label do
693
+ input options do
694
+ text " #{checkbox_label}"
695
+ end
696
+ end
697
+ end
698
+ end
699
+
700
+ elem.generate
701
+ end
702
+
703
+ def generate
704
+ inner = super
705
+ formName = @formName
706
+
707
+ elem = Elements.new(@page, @anchors)
708
+ elem.instance_eval do
709
+ method_missing :form, id: formName, role: "form" do
710
+ text inner
711
+ end
712
+ end
713
+
714
+ elem.generate
715
+ end
716
+ end
717
+
448
718
  class Panel < Elements
449
719
  def initialize(page, anchors, options)
450
720
  super(page, anchors)
@@ -770,10 +1040,26 @@ ENDROW
770
1040
  @scripts = []
771
1041
  @top_content = ""
772
1042
 
1043
+ @scripts_once = {}
1044
+
773
1045
  @requested_scripts = {}
774
1046
  @requested_css = {}
775
1047
  end
776
1048
 
1049
+ def create_anchor(name)
1050
+
1051
+ if !@anchors[name]
1052
+ @anchors[name] = []
1053
+ end
1054
+
1055
+ anchor_array = @anchors[name]
1056
+
1057
+ anchor_name = "#{name}#{anchor_array.length}"
1058
+ anchor_array << anchor_name
1059
+
1060
+ anchor_name
1061
+ end
1062
+
777
1063
  def root
778
1064
  return @options[:root]
779
1065
  end
@@ -786,6 +1072,10 @@ ENDROW
786
1072
  @requested_css[path] = true
787
1073
  end
788
1074
 
1075
+ def write_script_once(script)
1076
+ @scripts_once[script] = true
1077
+ end
1078
+
789
1079
  def top(&block)
790
1080
  elem = Elements.new(@page, @anchors)
791
1081
  elem.instance_eval(&block)
@@ -812,7 +1102,7 @@ ENDROW
812
1102
  body_tag = "<body class='#{@body_class}'>" if @body_class
813
1103
 
814
1104
  loading_bar = ""
815
- loading_bar = '<script src="js/plugins/pace/pace.min.js"></script>' if @loading_bar_visible
1105
+ loading_bar = '<script src="#{mod}js/plugins/pace/pace.min.js"></script>' if @loading_bar_visible
816
1106
 
817
1107
  extra_scripts = @requested_scripts.map {|key,value| <<-SCRIPT_DECL
818
1108
  <script src="#{mod}#{key}"></script>
@@ -824,6 +1114,11 @@ ENDROW
824
1114
  STYLESHEET_DECL
825
1115
  }.join "\n"
826
1116
 
1117
+ extra_one_time_scripts = @scripts_once.map {|key,value| <<-SCRIPT_DECL
1118
+ #{key}
1119
+ SCRIPT_DECL
1120
+ }.join "\n"
1121
+
827
1122
  <<-SKELETON
828
1123
  <!DOCTYPE html>
829
1124
  <html>
@@ -883,6 +1178,7 @@ ENDROW
883
1178
 
884
1179
  <script>
885
1180
  #{scripts}
1181
+ #{extra_one_time_scripts}
886
1182
  </script>
887
1183
 
888
1184
  <div id="blueimp-gallery" class="blueimp-gallery">
@@ -995,6 +1291,8 @@ ENDROW
995
1291
  def nav(name, icon=:question, url=nil, &block)
996
1292
  if url
997
1293
  @items << { name: name, link: url, icon: icon }
1294
+ else
1295
+ @items << { name: name, link: "#", icon: icon }
998
1296
  end
999
1297
  if block
1000
1298
  menu = Menu.new
@@ -1,3 +1,3 @@
1
1
  module Weaver
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weaver
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
  - David Siaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-16 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra