formal 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +45 -0
- data/Rakefile +2 -0
- data/formal.gemspec +17 -0
- data/lib/formal.rb +41 -0
- data/lib/formal/version.rb +3 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Hashrocket Workstation
|
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,45 @@
|
|
1
|
+
# Formal
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'formal'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install formal
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
Specify the builder option in your form_for parameters
|
23
|
+
|
24
|
+
```
|
25
|
+
= form_for post, builder: Formal::Builder do |f|
|
26
|
+
```
|
27
|
+
|
28
|
+
This will wrap a ```<dt>``` around labels and a ```<dd>``` around the following helpers:
|
29
|
+
|
30
|
+
- label_tag
|
31
|
+
- text_field
|
32
|
+
- password_field
|
33
|
+
- text_area
|
34
|
+
- select
|
35
|
+
- email_field
|
36
|
+
- search_field
|
37
|
+
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/formal.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/formal/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["mrmicahcooper", "syntaxritual"]
|
6
|
+
gem.email = [""]
|
7
|
+
gem.description = %q{Helpful form builder used by Rocketeers}
|
8
|
+
gem.summary = %q{A form builder that wraps form fields the way we like it at Hashrocket}
|
9
|
+
gem.homepage = "http://github.com/mrmicahcooper/formal"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "formal"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Formal::VERSION
|
17
|
+
end
|
data/lib/formal.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "formal/version"
|
2
|
+
|
3
|
+
module Formal
|
4
|
+
class Builder < ActionView::Helpers::FormBuilder
|
5
|
+
|
6
|
+
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
7
|
+
|
8
|
+
@@field_helper_methods = %w(label_tag text_field password_field text_area select email_field search_field)
|
9
|
+
|
10
|
+
def label(method, text = nil, options = {}, &block)
|
11
|
+
text = text || method.to_s.humanize
|
12
|
+
|
13
|
+
if object.errors.any?
|
14
|
+
error_message = object.errors[method]
|
15
|
+
errors = error_message.is_a?(Array) ? error_message.first : error_message
|
16
|
+
error_span = @template.content_tag(:span, errors, class: 'error')
|
17
|
+
text << " #{error_span}"
|
18
|
+
@template.content_tag(:dt, super(method, text.html_safe, options, &block), class: 'error')
|
19
|
+
else
|
20
|
+
@template.content_tag(:dt, super(method, text.html_safe, options, &block))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@@field_helper_methods.each do |method_name|
|
25
|
+
define_method method_name do |*args|
|
26
|
+
if object.errors.any?
|
27
|
+
@template.content_tag(:dd, super(*args), class: 'error')
|
28
|
+
else
|
29
|
+
@template.content_tag(:dd, super(*args))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_box_with_label(method, text = nil, *args)
|
35
|
+
text = text || method.to_s
|
36
|
+
box = [check_box(method, *args).html_safe, text].join(" ")
|
37
|
+
label(method, box, *args)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mrmicahcooper
|
9
|
+
- syntaxritual
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Helpful form builder used by Rocketeers
|
16
|
+
email:
|
17
|
+
- ''
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- formal.gemspec
|
28
|
+
- lib/formal.rb
|
29
|
+
- lib/formal/version.rb
|
30
|
+
homepage: http://github.com/mrmicahcooper/formal
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.24
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: A form builder that wraps form fields the way we like it at Hashrocket
|
54
|
+
test_files: []
|