formidable-ruby 0.0.1
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/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +9 -0
- data/formidable-ruby.gemspec +19 -0
- data/lib/formidable.rb +9 -0
- data/lib/formidable/form_builder.rb +151 -0
- data/lib/formidable/helpers/form_helper.rb +12 -0
- data/lib/formidable/version.rb +3 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c86eec8a92bdbd6786a14faff2c5e68fcfd7e0a3
|
4
|
+
data.tar.gz: 10664a624e567729ea3e8e7cb82385b58d2609df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c188ac8bc25544d9ced37563468748768d35d516ff7ba67535db9eef5506b40731b1010b42654e3ec98550460d5ad54658f420f4472fd72aa26c7e944d2cff4e
|
7
|
+
data.tar.gz: a3e431d29bbd3421b15507008bddcedf35e35224813efccf36005ee63c9492ef8b5757a1fe793c97d5b39e2167df9244c54eeb7d638207ece8a98c7890933b59
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simpler_form (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rspec (2.12.0)
|
11
|
+
rspec-core (~> 2.12.0)
|
12
|
+
rspec-expectations (~> 2.12.0)
|
13
|
+
rspec-mocks (~> 2.12.0)
|
14
|
+
rspec-core (2.12.2)
|
15
|
+
rspec-expectations (2.12.1)
|
16
|
+
diff-lcs (~> 1.1.3)
|
17
|
+
rspec-mocks (2.12.1)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
rspec
|
24
|
+
simpler_form!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jamal El Milahi
|
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,29 @@
|
|
1
|
+
# Formidable
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'formidable'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install formidable
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'formidable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'formidable-ruby'
|
8
|
+
gem.version = Formidable::VERSION
|
9
|
+
gem.authors = ['Jamal El Milahi']
|
10
|
+
gem.email = ['jamal@elmilahi.com']
|
11
|
+
gem.description = %q{Gem to generate forms}
|
12
|
+
gem.summary = %q{Gem to generate forms}
|
13
|
+
gem.homepage = ''
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
end
|
data/lib/formidable.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
module Formidable
|
2
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
+
delegate :content_tag, to: :@template
|
4
|
+
|
5
|
+
HTML_FIELDS = %w(date_field date_select email_field file_field number_field
|
6
|
+
password_field search_field telephone_field text_area
|
7
|
+
text_field url_field)
|
8
|
+
|
9
|
+
HTML_FIELDS.each do |method_name|
|
10
|
+
define_method(method_name) do |name, *args|
|
11
|
+
content_tag(:div, class: ['field', custom_class(*args)].reject(&:blank?).join(' ')) do
|
12
|
+
custom_label(name, *args) +
|
13
|
+
content_tag(:div, class: 'input') do
|
14
|
+
[prefix(*args), super(name, *args), postfix(*args), error(name), hint(*args), tooltip(*args)].inject(&:+)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def select(name, *args)
|
21
|
+
content_tag(:div, class: ['field', 'select', custom_class(*args)].reject(&:blank?).join(' ')) do
|
22
|
+
custom_label(name, *args) +
|
23
|
+
content_tag(:div, class: 'input') do
|
24
|
+
[super, ' ', error(name), hint(*args)].inject(&:+)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def collection_select(name, *args)
|
30
|
+
content_tag(:div, class: ['field', 'select', custom_class(*args)].reject(&:blank?).join(' ')) do
|
31
|
+
[custom_label(name, *args), super, ' ', error(name), hint(*args)].inject(&:+)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def collection_check_boxes(name, *args)
|
36
|
+
content_tag(:div, class: 'field checkbox-buttons') do
|
37
|
+
custom_label(name, *args) +
|
38
|
+
content_tag(:div, class: 'input') do
|
39
|
+
[super, ' ', error(name), hint(*args)].inject(&:+)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def collection_radio_buttons(name, *args)
|
45
|
+
content_tag(:div, class: 'field radio-buttons') do
|
46
|
+
custom_label(name, *args) +
|
47
|
+
content_tag(:div, class: 'input') do
|
48
|
+
[super, ' ', error(name), hint(*args)].inject(&:+)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_box(name, *args)
|
54
|
+
content_tag(:div, class: ['field', 'checkbox', custom_class(*args)].reject(&:blank?).join(' ')) do
|
55
|
+
[super, ' ', custom_label(name, *args) ,error(name), hint(*args)].inject(&:+)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def radio_button(name, *args)
|
60
|
+
content_tag(:div, class: 'field radio') do
|
61
|
+
[super, ' ', custom_label(name, *args) ,error(name), hint(*args)].inject(&:+)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def submit(*args)
|
66
|
+
options = args.extract_options!
|
67
|
+
if options[:disable_on_click]
|
68
|
+
content_tag(:div, class: 'actions') do
|
69
|
+
super(*args, disabled: options[:disabled], data: { disable_with: options[:disable_on_click] })
|
70
|
+
end
|
71
|
+
else
|
72
|
+
content_tag :div, super(*args, disabled: options[:disabled]), class: 'actions'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def button(*args)
|
77
|
+
options = args.extract_options!
|
78
|
+
if options[:disable_on_click]
|
79
|
+
content_tag(:div, class: 'actions') do
|
80
|
+
super(*args, disabled: options[:disabled], data: { disable_with: options[:disable_on_click] })
|
81
|
+
end
|
82
|
+
else
|
83
|
+
content_tag :div, super(*args, disabled: options[:disabled]), class: 'actions'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def objectify_options(options)
|
90
|
+
super.except(:label, :hint, :tooltip, :prefix, :postfix)
|
91
|
+
end
|
92
|
+
|
93
|
+
def custom_class(*args)
|
94
|
+
options = args.extract_options!
|
95
|
+
if options[:class]
|
96
|
+
options[:class]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def custom_label(name, *args)
|
101
|
+
options = args.extract_options!
|
102
|
+
unless options[:label] == false
|
103
|
+
content_tag(:div, class: 'label') do
|
104
|
+
label(name, options[:label])
|
105
|
+
end
|
106
|
+
else
|
107
|
+
''.html_safe
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def error(name)
|
112
|
+
if object.errors[name].any?
|
113
|
+
content_tag(:div, class: 'error') do
|
114
|
+
object.errors[name].first
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def hint(*args)
|
120
|
+
options = args.extract_options!
|
121
|
+
if options[:hint]
|
122
|
+
content_tag(:span, options[:hint], class: 'hint')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def tooltip(*args)
|
127
|
+
options = args.extract_options!
|
128
|
+
if options[:tooltip]
|
129
|
+
content_tag(:span, options[:tooltip], class: 'tooltip')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def prefix(*args)
|
134
|
+
options = args.extract_options!
|
135
|
+
if options[:prefix]
|
136
|
+
content_tag(:span, options[:prefix], class: 'prefix')
|
137
|
+
else
|
138
|
+
''.html_safe
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def postfix(*args)
|
143
|
+
options = args.extract_options!
|
144
|
+
if options[:postfix]
|
145
|
+
content_tag(:span, options[:postfix], class: 'postfix')
|
146
|
+
else
|
147
|
+
''.html_safe
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Formidable
|
2
|
+
module Helpers
|
3
|
+
module FormHelper
|
4
|
+
::ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
|
5
|
+
|
6
|
+
def formidable_for(object, options = {}, &block)
|
7
|
+
options[:builder] = Formidable::FormBuilder
|
8
|
+
form_for(object, options, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formidable-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamal El Milahi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Gem to generate forms
|
14
|
+
email:
|
15
|
+
- jamal@elmilahi.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- formidable-ruby.gemspec
|
26
|
+
- lib/formidable.rb
|
27
|
+
- lib/formidable/form_builder.rb
|
28
|
+
- lib/formidable/helpers/form_helper.rb
|
29
|
+
- lib/formidable/version.rb
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.4.5.1
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Gem to generate forms
|
53
|
+
test_files: []
|
54
|
+
has_rdoc:
|