weaver 0.3.4 → 0.3.5

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: c353ccbc567eb541727a44254ba814ac5e8eafd3
4
- data.tar.gz: 86828051371239af0b3a663580a31113599f8cb1
3
+ metadata.gz: 0bbee7c107a2c4938c07cfcf0e0f8a7357589667
4
+ data.tar.gz: e574b0658c639c772fb42a3c48a16d8f85c46e53
5
5
  SHA512:
6
- metadata.gz: ea92131d491f3e80a35529f4f4be0dfb0e16a2d59c39198fa14781c6bdebdbd5b108f30028a942069ed019cd0a64b6210f5e02ca66b1ceaa9f0231d2dafa6b29
7
- data.tar.gz: 1aeebe6c64304feb61ce8c8c0ca8a91fa922c8ff1f28c5a462743f428bb71cfd3ef2ac4cd79288f60506d6a342181096ad292bbd8954f2828656ca05538ecd32
6
+ metadata.gz: 3d941ce753c4d92d3ebda8a3536f56b83e238fb55e64a810ad1f998d80e823de0c6b35cb5806ac56ec2ecec8dffdcc9df97a5147b7e2effcbe8cb9611c1ed480
7
+ data.tar.gz: eeb5d8d0182dffadd3eac2ba86951c439a753e0563a94337874f025a459d303bdee243698e87157eebefb706d28ad873d6fb14c196a144ebd3caf902be3ef270
@@ -2337,7 +2337,9 @@ label.error {
2337
2337
  margin-left: 5px;
2338
2338
  }
2339
2339
  .form-control.error {
2340
- border: 1px dotted #cc5965;
2340
+ background: rgb(251, 227, 228);
2341
+ border: 1px solid #fbc2c4;
2342
+ color: #8a1f11;
2341
2343
  }
2342
2344
  /* ngGrid */
