formbuilder 0.0.1.beta
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 +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +89 -0
- data/lib/formbuilder/version.rb +3 -0
- data/lib/formbuilder.rb +83 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7687ac34224c4aa005d8b734426acae27112d263
|
4
|
+
data.tar.gz: b55cf5aade5b6fd898cf875cf4f72113bfa633b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4f0b60ee4ba3d0200967fb6b52632d6da7ed6d5e5809b1a5025c3314167d55685369aea9697ed61fe86232165cd96037af4d9f5558801b4005144515113849b
|
7
|
+
data.tar.gz: ca523fb2d9ae8be12cd4bc08bcfeb7a6286a4102cb0af795bba8bcaf8a13393a98a02dfdc7e1aaa02716dba718fac9dd4280fcad91172e4337236115129c7639
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tim
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
formbuilder
|
2
|
+
==================
|
3
|
+
|
4
|
+
This project has many changes to it, but it is heavily based on the jquery.formbuilder project. (https://github.com/botskonet/jquery.formbuilder)
|
5
|
+
|
6
|
+
Changes:
|
7
|
+
-------
|
8
|
+
|
9
|
+
* There is no longer a checkbox group. Each checkbox element created is just one checkbox.
|
10
|
+
* Rearranged defaults object:
|
11
|
+
|
12
|
+
```javascript
|
13
|
+
var defaults = {
|
14
|
+
// must have jquery ui included to make sortable.
|
15
|
+
sortable: false,
|
16
|
+
save: {
|
17
|
+
url: false,
|
18
|
+
complete_function: function(xhr, status) {},
|
19
|
+
data_type: 'json'
|
20
|
+
},
|
21
|
+
load_url: false,
|
22
|
+
control_box_target: false,
|
23
|
+
save_button_classes: false,
|
24
|
+
serialize_prefix: 'frmb',
|
25
|
+
types: {
|
26
|
+
text: {
|
27
|
+
icon: false,
|
28
|
+
label: 'Text Field',
|
29
|
+
value: 'input_text'
|
30
|
+
},
|
31
|
+
paragraph: {
|
32
|
+
icon: false,
|
33
|
+
label: 'Paragraph Field',
|
34
|
+
value: 'textarea'
|
35
|
+
},
|
36
|
+
checkbox: {
|
37
|
+
icon: false,
|
38
|
+
label: 'Checkbox',
|
39
|
+
value: 'checkbox'
|
40
|
+
},
|
41
|
+
radio: {
|
42
|
+
icon: false,
|
43
|
+
label: 'Radio Group',
|
44
|
+
value: 'radio'
|
45
|
+
},
|
46
|
+
select: {
|
47
|
+
icon: false,
|
48
|
+
label: 'Select Box',
|
49
|
+
value: 'select'
|
50
|
+
}
|
51
|
+
},
|
52
|
+
messages: {
|
53
|
+
save: "Save",
|
54
|
+
add_new_field: "Add New Field...",
|
55
|
+
title: "Title",
|
56
|
+
label: "Label",
|
57
|
+
select_options: "Select Options",
|
58
|
+
add: "Add",
|
59
|
+
remove_message: "Are you sure you want to remove this element?",
|
60
|
+
remove: "Remove",
|
61
|
+
selections_message: "Allow Multiple Selections",
|
62
|
+
hide: "Hide",
|
63
|
+
required: "Required",
|
64
|
+
show: "Show",
|
65
|
+
checked: 'Checked'
|
66
|
+
}
|
67
|
+
};
|
68
|
+
```
|
69
|
+
* made list items optionally sortable (see defaults)
|
70
|
+
* changed controls from a select box to a list of list items
|
71
|
+
* added optional icons for control list items
|
72
|
+
* various changes to JSON that is submitted to save.url
|
73
|
+
|
74
|
+
|
75
|
+
Usage
|
76
|
+
-----
|
77
|
+
```
|
78
|
+
$('any_element').formbuilder({options_to_override_defaults})
|
79
|
+
```
|
80
|
+
|
81
|
+
I have also added a server side parser written in ruby to generate html from the json that is saved.
|
82
|
+
|
83
|
+
Contributing
|
84
|
+
------------
|
85
|
+
1. Fork it
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create new Pull Request
|
data/lib/formbuilder.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
module Formbuilder
|
2
|
+
class << self
|
3
|
+
def generate_html(data)
|
4
|
+
@html = ''
|
5
|
+
JSON.parse(data).each { |field| build_field(field[0], field[1]) }
|
6
|
+
return @html
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_field(index, field)
|
10
|
+
case field['cssClass']
|
11
|
+
when 'input_text'
|
12
|
+
@html += build_text_input(field)
|
13
|
+
when 'textarea'
|
14
|
+
@html += build_textarea(field)
|
15
|
+
when 'checkbox'
|
16
|
+
@html += build_checkbox(field)
|
17
|
+
when 'radio'
|
18
|
+
@html += build_radio(field)
|
19
|
+
when 'select'
|
20
|
+
@html += build_select(field)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_text_input(f)
|
25
|
+
s = f['required'] == 'true' ? "<label><abbr title='required'>*</abbr>#{f['title']}</label>" : "<label>#{f['title']}</label>"
|
26
|
+
s += "<input type='text' name='custom_fields[#{nameize(f['title'])}]' />"
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_textarea(f)
|
30
|
+
s = f['required'] == 'true' ? "<label><abbr title='required'>*</abbr>#{f['title']}</label>" : "<label>#{f['title']}</label>"
|
31
|
+
s += "<textarea name='custom_fields[#{nameize(f['title'])}]'></textarea>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_checkbox(f)
|
35
|
+
s = "<label class='checkbox'>"
|
36
|
+
s += f['required'] == 'true' ? "<abbr class='required'>*</abbr>" : ''
|
37
|
+
s += "<input type='checkbox'#{ f['baseline'] == 'true' ? " checked='checked'" : '' } value='1' name='custom_fields[#{nameize(f['title'])}]'> #{f['title']}"
|
38
|
+
s += "<input type='hidden' value='0' name='custom_fields[#{nameize(f['title'])}]'>"
|
39
|
+
s += '</label>'
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_radio(f)
|
43
|
+
s = "<label>#{f['title']}</label>"
|
44
|
+
f['values'].each do |v|
|
45
|
+
attrs = v[1]
|
46
|
+
s += "<label class='radio'>"
|
47
|
+
s += "<input type='radio'#{ attrs['baseline'] == 'true' ? " checked='checked'" : '' } value='#{attrs['value']}' name='custom_fields[#{nameize(f['title'])}]'> #{ attrs['value'] }"
|
48
|
+
s += "</label>"
|
49
|
+
end
|
50
|
+
s
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_select(f)
|
54
|
+
s = "<label>#{f['title']}</label>"
|
55
|
+
if f['multiple'] == 'true'
|
56
|
+
s += "<select multiple='multiple' name='custom_fields[#{nameize(f['title'])}]'>"
|
57
|
+
else
|
58
|
+
s += "<select name='custom_fields[#{nameize(f['title'])}]'>"
|
59
|
+
end
|
60
|
+
f['values'].each do |v|
|
61
|
+
attrs = v[1]
|
62
|
+
if attrs['baseline'] == 'true'
|
63
|
+
s += "<option value='#{attrs['value']}' selected='selected'>"
|
64
|
+
else
|
65
|
+
s += "<option value='#{attrs['value']}'>"
|
66
|
+
end
|
67
|
+
s += attrs['value']
|
68
|
+
s += "</option>"
|
69
|
+
end
|
70
|
+
s += "</select>"
|
71
|
+
end
|
72
|
+
|
73
|
+
def nameize(string)
|
74
|
+
string.gsub(/\s+/, "_").downcase rescue nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module Rails
|
79
|
+
class Engine < ::Rails::Engine
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formbuilder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: formbuilder
|
42
|
+
email:
|
43
|
+
- thogg4@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/formbuilder/version.rb
|
49
|
+
- lib/formbuilder.rb
|
50
|
+
- README.md
|
51
|
+
- LICENSE.txt
|
52
|
+
homepage: ''
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>'
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.3.1
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.0.0.rc.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: formbuilder
|
76
|
+
test_files: []
|