weaver 0.2.2 → 0.3.0

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: ae6c5d9dc5321714d7473018da8bc8738d62bee1
4
- data.tar.gz: 1e4402daa077db93b77cf933a8b3e482f3041d89
3
+ metadata.gz: d1935b42581f7e4c6448b307ce17a4f6bbd6f168
4
+ data.tar.gz: 534788172b09e63d3b41efb2af77de2490be72b7
5
5
  SHA512:
6
- metadata.gz: 4d2fc0027cba08b8400979f2cee102de30f23635bab9a1776163bbcb45c80d71b0f80cf602b87c7fed9232d1ba36a254fad179043107620ad21bf9bb265070c2
7
- data.tar.gz: bd9eaf24fe0e0ef30c3ffb3ee416704cbd1a0e248f3204792e4ef9085918f952961ce5084f1fc37d9162a2e02c4c3903a2f37af3ef3135192818803261971764
6
+ metadata.gz: c32e2b77f1c2a77d0a1455b205ad560f6dc705eccdf94c6960bb35b4eddc108426aa9ba80298f45debe3f285685ac320d85e49420f72ed33432233645a8d7bd4
7
+ data.tar.gz: e556fa59bd695bbf37099ae444d6913817182f16a21af7f1ad840cb0a5cfb17bbd9dd94338cb66b055836985d4168636acb453efdeb0bd7eefb5368ad3602545
data/exe/weaver CHANGED
@@ -43,6 +43,15 @@ class Website < Sinatra::Base
43
43
  return send_file(params[:splat].first, :disposition => 'inline')
44
44
  end
45
45
 
46
+ if params[:splat].first.start_with? "js/"
47
+ return send_file(params[:splat].first, :disposition => 'inline')
48
+ end
49
+
50
+ if params[:splat].first.start_with? "css/"
51
+ return send_file(params[:splat].first, :disposition => 'inline')
52
+ end
53
+
54
+
46
55
  viewname = params[:splat].first
47
56
  result = getWeavefile viewname
48
57
  viewFile = result[:viewFile]
@@ -93,6 +102,16 @@ where [options] are:
93
102
  if Dir.exist? "images"
94
103
  FileUtils.cp_r("images", buildDir)
95
104
  end
105
+ if Dir.exist? "js"
106
+ Dir["js/*.*"].each do |x|
107
+ FileUtils.cp_r(x, File.join("js", buildDir))
108
+ end
109
+ end
110
+ if Dir.exist? "css"
111
+ Dir["css/*.*"].each do |x|
112
+ FileUtils.cp_r(x, File.join("css", buildDir))
113
+ end
114
+ end
96
115
 
97
116
  files = Dir["source/**/*.weave"]
98
117
  files.each do |file|
@@ -153,8 +172,12 @@ end
153
172
 
154
173
  to_create = "#{args[0]}"
155
174
  FileUtils::mkdir_p "#{to_create}"
175
+ FileUtils::mkdir_p "#{to_create}/cache"
176
+ File.write("#{to_create}/cache/this_directory_is_used_by_weaver_as_a_cache","")
156
177
  FileUtils::mkdir_p "#{to_create}/source"
157
178
  FileUtils::mkdir_p "#{to_create}/images"
179
+ FileUtils::mkdir_p "#{to_create}/js"
180
+ FileUtils::mkdir_p "#{to_create}/css"
158
181
  File.write "#{to_create}/Gemfile", gemfile
159
182
  File.write "#{to_create}/source/index.weave", source
160
183
  end
@@ -1,3 +1,3 @@
1
1
  module Weaver
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/weaver.rb CHANGED
@@ -3,6 +3,7 @@ require "weaver/version"
3
3
  require 'fileutils'
4
4
  require 'sinatra'
5
5
  require 'json'
6
+ require 'active_support/core_ext/object/to_query'
6
7
 
7
8
  module Weaver
8
9
 
@@ -44,13 +45,47 @@ module Weaver
44
45
  tag
45
46
  end
46
47
 
48
+ def root
49
+ @page.root
50
+ end
51
+
52
+ def request_js(path)
53
+ @page.request_js(script_file)
54
+ end
55
+
56
+ def request_css(path)
57
+ @page.request_css(path)
58
+ end
59
+
60
+ def on_page_load(script)
61
+ @page.on_page_load(script)
62
+ end
63
+
64
+ def write_script_once(script)
65
+ @page.write_script_once(script)
66
+ end
67
+
68
+ def background(&block)
69
+ @page.background(block)
70
+ end
71
+
72
+ def on_page_load(script)
73
+ @page.on_page_load(script)
74
+ end
75
+
47
76
  def icon(type)
48
77
  iconname = type.to_s.gsub(/_/, "-")
49
- i class: "fa fa-#{iconname}" do
78
+ if type.is_a? Symbol
79
+ i class: "fa fa-#{iconname}" do
80
+ end
81
+ else
82
+ i class: "fa" do
83
+ text type
84
+ end
50
85
  end
51
86
  end
52
87
 
53
- def form(options={}, &block)
88
+ def wform(options={}, &block)
54
89
  theform = Form.new(@page, @anchors, options)
55
90
  theform.instance_eval(&block)
