labelled_form 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/labelled_form.gemspec +31 -0
- data/lib/labelled_form/version.rb +3 -0
- data/lib/labelled_form.rb +73 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7fb60a6ec307623386f7623a1dba2201fabb8f76
|
4
|
+
data.tar.gz: 02ffc6f6465af02a3943adb352a91e3643b8bc81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f074820f72083508208c500cf3ef0d25ee0560cc3f83e34f09d8d934cf045ad53c1d512c14162323eb47da1b9a64a9fbaa40dfad452a5a235f9e360b117760a
|
7
|
+
data.tar.gz: c2ecda8e527474fe6772b3329d9e3842b43ad7b76c66b40d75c3bf43d68e25ee4ae2dc3ec7bf06411a8ac301ef5b8560ae392ca58ad8b17161853bcc0cf51cb7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
labelled_form
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.4.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
labelled_form (0.1.0)
|
5
|
+
actionview
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionview (5.2.1)
|
11
|
+
activesupport (= 5.2.1)
|
12
|
+
builder (~> 3.1)
|
13
|
+
erubi (~> 1.4)
|
14
|
+
rails-dom-testing (~> 2.0)
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
16
|
+
activesupport (5.2.1)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
builder (3.2.3)
|
22
|
+
concurrent-ruby (1.0.5)
|
23
|
+
crass (1.0.4)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
erubi (1.7.1)
|
26
|
+
i18n (1.1.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
loofah (2.2.2)
|
29
|
+
crass (~> 1.0.2)
|
30
|
+
nokogiri (>= 1.5.9)
|
31
|
+
mini_portile2 (2.3.0)
|
32
|
+
minitest (5.11.3)
|
33
|
+
nokogiri (1.8.4)
|
34
|
+
mini_portile2 (~> 2.3.0)
|
35
|
+
rails-dom-testing (2.0.3)
|
36
|
+
activesupport (>= 4.2.0)
|
37
|
+
nokogiri (>= 1.6)
|
38
|
+
rails-html-sanitizer (1.0.4)
|
39
|
+
loofah (~> 2.2, >= 2.2.2)
|
40
|
+
rake (10.5.0)
|
41
|
+
rspec (3.8.0)
|
42
|
+
rspec-core (~> 3.8.0)
|
43
|
+
rspec-expectations (~> 3.8.0)
|
44
|
+
rspec-mocks (~> 3.8.0)
|
45
|
+
rspec-core (3.8.0)
|
46
|
+
rspec-support (~> 3.8.0)
|
47
|
+
rspec-expectations (3.8.1)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.8.0)
|
50
|
+
rspec-mocks (3.8.0)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-support (3.8.0)
|
54
|
+
thread_safe (0.3.6)
|
55
|
+
tzinfo (1.2.5)
|
56
|
+
thread_safe (~> 0.1)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
bundler (~> 1.16)
|
63
|
+
labelled_form!
|
64
|
+
rake (~> 10.0)
|
65
|
+
rspec (~> 3.0)
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
1.16.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Micah Geisel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# LabelledForm
|
2
|
+
|
3
|
+
Adds `label:` option to Rails form helpers.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Works like you'd expect, or at least, works like I'd expect! Examples:
|
8
|
+
|
9
|
+
```slim
|
10
|
+
form_with :user do |form|
|
11
|
+
|
12
|
+
# Prepends label to field and infers label text
|
13
|
+
form.text_field :email, label: true
|
14
|
+
# <label for="user_email">Email</label>
|
15
|
+
# <input type="text" name="user[email]" id="user_email">
|
16
|
+
|
17
|
+
# Supports specifying different label text
|
18
|
+
form.text_field :name, label: "Full name"
|
19
|
+
# <label for="user_name">Full name</label>
|
20
|
+
# <input type="text" name="user[name]" id="user_name">
|
21
|
+
|
22
|
+
# Appends label to field for radio buttons and checkboxes
|
23
|
+
form.radio_button :gender, "Male", label: true
|
24
|
+
# <input type="radio" name="user[gender]" value="Male" id="user_gender_male">
|
25
|
+
# <label for="user_gender_male">Male</label>
|
26
|
+
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/labelled_form.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "labelled_form"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "labelled_form/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "labelled_form"
|
8
|
+
spec.version = LabelledForm::VERSION
|
9
|
+
spec.authors = ["Micah Geisel"]
|
10
|
+
spec.email = ["micah@botandrose.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Adds label option to Rails form helpers}
|
13
|
+
spec.description = %q{Adds label option to Rails form helpers}
|
14
|
+
spec.homepage = "https://github.com/botandrose/labelled_form"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "actionview"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "labelled_form/version"
|
2
|
+
require "action_view"
|
3
|
+
|
4
|
+
module LabelledForm
|
5
|
+
class Rails < ::Rails::Engine
|
6
|
+
initializer "labelled_form.installation" do
|
7
|
+
ActionView::Base.default_form_builder = Builder
|
8
|
+
end
|
9
|
+
end if defined?(Rails)
|
10
|
+
|
11
|
+
class Builder < ActionView::Helpers::FormBuilder
|
12
|
+
def text_area method, options = {}
|
13
|
+
if label_text = options[:label]
|
14
|
+
label_text = method.to_s.humanize if label_text === true
|
15
|
+
label(method, label_text) + " ".html_safe + super
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def date_field method, options = {}
|
22
|
+
if label_text = options[:label]
|
23
|
+
label_text = method.to_s.humanize if label_text === true
|
24
|
+
label(method, label_text) + " ".html_safe + super
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def email_field method, options = {}
|
31
|
+
if label_text = options[:label]
|
32
|
+
label_text = method.to_s.humanize if label_text === true
|
33
|
+
label(method, label_text) + " ".html_safe + super
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def text_field method, options = {}
|
40
|
+
if label_text = options[:label]
|
41
|
+
label_text = method.to_s.humanize if label_text === true
|
42
|
+
label(method, label_text) + " ".html_safe + super
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def radio_button(method, tag_value, options = {})
|
49
|
+
label_text = options.delete(:label)
|
50
|
+
super.tap do |out|
|
51
|
+
if label_text
|
52
|
+
label_text = tag_value if label_text === true
|
53
|
+
label_field = :"#{method}_#{label_text.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase}"
|
54
|
+
|
55
|
+
out << " ".html_safe
|
56
|
+
out << label(label_field, label_text)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
62
|
+
label_text = options.delete(:label)
|
63
|
+
super.tap do |out|
|
64
|
+
if label_text
|
65
|
+
label_text = checked_value if label_text === true
|
66
|
+
out << " ".html_safe
|
67
|
+
label_options = options[:multiple] ? { value: checked_value } : {}
|
68
|
+
out << label(method, label_text, label_options)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: labelled_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micah Geisel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Adds label option to Rails form helpers
|
70
|
+
email:
|
71
|
+
- micah@botandrose.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- labelled_form.gemspec
|
89
|
+
- lib/labelled_form.rb
|
90
|
+
- lib/labelled_form/version.rb
|
91
|
+
homepage: https://github.com/botandrose/labelled_form
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.6.14
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Adds label option to Rails form helpers
|
115
|
+
test_files: []
|