2343
2345
  .gridStyle {
data/exe/weaver CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'weaver'
4
4
  require 'trollop'
5
+ require 'sinatra/base'
5
6
 
6
7
  class Website < Sinatra::Base
7
8
 
@@ -95,7 +96,7 @@ where [options] are:
95
96
  end
96
97
 
97
98
  puts "Building site..."
98
-
99
+
99
100
  buildDir = "#{Dir.pwd}/build"
100
101
  FileUtils::rm_rf buildDir
101
102
  FileUtils.cp_r(Gem.datadir("weaver"), buildDir)
@@ -1,3 +1,3 @@
1
1
  module Weaver
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
data/lib/weaver.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require "weaver/version"
2
2
 
3
3
  require 'fileutils'
4
- require 'sinatra'
5
4
  require 'json'
6
5
  require 'active_support/core_ext/object/to_query'
7
6
 
@@ -353,7 +352,6 @@ ENDROW
353
352
  type = :a if options[:toggle]
354
353
 
355
354
 
356
-
357
355
  method_missing type, buttonOptions do
358
356
  if title.is_a? Symbol
359
357
  icon title
@@ -590,12 +588,19 @@ ENDROW
590
588
 
591
589
  class DynamicTableCell < Elements
592
590
 
591
+ attr_accessor :transform_script
592
+
593
593
  def data_button(anIcon, title={}, options={}, &block)
594
594
  options[:icon] = anIcon
595
595
  options[:title] = title
596
596
  options[:data] = "$(this).closest('td').data('object')"
597
597
  _button(options, &block)
598
598
  end
599
+
600
+ def transform(script)
601
+ @transform_script = script
602
+ end
603
+
599
604
  end
600
605
 
601
606
  class JavaScriptObject
@@ -658,6 +663,7 @@ ENDROW
658
663
 
659
664
  title = options[:title] || name
660
665
  format = nil
666
+ transform = nil
661
667
 
662
668
  if options[:icon]
663
669
  elem = Elements.new(@page, @anchors)
@@ -672,9 +678,20 @@ ENDROW
672
678
  elem = DynamicTableCell.new(@page, @anchors)
673
679
  elem.instance_eval(&block)
674
680
  format = elem.generate
681
+ if elem.transform_script
682
+ func_name = @page.create_anchor "transform"
683
+ @page.write_script_once <<-SCRIPT
684
+ document.transform_#{func_name} = function (input)
685
+ {
686
+ #{elem.transform_script}
687
+ }
688
+ SCRIPT
689
+
690
+ transform = func_name
691
+ end
675
692
  end
676
693
 
677
- @columns << {name: name, title: title, format: format}
694
+ @columns << {name: name, title: title, format: format, transform: transform}
678
695
 
679
696
  end
680
697
 
@@ -723,15 +740,20 @@ ENDROW
723
740
  query_string = "+ \"?\" + $.param(query_object)"
724
741
  end
725
742
 
743
+ member_expr = ""
744
+ if @options[:member]
745
+ member_expr = ".#{@options[:member]}"
746
+ end
747
+
726
748
  <<-DATATABLE_SCRIPT
727
749
 
728
750
  function refresh_table_#{@table_name}()
729
751
  {
730
752
  var query_object = #{query_object_declaration};
731
753
 
732
- $.get( "#{@url}" #{query_string}, function( data )
754
+ $.get( "#{@url}" #{query_string}, function( returned_data )
733
755
  {
734
-
756
+ var data = returned_data#{member_expr};
735
757
  var data_object = {};
736
758
  if (data !== null && typeof data === 'object')
737
759
  {
@@ -800,6 +822,7 @@ ENDROW
800
822
  var row = $('<tr>');
801
823
  for (var columnIndex = 0; columnIndex < Object.keys(columns).length; columnIndex++) {
802
824
  var cell_data = data_object[index][ Object.keys(columns)[columnIndex] ];
825
+
803
826
  if (columnData && columnData[columnIndex]["format"])
804
827
  {
805
828
  var format = columnData[columnIndex]["format"];
@@ -812,10 +835,18 @@ ENDROW
812
835
  result = result.replaceAll(matches[matchIndex], data_object[index][member_name]);
813
836
  }
814
837
 
838
+ if (columnData && columnData[columnIndex]["transform"])
839
+ {
840
+ result = document["transform_" + columnData[columnIndex]["transform"]](result);
841
+ }
815
842
  row.append($('<td>').html( result ).data("object", data_object[index]) );
816
843
  }
817
844
  else
818
845
  {
846
+ if (columnData && columnData[columnIndex]["transform"])
847
+ {
848
+ cell_data = document["transform_" + columnData[columnIndex]["transform"]](cell_data);
849
+ }
819
850
  row.append($('<td>').text( cell_data ).data("object", data_object[index]) );
820
851
  }
821
852
  }
@@ -957,6 +988,58 @@ function #{@actionName}(caller, data) {
957
988
  end
958
989
  end
959
990
 
991
+ class TextfieldJavascript
992
+
993
+ def initialize(id)
994
+ @id = id
995
+ end
996
+
997
+ def onchange(script)
998
+ @change_script = script
999
+ end
1000
+
1001
+ def validate(script)
1002
+ @validate_script = script
1003
+ end
1004
+
1005
+ def generate(&block)
1006
+ if block
1007
+ instance_eval(&block)
1008
+ <<-SCRIPT
1009
+ $("##{@id}").keyup(function()
1010
+ {
1011
+ function validate()
1012
+ {
1013
+ #{@validate_script};
1014
+ return true;
1015
+ }
1016
+
1017
+ var object = $("##{@id}");
1018
+ #{@change_script};
1019
+
1020
+ if (validate())
1021
+ {
1022
+ object.removeClass("required");
1023
+ object.removeClass("error");
1024
+ object.removeAttr("aria-invalid");
1025
+ }
1026
+ else
1027
+ {
1028
+ object.addClass("required");
1029
+ object.addClass("error");
1030
+ object.attr("aria-required", "true");
1031
+ object.attr("aria-invalid", "true");
1032
+ }
1033
+ })
1034
+
1035
+
1036
+ SCRIPT
1037
+ end
1038
+
1039
+ end
1040
+
1041
+ end
1042
+
960
1043
  class Form < Elements
961
1044
  def initialize(page, anchors, options)
962
1045
  super(page, anchors)
@@ -966,7 +1049,7 @@ function #{@actionName}(caller, data) {
966
1049
  @formName = options[:id] || @page.create_anchor("form")
967
1050
  end
968
1051
 
969
- def passwordfield(name, textfield_label=nil, options={})
1052
+ def passwordfield(name, textfield_label=nil, options={}, &block)
970
1053
 
971
1054
  if textfield_label.is_a? Hash
972
1055
  options = textfield_label
@@ -974,17 +1057,17 @@ function #{@actionName}(caller, data) {
974
1057
  end
975
1058
 
976
1059
  options[:type] = "password"
977
- textfield(name, textfield_label, options)
1060
+ textfield(name, textfield_label, options, &block)
978
1061
  end
979
1062
 
980
- def textfield(name, textfield_label=nil, options={})
1063
+ def textfield(name, textfield_label=nil, options={}, &block)
981
1064
 
982
1065
  if textfield_label.is_a? Hash
983
1066
  options = textfield_label
984
1067
  textfield_label = nil
985
1068
  end
986
1069
 
987
- textfield_name = @page.create_anchor "textfield"
1070
+ textfield_name = options[:id] || @page.create_anchor("textfield")
988
1071
  options[:type] ||= "text"
989
1072
  options[:placeholder] ||= ""
990
1073
  options[:name] = name
@@ -996,6 +1079,7 @@ function #{@actionName}(caller, data) {
996
1079
  input_options[:name] = options[:name]
997
1080
  input_options[:rows] = options[:rows]
998
1081
  input_options[:class] = "form-control"
1082
+ input_options[:value] = options[:value]
999
1083
 
1000
1084
  input_options[:autocomplete] = options[:autocomplete] || "on"
1001
1085
  input_options[:autocorrect] = options[:autocorrect] || "on"
@@ -1008,7 +1092,7 @@ function #{@actionName}(caller, data) {
1008
1092
  input_options[:"data-mask"] = options[:mask]
1009
1093
  end
1010
1094
 
1011
- div :class => "form-group" do
1095
+ div :class => "form-group #{options[:extra_class]}", id: "#{input_options[:id]}-group" do
1012
1096
  label textfield_label if textfield_label
1013
1097
  if input_options[:rows] and input_options[:rows] > 1
1014
1098
  textarea input_options do
@@ -1018,11 +1102,31 @@ function #{@actionName}(caller, data) {
1018
1102
  end
1019
1103
  end
1020
1104
 
1105
+ textjs = TextfieldJavascript.new(input_options[:id])
1106
+
1107
+ @page.on_page_load textjs.generate(&block) if block
1108
+
1021
1109
  @scripts << <<-SCRIPT
1022
1110
  object["#{name}"] = $('##{textfield_name}').val();
1023
1111
  SCRIPT
1024
1112
  end
1025
1113
 
1114
+ def hiddenfield(name, value, options={})
1115
+ hiddenfield_name = options[:id] || @page.create_anchor("hiddenfield")
1116
+
1117
+ input_options = {}
1118
+ input_options[:type] = "hidden"
1119
+ input_options[:value] = value
1120
+ input_options[:id] = hiddenfield_name
1121
+ input_options[:name] = name
1122
+
1123
+ input input_options
1124
+
1125
+ @scripts << <<-SCRIPT
1126
+ object["#{name}"] = $('##{hiddenfield_name}').val();
1127
+ SCRIPT
1128
+
1129
+ end
1026
1130
 
1027
1131
  def dropdown(name, dropdown_label, choice_array, options={})
1028
1132
  select_name = @page.create_anchor "select"
@@ -1124,26 +1228,36 @@ function #{@actionName}(caller, data) {
1124
1228
 
1125
1229
  radio_name = @page.create_anchor "radio"
1126
1230
 
1127
- first = true
1128
- choice_array.each do |choice|
1129
-
1130
- value = choice
1131
- label = choice
1231
+ choice_array = choice_array.map do |choice|
1132
1232
  if choice.is_a? Hash
1133
- value = choice[:value]
1134
- label = choice[:label]
1233
+ {value: choice[:value], label: choice[:label]}
1234
+ else
1235
+ {value: choice, label: choice}
1135
1236
  end
1237
+ end
1238
+
1239
+ active = choice_array[0][:value]
1240
+ if options[:value] and choice_array.index { |x| x[:value] == options[:value] } != nil
1241
+ active = options[:value]
1242
+ end
1243
+
1244
+ choice_array.each do |choice|
1245
+
1246
+ value = choice[:value]
1247
+ label = choice[:label]
1136
1248
 
1137
1249
  the_options = Hash.new(options)
1138
- if first
1250
+
1251
+ if active == value
1139
1252
  the_options[:checked] = ""
1140
- first = false
1141
1253
  end
1142
1254
  the_options[:type] = "radio"
1143
1255
  the_options[:value] = value
1144
1256
  the_options[:name] = name
1145
1257
  text boolean_element(label, the_options)
1146
1258
  end
1259
+
1260
+
1147
1261
  @scripts << <<-SCRIPT
1148
1262
  object["#{name}"] = $('input[name=#{name}]:checked', '##{@formName}').val()
1149
1263
  SCRIPT
@@ -1224,6 +1338,7 @@ $(document).ready(function () {
1224
1338
  }
1225
1339
 
1226
1340
  form_opts[:action] = options[:action] if options[:action]
1341
+ form_opts[:method] = options[:method] if options[:method]
1227
1342
  form_opts[:class] = options[:class] if options[:class]
1228
1343
 
1229
1344
  method_missing :form, form_opts do
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.3.4
4
+ version: 0.3.5
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-04-21 00:00:00.000000000 Z
11
+ date: 2016-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -720,7 +720,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
720
720
  version: '0'
721
721
  requirements: []
722
722
  rubyforge_project:
723
- rubygems_version: 2.4.6
723
+ rubygems_version: 2.2.2
724
724
  signing_key:
725
725
  specification_version: 4
726
726
  summary: Website generator