56
91
  @inner_content << theform.generate
@@ -90,17 +125,24 @@ module Weaver
90
125
 
91
126
  def image(name, options={})
92
127
 
93
- style = ""
128
+ style = "#{options[:style]}"
94
129
  if options[:rounded_corners] == true
95
130
  style += " border-radius: 8px"
96
131
  elsif options[:rounded_corners] == :top
97
132
  style += " border-radius: 8px 8px 0px 0px"
98
133
  else
99
- style += " border-radius: #{options[:rounded_corners]}px"
134
+ style += " border-radius: #{options[:rounded_corners]}px" if options[:rounded_corners]
100
135
 
101
136
  end
102
137
 
103
- img class: "img-responsive #{options[:class]}", src: "#{@page.root}images/#{name}", style: style
138
+ img_options = {
139
+ class: "img-responsive #{options[:class]}",
140
+ src: "#{@page.root}images/#{name}",
141
+ style: style
142
+ }
143
+ img_options[:id] = options[:id] if options[:id]
144
+
145
+ img img_options
104
146
  end
105
147
 
106
148
  def crossfade_image(image_normal, image_hover)
@@ -112,6 +154,35 @@ module Weaver
112
154
  @page.request_css "css/crossfade_style.css"
113
155
  end
114
156
 
157
+ def gallery(images, thumbnails=images, options={}, &block)
158
+
159
+ @page.request_css "css/plugins/blueimp/css/blueimp-gallery.min.css"
160
+
161
+ div class:"lightBoxGallery" do
162
+ (0...images.length).to_a.each do |index|
163
+
164
+ title = options[:titles][index] if options[:titles]
165
+
166
+ a href:"#{images[index]}", title: "#{title}", :"data-gallery"=> "" do
167
+ img src:"#{thumbnails[index]}", style: "margin: 5px;"
168
+ end
169
+ end
170
+
171
+ div id:"blueimp-gallery", class:"blueimp-gallery" do
172
+ div class:"slides" do end
173
+ h3 class:"title" do end
174
+ a class:"prev" do end
175
+ a class:"next" do end
176
+ a class:"close" do end
177
+ a class:"play-pause" do end
178
+ ol class:"indicator" do end
179
+ end
180
+ end
181
+
182
+ @page.request_js "js/plugins/blueimp/jquery.blueimp-gallery.min.js"
183
+
184
+ end
185
+
115
186
  def breadcrumb(patharray)
116
187
  ol class: "breadcrumb" do
117
188
  patharray.each do |path|
@@ -234,6 +305,11 @@ ENDROW
234
305
  div :class => "jumbotron", style: additional_style, &block
235
306
  end
236
307
 
308
+ def modal(id=nil, &block)
309
+ mm = ModalDialog.new(@page, @anchors, id, &block)
310
+ @inner_content << mm.generate
311
+ end
312
+
237
313
  def _button(options={}, &block)
238
314
 
239
315
  anIcon = options[:icon]
@@ -255,14 +331,19 @@ ENDROW
255
331
  dim = "btn-circle" if options[:circle]
256
332
 
257
333
  buttonOptions = {
258
- :type => "button",
259
- :class => "btn btn-#{style} #{size} #{blockstyle} #{outline} #{dim}"
334
+ :type => options[:type] || "button",
335
+ :class => "btn btn-#{style} #{size} #{blockstyle} #{outline} #{dim}",
336
+ :id => options[:id]
260
337
  }
261
338
 
262
339
  if block
340
+ closer = ""
341
+
342
+ closer = "; return false;" if options[:nosubmit]
343
+
263
344
  action = Action.new(@page, @anchors, &block)
264
345
  buttonOptions[:onclick] = "#{action.name}(this)"
265
- buttonOptions[:onclick] = "#{action.name}(this, #{options[:data]})" if options[:data]
346
+ buttonOptions[:onclick] = "#{action.name}(this, #{options[:data]})#{closer}" if options[:data]
266
347
  @page.scripts << action.generate
267
348
  end
268
349
 
@@ -272,6 +353,7 @@ ENDROW
272
353
  type = :a if options[:toggle]
273
354
 
274
355
 
356
+
275
357
  method_missing type, buttonOptions do
276
358
  if title.is_a? Symbol
277
359
  icon title
@@ -283,7 +365,7 @@ ENDROW
283
365
  end
284
366
  end
285
367
 
286
- def button(anIcon, title={}, options={}, &block)
368
+ def normal_button(anIcon, title={}, options={}, &block)
287
369
  options[:icon] = anIcon
288
370
  options[:title] = title
289
371
  _button(options, &block)
@@ -444,6 +526,68 @@ ENDROW
444
526
  end
445
527
  end
446
528
 
