weaver 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/bin/console +3 -3
- data/exe/weaver +112 -122
- data/lib/weaver.rb +24 -2654
- data/lib/weaver/element_types/accordion.rb +122 -0
- data/lib/weaver/element_types/action.rb +38 -0
- data/lib/weaver/element_types/code.rb +81 -0
- data/lib/weaver/element_types/dynamic_table.rb +324 -0
- data/lib/weaver/element_types/dynamic_table_cell.rb +16 -0
- data/lib/weaver/element_types/form.rb +47 -0
- data/lib/weaver/element_types/form_elements.rb +297 -0
- data/lib/weaver/element_types/javascript_object.rb +28 -0
- data/lib/weaver/element_types/modal_dialog.rb +68 -0
- data/lib/weaver/element_types/panel.rb +124 -0
- data/lib/weaver/element_types/row.rb +117 -0
- data/lib/weaver/element_types/tabs.rb +75 -0
- data/lib/weaver/element_types/textfield_javascript.rb +58 -0
- data/lib/weaver/elements.rb +406 -0
- data/lib/weaver/page_types/center_page.rb +25 -0
- data/lib/weaver/page_types/empty_page.rb +26 -0
- data/lib/weaver/page_types/nav_page.rb +39 -0
- data/lib/weaver/page_types/nonnav_page.rb +35 -0
- data/lib/weaver/page_types/page.rb +234 -0
- data/lib/weaver/page_types/raw_page.rb +17 -0
- data/lib/weaver/page_types/sidenav_page.rb +119 -0
- data/lib/weaver/page_types/structured_page.rb +19 -0
- data/lib/weaver/page_types/topnav_page.rb +167 -0
- data/lib/weaver/version.rb +1 -1
- data/lib/weaver/weave.rb +44 -0
- data/weaver.gemspec +27 -24
- metadata +37 -13
@@ -0,0 +1,16 @@
|
|
1
|
+
module Weaver
|
2
|
+
class DynamicTableCell < Elements
|
3
|
+
attr_accessor :transform_script
|
4
|
+
|
5
|
+
def data_button(anIcon, title = {}, options = {}, &block)
|
6
|
+
options[:icon] = anIcon
|
7
|
+
options[:title] = title
|
8
|
+
options[:data] = "$(this).closest('td').data('object')"
|
9
|
+
_button(options, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def transform(script)
|
13
|
+
@transform_script = script
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'weaver/element_types/form_elements'
|
2
|
+
module Weaver
|
3
|
+
class Form
|
4
|
+
def initialize(page, anchors, options = {}, &block)
|
5
|
+
@formName = options[:id] || page.create_anchor('form')
|
6
|
+
|
7
|
+
@form_element = FormElements.new(page, anchors, @formName, options)
|
8
|
+
|
9
|
+
@form_element.instance_eval(&block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_script
|
13
|
+
<<-SCRIPT
|
14
|
+
function get_#{@formName}_object()
|
15
|
+
{
|
16
|
+
var object = {}
|
17
|
+
#{@form_element.scripts.join "\n"}
|
18
|
+
return object;
|
19
|
+
}
|
20
|
+
SCRIPT
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate
|
24
|
+
inner = @form_element.generate
|
25
|
+
formName = @formName
|
26
|
+
options = @form_element.options
|
27
|
+
|
28
|
+
elem = Elements.new(@page, @anchors)
|
29
|
+
elem.instance_eval do
|
30
|
+
form_opts = {
|
31
|
+
id: formName,
|
32
|
+
role: 'form'
|
33
|
+
}
|
34
|
+
|
35
|
+
form_opts[:action] = options[:action] if options[:action]
|
36
|
+
form_opts[:method] = options[:method] if options[:method]
|
37
|
+
form_opts[:class] = options[:class] if options[:class]
|
38
|
+
|
39
|
+
method_missing :form, form_opts do
|
40
|
+
text inner
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
elem.generate
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,297 @@
|
|
1
|
+
module Weaver
|
2
|
+
class FormElements < Elements
|
3
|
+
attr_accessor :options, :scripts
|
4
|
+
|
5
|
+
def initialize(page, anchors, formName, options = {})
|
6
|
+
super(page, anchors)
|
7
|
+
@formName = formName
|
8
|
+
@options = options
|
9
|
+
@scripts = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def passwordfield(name, textfield_label = nil, options = {}, &block)
|
13
|
+
if textfield_label.is_a? Hash
|
14
|
+
options = textfield_label
|
15
|
+
textfield_label = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
options[:type] = 'password'
|
19
|
+
textfield(name, textfield_label, options, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def textfield(name, textfield_label = nil, options = {}, &block)
|
23
|
+
if textfield_label.is_a? Hash
|
24
|
+
options = textfield_label
|
25
|
+
textfield_label = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
textfield_name = options[:id] || @page.create_anchor('textfield')
|
29
|
+
options[:type] ||= 'text'
|
30
|
+
options[:placeholder] ||= ''
|
31
|
+
options[:name] = name
|
32
|
+
|
33
|
+
input_options = {}
|
34
|
+
input_options[:type] = options[:type]
|
35
|
+
input_options[:placeholder] = options[:placeholder]
|
36
|
+
input_options[:id] = textfield_name
|
37
|
+
input_options[:name] = options[:name]
|
38
|
+
input_options[:rows] = options[:rows]
|
39
|
+
input_options[:class] = 'form-control'
|
40
|
+
input_options[:value] = options[:value]
|
41
|
+
input_options[:style] = options[:style]
|
42
|
+
|
43
|
+
input_options[:autocomplete] = options[:autocomplete] || 'on'
|
44
|
+
input_options[:autocorrect] = options[:autocorrect] || 'on'
|
45
|
+
input_options[:autocapitalize] = options[:autocapitalize] || 'off'
|
46
|
+
|
47
|
+
if options[:mask]
|
48
|
+
@page.request_css 'css/plugins/jasny/jasny-bootstrap.min.css'
|
49
|
+
@page.request_js 'js/plugins/jasny/jasny-bootstrap.min.js'
|
50
|
+
|
51
|
+
input_options[:"data-mask"] = options[:mask]
|
52
|
+
end
|
53
|
+
|
54
|
+
div class: "form-group #{options[:extra_class]}", id: "#{input_options[:id]}-group" do
|
55
|
+
label textfield_label if textfield_label
|
56
|
+
|
57
|
+
div_class = ' '
|
58
|
+
if options[:front_text] || options[:back_text]
|
59
|
+
div_class = 'input-group m-b'
|
60
|
+
end
|
61
|
+
|
62
|
+
div "class": div_class do
|
63
|
+
span (options[:front_text]).to_s, class: 'input-group-addon' if options[:front_text]
|
64
|
+
if input_options[:rows] && (input_options[:rows] > 1)
|
65
|
+
textarea input_options do
|
66
|
+
end
|
67
|
+
else
|
68
|
+
input input_options
|
69
|
+
end
|
70
|
+
span (options[:back_text]).to_s, class: 'input-group-addon' if options[:back_text]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
textjs = TextfieldJavascript.new(input_options[:id])
|
75
|
+
|
76
|
+
@page.on_page_load textjs.generate(&block) if block
|
77
|
+
|
78
|
+
@scripts << <<-SCRIPT
|
79
|
+
object["#{name}"] = $('##{textfield_name}').val();
|
80
|
+
SCRIPT
|
81
|
+
end
|
82
|
+
|
83
|
+
def hiddenfield(name, value, options = {})
|
84
|
+
hiddenfield_name = options[:id] || @page.create_anchor('hiddenfield')
|
85
|
+
|
86
|
+
input_options = {}
|
87
|
+
input_options[:type] = 'hidden'
|
88
|
+
input_options[:value] = value
|
89
|
+
input_options[:id] = hiddenfield_name
|
90
|
+
input_options[:name] = name
|
91
|
+
|
92
|
+
input input_options
|
93
|
+
|
94
|
+
@scripts << <<-SCRIPT
|
95
|
+
object["#{name}"] = $('##{hiddenfield_name}').val();
|
96
|
+
SCRIPT
|
97
|
+
end
|
98
|
+
|
99
|
+
def dropdown(name, dropdown_label, choice_array, options = {})
|
100
|
+
select_name = options[:id] || @page.create_anchor('select')
|
101
|
+
|
102
|
+
options[:class] = 'form-control'
|
103
|
+
options[:name] = name
|
104
|
+
options[:id] = select_name
|
105
|
+
options[:placeholder] ||= ' '
|
106
|
+
|
107
|
+
form_options = options.clone
|
108
|
+
|
109
|
+
if options[:multiple]
|
110
|
+
|
111
|
+
if options[:multiple_style] == :chosen
|
112
|
+
@page.request_css 'css/plugins/chosen/chosen.css'
|
113
|
+
@page.request_js 'js/plugins/chosen/chosen.jquery.js'
|
114
|
+
|
115
|
+
@page.write_script_once <<-SCRIPT
|
116
|
+
var config = {
|
117
|
+
'.chosen-select' : {placeholder_text_multiple: "#{options[:placeholder]}"},
|
118
|
+
'.chosen-select-deselect' : {allow_single_deselect:true},
|
119
|
+
'.chosen-select-no-single' : {disable_search_threshold:10},
|
120
|
+
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
|
121
|
+
'.chosen-select-width' : {width:"95%"}
|
122
|
+
}
|
123
|
+
for (var selector in config) {
|
124
|
+
$(selector).chosen(config[selector]);
|
125
|
+
}
|
126
|
+
SCRIPT
|
127
|
+
|
128
|
+
form_options[:class] = 'chosen-select'
|
129
|
+
form_options[:style] = 'width: 100%'
|
130
|
+
end
|
131
|
+
|
132
|
+
@scripts << <<-SCRIPT
|
133
|
+
var selections = [];
|
134
|
+
$("##{select_name} option:selected").each(function(i, selected){
|
135
|
+
selections[i] = $(selected).text();
|
136
|
+
});
|
137
|
+
object["#{name}"] = selections;
|
138
|
+
SCRIPT
|
139
|
+
|
140
|
+
else
|
141
|
+
@scripts << <<-SCRIPT
|
142
|
+
object["#{name}"] = $( "##{select_name} option:selected" ).text();
|
143
|
+
SCRIPT
|
144
|
+
end
|
145
|
+
|
146
|
+
div class: 'form-group' do
|
147
|
+
label dropdown_label, class: 'control-label'
|
148
|
+
|
149
|
+
div class: 'input-group', style: 'width: 100%' do
|
150
|
+
method_missing :select, form_options do
|
151
|
+
choice_array.each do |choice|
|
152
|
+
if (options[:value]).to_s == choice.to_s
|
153
|
+
option choice, selected: true
|
154
|
+
else
|
155
|
+
option choice
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def knob(name, options = {})
|
164
|
+
knob_name = @page.create_anchor 'knob'
|
165
|
+
|
166
|
+
@page.request_js 'js/plugins/jsKnob/jquery.knob.js'
|
167
|
+
@page.write_script_once <<-SCRIPT
|
168
|
+
$(".dial").knob();
|
169
|
+
SCRIPT
|
170
|
+
|
171
|
+
knob_options = {}
|
172
|
+
|
173
|
+
knob_options[:id] = knob_name
|
174
|
+
knob_options[:type] = 'text'
|
175
|
+
knob_options[:value] = options[:value] || '0'
|
176
|
+
knob_options[:class] = 'dial'
|
177
|
+
|
178
|
+
options.each do |key, value|
|
179
|
+
knob_options["data-#{key}".to_sym] = value
|
180
|
+
end
|
181
|
+
|
182
|
+
knob_options[:"data-fgColor"] = '#1AB394'
|
183
|
+
knob_options[:"data-width"] = '85'
|
184
|
+
knob_options[:"data-height"] = '85'
|
185
|
+
|
186
|
+
input knob_options
|
187
|
+
|
188
|
+
@scripts << <<-SCRIPT
|
189
|
+
object["#{name}"] = $('##{knob_name}').val();
|
190
|
+
SCRIPT
|
191
|
+
end
|
192
|
+
|
193
|
+
def radio(name, choice_array, options = {})
|
194
|
+
radio_name = @page.create_anchor 'radio'
|
195
|
+
|
196
|
+
choice_array = choice_array.map do |choice|
|
197
|
+
if choice.is_a? Hash
|
198
|
+
{ value: choice[:value], label: choice[:label] }
|
199
|
+
else
|
200
|
+
{ value: choice, label: choice }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
active = choice_array[0][:value]
|
205
|
+
if options[:value] && (choice_array.index { |x| x[:value] == options[:value] } != nil)
|
206
|
+
active = options[:value]
|
207
|
+
end
|
208
|
+
|
209
|
+
div_options = {}
|
210
|
+
curobject = self
|
211
|
+
div_options[:"data-toggle"] = 'buttons' if options[:form] == :button
|
212
|
+
div div_options do
|
213
|
+
choice_array.each do |choice|
|
214
|
+
value = choice[:value]
|
215
|
+
label = choice[:label]
|
216
|
+
|
217
|
+
the_options = Hash.new(options)
|
218
|
+
|
219
|
+
the_options[:checked] = '' if active == value
|
220
|
+
|
221
|
+
if options[:form] == :button
|
222
|
+
the_options[:type] = 'radio'
|
223
|
+
the_options[:value] = value
|
224
|
+
the_options[:name] = name
|
225
|
+
the_options[:form] = :button
|
226
|
+
text curobject.boolean_element(label, the_options)
|
227
|
+
else
|
228
|
+
the_options[:type] = 'radio'
|
229
|
+
the_options[:value] = value
|
230
|
+
the_options[:name] = name
|
231
|
+
text curobject.boolean_element(label, the_options)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
@scripts << <<-SCRIPT
|
237
|
+
object["#{name}"] = $('input[name=#{name}]:checked', '##{@formName}').val()
|
238
|
+
SCRIPT
|
239
|
+
end
|
240
|
+
|
241
|
+
def checkbox(name, checkbox_label, options = {})
|
242
|
+
checkbox_name = options[:id] || @page.create_anchor('checkbox')
|
243
|
+
options[:type] = 'checkbox'
|
244
|
+
options[:name] = name
|
245
|
+
options[:id] = checkbox_name
|
246
|
+
text boolean_element(checkbox_label, options)
|
247
|
+
@scripts << <<-SCRIPT
|
248
|
+
object["#{name}"] = $('##{checkbox_name}').is(":checked");
|
249
|
+
SCRIPT
|
250
|
+
end
|
251
|
+
|
252
|
+
def submit(anIcon, title = {}, options = {}, &block)
|
253
|
+
options[:icon] = anIcon
|
254
|
+
options[:title] = title
|
255
|
+
options[:type] = 'submit'
|
256
|
+
options[:data] = "get_#{@formName}_object()"
|
257
|
+
options[:nosubmit] = true if block
|
258
|
+
_button(options, &block)
|
259
|
+
end
|
260
|
+
|
261
|
+
def boolean_element(checkbox_label, options = {})
|
262
|
+
@page.request_css 'css/plugins/iCheck/custom.css'
|
263
|
+
@page.request_js 'js/plugins/iCheck/icheck.min.js'
|
264
|
+
|
265
|
+
@page.write_script_once <<-SCRIPT
|
266
|
+
$(document).ready(function () {
|
267
|
+
$('.i-checks').iCheck({
|
268
|
+
checkboxClass: 'icheckbox_square-green',
|
269
|
+
radioClass: 'iradio_square-green',
|
270
|
+
});
|
271
|
+
});
|
272
|
+
SCRIPT
|
273
|
+
|
274
|
+
label_options = {}
|
275
|
+
elem = Elements.new(@page, @anchors)
|
276
|
+
elem.instance_eval do
|
277
|
+
if options[:form] == :button
|
278
|
+
options.delete(:form)
|
279
|
+
label class: 'btn btn-primary btn-block btn-outline' do
|
280
|
+
input options
|
281
|
+
text checkbox_label.to_s
|
282
|
+
end
|
283
|
+
else
|
284
|
+
div class: 'i-checks' do
|
285
|
+
label label_options do
|
286
|
+
input options do
|
287
|
+
text " #{checkbox_label}"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
elem.generate
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Weaver
|
2
|
+
class JavaScriptObject
|
3
|
+
def initialize(&block)
|
4
|
+
@object = {}
|
5
|
+
instance_eval(&block) if block
|
6
|
+
end
|
7
|
+
|
8
|
+
def string(name, string)
|
9
|
+
@object[name] = { type: :string, value: string }
|
10
|
+
end
|
11
|
+
|
12
|
+
def variable(name, var_name)
|
13
|
+
@object[name] = { type: :var, value: var_name }
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
result = @object.map do |key, value|
|
18
|
+
value_expression = value[:value]
|
19
|
+
|
20
|
+
value_expression = "\"#{value[:value]}\"" if value[:type] == :string
|
21
|
+
|
22
|
+
"#{key}: #{value_expression}"
|
23
|
+
end.join ','
|
24
|
+
|
25
|
+
"{#{result}}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Weaver
|
2
|
+
# Modal dialog feature
|
3
|
+
class ModalDialog
|
4
|
+
def initialize(page, anchors, id, &block)
|
5
|
+
@page = page
|
6
|
+
@anchors = anchors
|
7
|
+
@id = id || @page.create_anchor('modal')
|
8
|
+
|
9
|
+
@header_content = Elements.new(@page, @anchors)
|
10
|
+
@body_content = Elements.new(@page, @anchors)
|
11
|
+
@footer_content = Elements.new(@page, @anchors)
|
12
|
+
|
13
|
+
instance_eval(&block) if block
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :id
|
17
|
+
|
18
|
+
def header(&block)
|
19
|
+
@header_content.instance_eval(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def body(&block)
|
23
|
+
@body_content.instance_eval(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def footer(&block)
|
27
|
+
@footer_content.instance_eval(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate
|
31
|
+
elem = Elements.new(@page, @anchors)
|
32
|
+
|
33
|
+
id = @id
|
34
|
+
header_content = @header_content
|
35
|
+
body_content = @body_content
|
36
|
+
footer_content = @footer_content
|
37
|
+
|
38
|
+
elem.instance_eval do
|
39
|
+
div class: 'modal fade', id: id, tabindex: -1, role: 'dialog' do
|
40
|
+
div class: 'modal-dialog', role: 'document' do
|
41
|
+
div class: 'modal-content' do
|
42
|
+
div class: 'modal-header' do
|
43
|
+
button '×', type: 'button', class: 'close', "data-dismiss": 'modal', "aria-label": 'Close'
|
44
|
+
text header_content.generate
|
45
|
+
end
|
46
|
+
div class: 'modal-body' do
|
47
|
+
text body_content.generate
|
48
|
+
end
|
49
|
+
div class: 'modal-footer' do
|
50
|
+
text footer_content.generate
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
elem.generate
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# add modal dialog to elements
|
62
|
+
class Elements
|
63
|
+
def modal(id = nil, &block)
|
64
|
+
mm = ModalDialog.new(@page, @anchors, id, &block)
|
65
|
+
@inner_content << mm.generate
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|