529
+ class ModalDialog
530
+
531
+ def initialize(page, anchors, id, &block)
532
+ @page = page
533
+ @anchors = anchors
534
+ @id = id || @page.create_anchor("modal")
535
+
536
+ @header_content = Elements.new(@page, @anchors)
537
+ @body_content = Elements.new(@page, @anchors)
538
+ @footer_content = Elements.new(@page, @anchors)
539
+
540
+ instance_eval(&block) if block
541
+ end
542
+
543
+ def id
544
+ @id
545
+ end
546
+
547
+ def header(&block)
548
+ @header_content.instance_eval(&block)
549
+ end
550
+
551
+ def body(&block)
552
+ @body_content.instance_eval(&block)
553
+ end
554
+
555
+ def footer(&block)
556
+ @footer_content.instance_eval(&block)
557
+ end
558
+
559
+ def generate
560
+ elem = Elements.new(@page, @anchors)
561
+
562
+ id = @id
563
+ header_content = @header_content
564
+ body_content = @body_content
565
+ footer_content = @footer_content
566
+
567
+ elem.instance_eval do
568
+ div class: "modal fade", id: id, tabindex: -1, role: "dialog" do
569
+ div class: "modal-dialog", role: "document" do
570
+ div class: "modal-content" do
571
+ div class: "modal-header" do
572
+ button "&times;", type: "button", class: "close", :"data-dismiss" => "modal", :"aria-label" => "Close"
573
+ text header_content.generate
574
+ end
575
+ div class: "modal-body" do
576
+ text body_content.generate
577
+ end
578
+ div class: "modal-footer" do
579
+ text footer_content.generate
580
+ end
581
+ end
582
+ end
583
+ end
584
+ end
585
+
586
+ elem.generate
587
+
588
+ end
589
+ end
590
+
447
591
  class DynamicTableCell < Elements
448
592
 
449
593
  def data_button(anIcon, title={}, options={}, &block)
@@ -454,6 +598,39 @@ ENDROW
454
598
  end
455
599
  end
456
600
 
601
+ class JavaScriptObject
602
+ def initialize(&block)
603
+ @object = {}
604
+ instance_eval(&block) if block
605
+ end
606
+
607
+ def string(name, string)
608
+ @object[name] = {type: :string, value: string}
609
+ end
610
+
611
+ def variable(name, var_name)
612
+ @object[name] = {type: :var, value: var_name}
613
+ end
614
+
615
+ def generate
616
+ result = @object.map {
617
+ |key,value|
618
+
619
+ value_expression = value[:value]
620
+
621
+ if value[:type] == :string
622
+ value_expression = "\"#{value[:value]}\""
623
+ end
624
+
625
+ "#{key}: #{value_expression}"
626
+
627
+ }.join ","
628
+
629
+ "{#{result}}"
630
+ end
631
+
632
+ end
633
+
457
634
  class DynamicTable
458
635
 
459
636
  def initialize(page, anchors, url, options={}, &block)
@@ -462,6 +639,7 @@ ENDROW
462
639
  @url = url
463
640
  @options = options
464
641
  @columns = nil
642
+ @query_object = nil
465
643
 
466
644
  self.instance_eval(&block) if block
467
645
 
@@ -531,15 +709,39 @@ ENDROW
531
709
  elem.generate
532
710
  end
533
711
 
712
+ def query(&block)
713
+ @query_object = JavaScriptObject.new(&block)
714
+ end
715
+
534
716
  def generate_script
535
717
 
718
+ query_object_declaration = ''
719
+ query_string = ""
720
+
721
+ if @query_object
722
+ query_object_declaration = @query_object.generate
723
+ query_string = "+ \"?\" + $.param(query_object)"
724
+ end
725
+
536
726
  <<-DATATABLE_SCRIPT
537
727
 
538
728
  function refresh_table_#{@table_name}()
539
729
  {
540
- $.get( "#{@url}", function( data )
730
+ var query_object = #{query_object_declaration};
731
+
732
+ $.get( "#{@url}" #{query_string}, function( data )
541
733
  {
542
- var data_object = JSON.parse(data);
734
+
735
+ var data_object = {};
736
+ if (data !== null && typeof data === 'object')
737
+ {
738
+ data_object = data;
739
+ }
740
+ else
741
+ {
742
+ data_object = JSON.parse(data);
743
+ }
744
+
543
745
  var head = $("##{@head_name}")
544
746
  var body = $("##{@body_name}")
545
747
 
@@ -656,7 +858,7 @@ ENDROW
656
858
  end
657
859
 
658
860
  def generate
659
- puts @code
861
+ #puts @code
660
862
  <<-FUNCTION
661
863
  function #{@actionName}(caller, data) {
662
864
  #{@code}
@@ -761,15 +963,26 @@ function #{@actionName}(caller, data) {
761
963
  @options = options
762
964
  @scripts = []
763
965
 
764
- @formName = @page.create_anchor "form"
966
+ @formName = options[:id] || @page.create_anchor("form")
765
967
  end
766
968
 
767
- def passwordfield(name, textfield_label, options={})
969
+ def passwordfield(name, textfield_label=nil, options={})
970
+
971
+ if textfield_label.is_a? Hash
972
+ options = textfield_label
973
+ textfield_label = nil
974
+ end
975
+
768
976
  options[:type] = "password"
769
977
  textfield(name, textfield_label, options)
770
978
  end
771
979
 
772
- def textfield(name, textfield_label, options={})
980
+ def textfield(name, textfield_label=nil, options={})
981
+
982
+ if textfield_label.is_a? Hash
983
+ options = textfield_label
984
+ textfield_label = nil
985
+ end
773
986
 
774
987
  textfield_name = @page.create_anchor "textfield"
775
988
  options[:type] ||= "text"
@@ -781,19 +994,28 @@ function #{@actionName}(caller, data) {
781
994
  input_options[:placeholder] = options[:placeholder]
782
995
  input_options[:id] = textfield_name
783
996
  input_options[:name] = options[:name]
997
+ input_options[:rows] = options[:rows]
784
998
  input_options[:class] = "form-control"
785
999
 
1000
+ input_options[:autocomplete] = options[:autocomplete] || "on"
1001
+ input_options[:autocorrect] = options[:autocorrect] || "on"
1002
+ input_options[:autocapitalize] = options[:autocapitalize] || "off"
1003
+
786
1004
  if options[:mask]
787
1005
  @page.request_css "css/plugins/jasny/jasny-bootstrap.min.css"
788
1006
  @page.request_js "js/plugins/jasny/jasny-bootstrap.min.js"
789
1007
 
790
1008
  input_options[:"data-mask"] = options[:mask]
791
-
792
1009
  end
793
1010
 
794
1011
  div :class => "form-group" do
795
- label textfield_label
796
- input input_options
1012
+ label textfield_label if textfield_label
1013
+ if input_options[:rows] and input_options[:rows] > 1
1014
+ textarea input_options do
1015
+ end
1016
+ else
1017
+ input input_options
1018
+ end
797
1019
  end
798
1020
 
799
1021
  @scripts << <<-SCRIPT
@@ -943,7 +1165,9 @@ function #{@actionName}(caller, data) {
943
1165
  def submit(anIcon, title={}, options={}, &block)
944
1166
  options[:icon] = anIcon
945
1167
  options[:title] = title
1168
+ options[:type] = "submit"
946
1169
  options[:data] = "get_#{@formName}_object()"
1170
+ options[:nosubmit] = true if block
947
1171
  _button(options, &block)
948
1172
  end
949
1173
 
@@ -989,10 +1213,20 @@ $(document).ready(function () {
989
1213
  def generate
990
1214
  inner = super
991
1215
  formName = @formName
1216
+ options = @options
992
1217
 
993
1218
  elem = Elements.new(@page, @anchors)
994
1219
  elem.instance_eval do
995
- method_missing :form, id: formName, role: "form" do
1220
+
1221
+ form_opts = {
1222
+ id: formName,
1223
+ role: "form"
1224
+ }
1225
+
1226
+ form_opts[:action] = options[:action] if options[:action]
1227
+ form_opts[:class] = options[:class] if options[:class]
1228
+
1229
+ method_missing :form, form_opts do
996
1230
  text inner
997
1231
  end
998
1232
  end
@@ -1315,21 +1549,27 @@ $(document).ready(function () {
1315
1549
 
1316
1550
  class Page
1317
1551
 
1318
- attr_accessor :scripts
1552
+ attr_accessor :scripts, :onload_scripts
1319
1553
 
1320
- def initialize(title, options)
1554
+ def initialize(title, global_settings, options, &block)
1321
1555
  @title = title
1322
1556
  @content = ""
1323
1557
  @body_class = nil
1324
1558
  @anchors = {}
1559
+ @global_settings = global_settings
1325
1560
  @options = options
1326
1561
  @scripts = []
1327
1562
  @top_content = ""
1328
1563
 
1329
1564
  @scripts_once = {}
1565
+ @onload_scripts = []
1330
1566
 
1331
1567
  @requested_scripts = {}
1332
1568
  @requested_css = {}
1569
+
1570
+ @background = Elements.new(self, @anchors)
1571
+
1572
+ @block = Proc.new &block
1333
1573
  end
1334
1574
 
1335
1575
  def create_anchor(name)
@@ -1347,7 +1587,7 @@ $(document).ready(function () {
1347
1587
  end
1348
1588
 
1349
1589
  def root
1350
- return @options[:root]
1590
+ return @global_settings[:root]
1351
1591
  end
1352
1592
 
1353
1593
  def request_js(path)
@@ -1358,10 +1598,18 @@ $(document).ready(function () {
1358
1598
  @requested_css[path] = true
1359
1599
  end
1360
1600
 
1601
+ def on_page_load(script)
1602
+ @onload_scripts << script
1603
+ end
1604
+
1361
1605
  def write_script_once(script)
1362
1606
  @scripts_once[script] = true
1363
1607
  end
1364
1608
 
1609
+ def background(&block)
1610
+ @background.instance_eval(&block)
1611
+ end
1612
+
1365
1613
  def top(&block)
1366
1614
  elem = Elements.new(@page, @anchors)
1367
1615
  elem.instance_eval(&block)
@@ -1371,6 +1619,21 @@ $(document).ready(function () {
1371
1619
 
1372
1620
  def generate(back_folders, options={})
1373
1621
 
1622
+ if @options[:cache_file]
1623
+ expired = @options[:cache_expired]
1624
+ cache_exist = File.exist?("cache/cachedpage#{@options[:cache_file]}")
1625
+
1626
+ if cache_exist and !expired
1627
+ puts "Weaver Hit cache for file: #{@options[:cache_file]}"
1628
+ puts "- expired: #{expired}"
1629
+ puts "- cache_exist: #{cache_exist}"
1630
+ return File.read("cache/cachedpage#{@options[:cache_file]}");
1631
+ end
1632
+ puts "Weaver Miss cache for file: #{@options[:cache_file]}"
1633
+ puts "- expired: #{expired}"
1634
+ puts "- cache_exist: #{cache_exist}"
1635
+ end
1636
+
1374
1637
  scripts = @scripts.join("\n")
1375
1638
 
1376
1639
  mod = "../" * back_folders
@@ -1405,7 +1668,12 @@ $(document).ready(function () {
1405
1668
  SCRIPT_DECL
1406
1669
  }.join "\n"
1407
1670
 
1408
- <<-SKELETON
1671
+ onload_scripts = @onload_scripts.map {|value| <<-SCRIPT_DECL
1672
+ #{value}
1673
+ SCRIPT_DECL
1674
+ }.join "\n"
1675
+
1676
+ result =<<-SKELETON
1409
1677
  <!DOCTYPE html>
1410
1678
  <html>
1411
1679
  <!-- Generated using weaver: https://github.com/davidsiaw/weaver -->
@@ -1419,7 +1687,6 @@ $(document).ready(function () {
1419
1687
  <link href="#{mod}css/bootstrap.min.css" rel="stylesheet">
1420
1688
  <link href="#{mod}font-awesome/css/font-awesome.css" rel="stylesheet">
1421
1689
  <link href="#{mod}css/plugins/iCheck/custom.css" rel="stylesheet">
1422
- <link href="#{mod}css/plugins/blueimp/css/blueimp-gallery.min.css" rel="stylesheet">
1423
1690
 
1424
1691
  #{extra_css}
1425
1692
 
@@ -1429,8 +1696,15 @@ $(document).ready(function () {
1429
1696
  </head>
1430
1697
 
1431
1698
  #{body_tag}
1699
+
1700
+ <div id="background" style="z-index: -999; position:absolute; left:0px; right:0px; width:100%; height:100%">
1701
+ #{@background.generate}
1702
+ </div>
1703
+
1704
+ <div id="content" style="z-index: 0">
1432
1705
  #{@top_content}
1433
1706
  #{@content}
1707
+ </div>
1434
1708
 
1435
1709
  <!-- Mainly scripts -->
1436
1710
  <script src="#{mod}js/jquery-2.1.1.js"></script>
@@ -1441,21 +1715,6 @@ $(document).ready(function () {
1441
1715
 
1442
1716
  #{extra_scripts}
1443
1717
 
1444
- <!-- blueimp gallery -->
1445
- <script src="#{mod}js/plugins/blueimp/jquery.blueimp-gallery.min.js"></script>
1446
-
1447
- <style>
1448
- /* Local style for demo purpose */
1449
-
1450
- .lightBoxGallery {
1451
- text-align: center;
1452
- }
1453
-
1454
- .lightBoxGallery img {
1455
- margin: 5px;
1456
- }
1457
-
1458
- </style>
1459
1718
 
1460
1719
 
1461
1720
  <!-- Custom and plugin javascript -->
@@ -1465,17 +1724,14 @@ $(document).ready(function () {
1465
1724
  <script>
1466
1725
  #{scripts}
1467
1726
  #{extra_one_time_scripts}
1727
+
1728
+ $( document ).ready(function() {
1729
+
1730
+ #{onload_scripts}
1731
+
1732
+ });
1468
1733
  </script>
1469
1734
 
1470
- <div id="blueimp-gallery" class="blueimp-gallery">
1471
- <div class="slides"></div>
1472
- <h3 class="title"></h3>
1473
- <a class="prev">‹</a>
1474
- <a class="next">›</a>
1475
- <a class="close">×</a>
1476
- <a class="play-pause"></a>
1477
- <ol class="indicator"></ol>
1478
- </div>
1479
1735
 
1480
1736
 
1481
1737
  </body>
@@ -1483,16 +1739,25 @@ $(document).ready(function () {
1483
1739
  </html>
1484
1740
 
1485
1741
  SKELETON
1742
+
1743
+ if @options[:cache_file]
1744
+ FileUtils.mkdir_p "cache"
1745
+ File.write("cache/cachedpage#{@options[:cache_file]}", result);
1746
+ end
1747
+
1748
+ return result
1749
+
1486
1750
  end
1487
1751
  end
1488
1752
 
1489
1753
  class Row
1490
- attr_accessor :extra_classes
1754
+ attr_accessor :extra_classes, :style
1491
1755
 
1492
1756
  def initialize(page, anchors, options)
1493
1757
  @columns = []
1494
1758
  @free = 12
1495
1759
  @extra_classes = options[:class] || ""
1760
+ @style = options[:style]
1496
1761
  @anchors = anchors
1497
1762
  @page = page
1498
1763
  end
@@ -1559,8 +1824,20 @@ $(document).ready(function () {
1559
1824
  md = col[:options][:md] || col[:occupy]
1560
1825
  lg = col[:options][:lg] || col[:occupy]
1561
1826
 
1827
+ hidden = ""
1828
+
1829
+ xs_style = "col-xs-#{xs}" unless col[:options][:xs] == 0
1830
+ sm_style = "col-sm-#{sm}" unless col[:options][:sm] == 0
1831
+ md_style = "col-md-#{md}" unless col[:options][:md] == 0
1832
+ lg_style = "col-lg-#{lg}" unless col[:options][:lg] == 0
1833
+
1834
+ hidden += "hidden-xs " if col[:options][:xs] == 0
1835
+ hidden += "hidden-sm " if col[:options][:sm] == 0
1836
+ hidden += "hidden-md " if col[:options][:md] == 0
1837
+ hidden += "hidden-lg " if col[:options][:lg] == 0
1838
+
1562
1839
  <<-ENDCOLUMN
1563
- <div class="col-xs-#{xs} col-sm-#{sm} col-md-#{md} col-lg-#{lg}">
1840
+ <div class="#{xs_style} #{sm_style} #{md_style} #{lg_style} #{hidden}">
1564
1841
  #{col[:elem].generate}
1565
1842
  </div>
1566
1843
  ENDCOLUMN
@@ -1574,23 +1851,22 @@ $(document).ready(function () {
1574
1851
  @items = []
1575
1852
  end
1576
1853
 
1577
- def nav(name, icon=:question, url=nil, &block)
1578
- if url
1579
- @items << { name: name, link: url, icon: icon }
1580
- else
1581
- @items << { name: name, link: "#", icon: icon }
1582
- end
1583
- if block
1854
+ def nav(name, icon=:question, url=nil, options={}, &block)
1855
+ if url and !block
1856
+ @items << { name: name, link: url, icon: icon, options: options }
1857
+ elsif block
1584
1858
  menu = Menu.new
1585
1859
  menu.instance_eval(&block)
1586
- @items << { name: name, menu: menu, icon: icon }
1860
+ @items << { name: name, menu: menu, icon: icon, options: options }
1861
+ else
1862
+ @items << { name: name, link: "#", icon: icon, options: options }
1587
1863
  end
1588
1864
  end
1589
1865
  end
1590
1866
 
1591
1867
  class StructuredPage < Page
1592
1868
 
1593
- def initialize(title, options)
1869
+ def initialize(title, global_settings, options, &block)
1594
1870
  @rows = []
1595
1871
  super
1596
1872
  end
@@ -1608,7 +1884,7 @@ $(document).ready(function () {
1608
1884
  end
1609
1885
 
1610
1886
  class NavPage < StructuredPage
1611
- def initialize(title, options)
1887
+ def initialize(title, global_settings, options, &block)
1612
1888
  super
1613
1889
  @menu = Menu.new
1614
1890
  end
@@ -1625,14 +1901,15 @@ $(document).ready(function () {
1625
1901
  end
1626
1902
 
1627
1903
  class SideNavPage < NavPage
1628
- def initialize(title, options)
1904
+ def initialize(title, global_settings, options, &block)
1629
1905
  super
1630
1906
  end
1631
1907
 
1632
1908
  def generate(level)
1909
+ instance_eval &@block
1633
1910
  rows = @rows.map { |row|
1634
1911
  <<-ENDROW
1635
- <div class="row #{row.extra_classes}">
1912
+ <div class="row #{row.extra_classes}" style="#{row.style}">
1636
1913
  #{row.generate}
1637
1914
  </div>
1638
1915
  ENDROW
@@ -1644,11 +1921,10 @@ $(document).ready(function () {
1644
1921
  navigation.instance_eval do
1645
1922
 
1646
1923
  menu.items.each do |item|
1647
- li do
1924
+ li item[:options] do
1648
1925
  if item.has_key? :menu
1649
1926
 
1650
-
1651
- a href:"#" do
1927
+ a href:"#{item[:link]}" do
1652
1928
  icon item[:icon]
1653
1929
  span :class => "nav-label" do
1654
1930
  text item[:name]
@@ -1660,17 +1936,23 @@ $(document).ready(function () {
1660
1936
 
1661
1937
  ul :class => "nav nav-second-level" do
1662
1938
  item[:menu].items.each do |inneritem|
1663
- li do
1939
+ li inneritem[:options] do
1664
1940
  if inneritem.has_key?(:menu)
1665
1941
  raise "Second level menu not supported"
1666
1942
  else
1667
- link inneritem[:name], href:inneritem[:link]
1943
+ a href:"#{inneritem[:link]}" do
1944
+ icon inneritem[:icon]
1945
+ span :class => "nav-label" do
1946
+ text inneritem[:name]
1947
+ end
1948
+ end
1668
1949
  end
1669
1950
  end
1670
1951
  end
1671
1952
  end
1672
1953
  elsif
1673
- a href: "#" do
1954
+ a href: "#{item[:link]}" do
1955
+ icon item[:icon]
1674
1956
  span :class => "nav-label" do
1675
1957
  text item[:name]
1676
1958
  end
@@ -1687,7 +1969,7 @@ $(document).ready(function () {
1687
1969
  brand_content = <<-BRAND_CONTENT
1688
1970
 
1689
1971
  <li>
1690
- <a href="#"><i class="fa fa-home"></i> <span class="nav-label">X</span> <span class="label label-primary pull-right"></span></a>
1972
+ <a href="#{root}"><i class="fa fa-home"></i> <span class="nav-label">#{@brand}</span> <span class="label label-primary pull-right"></span></a>
1691
1973
  </li>
1692
1974
  BRAND_CONTENT
1693
1975
  end
@@ -1728,14 +2010,15 @@ $(document).ready(function () {
1728
2010
  end
1729
2011
 
1730
2012
  class TopNavPage < NavPage
1731
- def initialize(title, options)
2013
+ def initialize(title, global_settings, options, &block)
1732
2014
  super
1733
2015
  end
1734
2016
 
1735
2017
  def generate(level)
2018
+ instance_eval &@block
1736
2019
  rows = @rows.map { |row|
1737
2020
  <<-ENDROW
1738
- <div class="row #{row.extra_classes}">
2021
+ <div class="row #{row.extra_classes}" style="#{row.style}">
1739
2022
  #{row.generate}
1740
2023
  </div>
1741
2024
  ENDROW
@@ -1750,7 +2033,7 @@ $(document).ready(function () {
1750
2033
  navigation.instance_eval do
1751
2034
 
1752
2035
  menu.items.each do |item|
1753
- li do
2036
+ li item[:options] do
1754
2037
  if item.has_key? :menu
1755
2038
 
1756
2039
  li :class => "dropdown" do
@@ -1769,7 +2052,7 @@ $(document).ready(function () {
1769
2052
  end
1770
2053
  ul role: "menu", :class => "dropdown-menu" do
1771
2054
  item[:menu].items.each do |inneritem|
1772
- li do
2055
+ li inneritem[:options] do
1773
2056
  if inneritem.has_key?(:menu)
1774
2057
  raise "Second level menu not supported"
1775
2058
  else
@@ -1799,7 +2082,7 @@ $(document).ready(function () {
1799
2082
 
1800
2083
  <div class="navbar-header">
1801
2084
 
1802
- <a href="#" class="navbar-brand">X</a>
2085
+ <a href="#{root}" class="navbar-brand">#{@brand}</a>
1803
2086
  </div>
1804
2087
  BRAND_CONTENT
1805
2088
  end
@@ -1846,11 +2129,12 @@ $(document).ready(function () {
1846
2129
  end
1847
2130
 
1848
2131
  class NonNavPage < StructuredPage
1849
- def initialize(title, options)
2132
+ def initialize(title, global_settings, options, &block)
1850
2133
  super
1851
2134
  end
1852
2135
 
1853
2136
  def generate(level)
2137
+ instance_eval &@block
1854
2138
  rows = @rows.map { |row|
1855
2139
  <<-ENDROW
1856
2140
  <div class="row #{row.extra_classes}">
@@ -1875,39 +2159,34 @@ $(document).ready(function () {
1875
2159
  end
1876
2160
 
1877
2161
  class RawPage < Page
1878
- def initialize(title, options)
1879
- @element = Elements.new(self, {})
2162
+ def initialize(title, global_settings, options, &block)
1880
2163
  super
1881
2164
  end
1882
2165
 
1883
- def element=(value)
1884
- @element = value
1885
- end
2166
+ def generate(back_folders, options={})
1886
2167
 
2168
+ elem = Elements.new(self, {})
2169
+ elem.instance_eval(&@block)
1887
2170
 
1888
- def generate(back_folders, options={})
1889
- @element.generate
2171
+ elem.generate
1890
2172
  end
1891
2173
 
1892
2174
  end
1893
2175
 
1894
2176
  class EmptyPage < Page
1895
- def initialize(title, options)
1896
- @element = Elements.new(self, {})
2177
+ def initialize(title, global_settings, options, &block)
1897
2178
  super
1898
2179
  end
1899
2180
 
1900
- def element=(value)
1901
- @element = value
1902
- end
1903
-
1904
2181
  def generate(level)
2182
+ elem = Elements.new(self, {})
2183
+ elem.instance_eval(&@block)
1905
2184
  @body_class = "gray-bg"
1906
2185
  @content = <<-CONTENT
1907
2186
  <div id="wrapper">
1908
2187
  <div class="wrapper-content">
1909
2188
  <div class="container">
1910
- #{@element.generate}
2189
+ #{elem.generate}
1911
2190
  </div>
1912
2191
  </div>
1913
2192
  </div>
@@ -1918,21 +2197,20 @@ $(document).ready(function () {
1918
2197
 
1919
2198
 
1920
2199
  class CenterPage < Page
1921
- def initialize(title, options)
1922
- @element = Elements.new(self, {})
2200
+ def initialize(title, global_settings, options, &block)
1923
2201
  super
1924
2202
  end
1925
2203
 
1926
- def element=(value)
1927
- @element = value
1928
- end
1929
-
1930
2204
  def generate(level)
2205
+
2206
+ elem = Elements.new(self, {})
2207
+ elem.instance_eval(&@block)
2208
+
1931
2209
  @body_class = "gray-bg"
1932
2210
  @content = <<-CONTENT
1933
2211
  <div class="middle-box text-center animated fadeInDown">
1934
2212
  <div>
1935
- #{@element.generate}
2213
+ #{elem.generate}
1936
2214
  </div>
1937
2215
  </div>
1938
2216
  CONTENT
@@ -1945,95 +2223,74 @@ $(document).ready(function () {
1945
2223
  def initialize(file, options={})
1946
2224
  @pages = {}
1947
2225
  @file = file
1948
- @options = options
2226
+ @global_settings = options
1949
2227
 
1950
- @options[:root] = @options[:root] || "/"
1951
- @options[:root] = "#{@options[:root]}/" unless @options[:root].end_with? "/"
2228
+ @global_settings[:root] = @global_settings[:root] || "/"
2229
+ @global_settings[:root] = "#{@global_settings[:root]}/" unless @global_settings[:root].end_with? "/"
1952
2230
  instance_eval(File.read(file), file)
1953
2231
  end
1954
2232
 
1955
- def center_page(path, title=nil, &block)
2233
+ def center_page(path, title=nil, options={}, &block)
1956
2234
 
1957
2235
  if title == nil
1958
2236
  title = path
1959
2237
  path = ""
1960
2238
  end
1961
2239
 
1962
- p = CenterPage.new(title, @options)
1963
-
1964
- elem = Elements.new(p, {})
1965
- elem.instance_eval(&block) if block
1966
-
1967
- p.element=elem
1968
-
2240
+ p = CenterPage.new(title, @global_settings, options, &block)
1969
2241
  @pages[path] = p
1970
2242
  end
1971
2243
 
1972
- def sidenav_page(path, title=nil, &block)
2244
+ def sidenav_page(path, title=nil, options={}, &block)
1973
2245
 
1974
2246
  if title == nil
1975
2247
  title = path
1976
2248
  path = ""
1977
2249
  end
1978
2250
 
1979
- p = SideNavPage.new(title, @options)
1980
- p.instance_eval(&block) if block
2251
+ p = SideNavPage.new(title, @global_settings, options, &block)
1981
2252
  @pages[path] = p
1982
2253
  end
1983
2254
 
1984
- def topnav_page(path, title=nil, &block)
2255
+ def topnav_page(path, title=nil, options={}, &block)
1985
2256
 
1986
2257
  if title == nil
1987
2258
  title = path
1988
2259
  path = ""
1989
2260
  end
1990
2261
 
1991
- p = TopNavPage.new(title, @options)
1992
- p.instance_eval(&block) if block
2262
+ p = TopNavPage.new(title, @global_settings, options, &block)
1993
2263
  @pages[path] = p
1994
2264
  end
1995
2265
 
1996
- def nonnav_page(path, title=nil, &block)
2266
+ def nonnav_page(path, title=nil, options={}, &block)
1997
2267
 
1998
2268
  if title == nil
1999
2269
  title = path
2000
2270
  path = ""
2001
2271
  end
2002
2272
 
2003
- p = NonNavPage.new(title, @options)
2004
- p.instance_eval(&block) if block
2273
+ p = NonNavPage.new(title, @global_settings, options, &block)
2005
2274
  @pages[path] = p
2006
2275
  end
2007
2276
 
2008
2277
 
2009
- def empty_page(path, title=nil, &block)
2278
+ def empty_page(path, title=nil, options={}, &block)
2010
2279
 
2011
2280
  if title == nil
2012
2281
  title = path
2013
2282
  path = ""
2014
2283
  end
2015
2284
 
2016
- p = EmptyPage.new(title, @options)
2017
-
2018
- elem = Elements.new(p, {})
2019
- elem.instance_eval(&block) if block
2020
-
2021
- p.element=elem
2022
-
2285
+ p = EmptyPage.new(title, @global_settings, options, &block)
2023
2286
  @pages[path] = p
2024
2287
  end
2025
2288
 
2026
- def raw_page(path="", &block)
2289
+ def raw_page(path="", options={}, &block)
2027
2290
 
2028
2291
  # raw pages dont even have a title
2029
2292
 
2030
- p = RawPage.new("", @options)
2031
-
2032
- elem = Elements.new(p, {})
2033
- elem.instance_eval(&block) if block
2034
-
2035
- p.element=elem
2036
-
2293
+ p = RawPage.new("", @global_settings, options, &block)
2037
2294
  @pages[path] = p
2038
2295
  end
2039
2296
 
data/weaver.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = "Website generator"
13
13
  spec.description = "Site generator with a simple DSL"
14
- spec.homepage = "https://github.com/davidsiaw/weaver"
14
+ spec.homepage = "https://davidsiaw.github.io/weaver-docs/"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency "activesupport"
30
31
  spec.add_dependency "sinatra"
31
32
  spec.add_dependency "trollop"
32
33
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
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-03-01 00:00:00.000000000 Z
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: sinatra
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -685,7 +699,7 @@ files:
685
699
  - lib/weaver.rb
686
700
  - lib/weaver/version.rb
687
701
  - weaver.gemspec
688
- homepage: https://github.com/davidsiaw/weaver
702
+ homepage: https://davidsiaw.github.io/weaver-docs/
689
703
  licenses:
690
704
  - MIT
691
705
  metadata: