will_toggle 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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +70 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/will_toggle.js.coffee +4 -0
- data/lib/view_helpers.rb +49 -0
- data/lib/will_toggle.rb +11 -0
- data/lib/will_toggle/engine.rb +4 -0
- data/lib/will_toggle/railtie.rb +11 -0
- data/lib/will_toggle/version.rb +3 -0
- data/spec/spec_helper.rb +6 -0
- data/will_toggle.gemspec +25 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 889d94bb1714f012c6941f1917779b84c9c33db2
|
4
|
+
data.tar.gz: 96353f998c76bbd5095b16e747b83de5ae68edb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1b4f35f454065c2ac36d5ee980e8321cf9e79e5fc54060ede87be8201d96f46925cc4acf6e864a9255786908b700c936fb01cbb6493c4c22e3f2f46665171f2
|
7
|
+
data.tar.gz: 545fb9f001f350d491c6b5c1fa57335992cc0d974e8a1aa9c633cde379e28012abf01b5159a6de2ee1f3504cdd987037503fab38935018e8a60179bcc59bcc65
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 johnotander
|
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,70 @@
|
|
1
|
+
# Will Toggle
|
2
|
+
|
3
|
+
This gem is intended to clean up RoR views for jQuery toggling between hidden and visible elements.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
<%= will_toggle label: 'Change Your Password',
|
7
|
+
partial: 'users/password_fields',
|
8
|
+
checked: false,
|
9
|
+
locals: { f: f } %>
|
10
|
+
```
|
11
|
+
|
12
|
+
Just like that, you now have a `check_box_tag` that will display the `password_fields` partial when checked, and hide it from view when unchecked. This becomes very handy in complex forms when you want to hide certain fields from a user until they actively enable a feature.
|
13
|
+
|
14
|
+
|
15
|
+
### How does it work?
|
16
|
+
|
17
|
+
A `check_box_tag` is added with `label_tag 'Change Your Password'`. The checkbox is wired in to the `onchange` event, which triggers a jQuery function to toggle a `will-toggle-wrapper` that encapsulates the partial.
|
18
|
+
|
19
|
+
__Currently will\_toggle only supports a checkbox toggle, however, you can expect many more implementations to come.__
|
20
|
+
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
gem 'will_toggle'
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
$ bundle install
|
31
|
+
|
32
|
+
Or, install it yourself as:
|
33
|
+
|
34
|
+
$ gem install will_toggle
|
35
|
+
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
A minimalist:
|
40
|
+
```ruby
|
41
|
+
<%= will_toggle label: 'Change Your Password', partial: 'users/password_fields', locals: { f: f } %>
|
42
|
+
```
|
43
|
+
|
44
|
+
### Available options:
|
45
|
+
|
46
|
+
- `label`: the string you will use to describe the toggled div, i.e. show details.
|
47
|
+
- `checked`: true or false, defaults to false. Specifies whether the checkbox will be checked.
|
48
|
+
- `locals`: a hash of necessary variables for your partial.
|
49
|
+
- `clear_data`: true or false, defaults to false. If true, the toggle function will clear any values in any child `text_field` upon toggle. Especially useful for optional form fields.
|
50
|
+
|
51
|
+
All the bells and whistles:
|
52
|
+
```ruby
|
53
|
+
<%= will_toggle label: 'Add Your Twitter Account',
|
54
|
+
partial: 'users/fields/twitter',
|
55
|
+
checked: false,
|
56
|
+
clear_data: true,
|
57
|
+
locals: { f: f } %>
|
58
|
+
```
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
67
|
+
|
68
|
+
## Acknowledgements
|
69
|
+
|
70
|
+
This gem is inspired by [will\_paginate](https://www.github.com/mislav/will_paginate)
|
data/Rakefile
ADDED
data/lib/view_helpers.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module WillToggle
|
2
|
+
module ViewHelpers
|
3
|
+
@@toggle_index ||= 0
|
4
|
+
|
5
|
+
def will_toggle(options = {})
|
6
|
+
attribute = nil
|
7
|
+
@@toggle_index += 1
|
8
|
+
generate_html(attribute, options).html_safe
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate_html(attribute, options = {})
|
12
|
+
<<-HTML
|
13
|
+
<div class='will-toggle-wrapper'>
|
14
|
+
<div class='field check-box'>
|
15
|
+
#{ get_check_box(attribute, options) }
|
16
|
+
</div>
|
17
|
+
<div class='will-toggle-content' id="will-toggle-#{ @@toggle_index }" style="display: #{ visibility(options[:checked]) };">
|
18
|
+
#{ get_partial(options) }
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
HTML
|
22
|
+
end
|
23
|
+
|
24
|
+
def visibility(checked = false)
|
25
|
+
checked ? :block : :none
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_check_box(attribute, options = {})
|
29
|
+
html = ''
|
30
|
+
if attribute
|
31
|
+
html << options[:form].check_box(attribute, onChange: js_call(options), class: 'check-box will-toggle-check-box')
|
32
|
+
html << options[:form].label(attribute, options[:label])
|
33
|
+
else
|
34
|
+
html << check_box_tag(nil, nil, options[:checked], onChange: js_call(options), class: 'check-box will-toggle-check-box')
|
35
|
+
html << label_tag(nil, options[:label], class: 'will-toggle-label')
|
36
|
+
end
|
37
|
+
html
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_partial(options = {})
|
41
|
+
render partial: options[:partial],
|
42
|
+
locals: options[:locals]
|
43
|
+
end
|
44
|
+
|
45
|
+
def js_call(options)
|
46
|
+
"willToggle.toggleNext('#will-toggle-#{ @@toggle_index }', #{ options[:clear_data] });"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/will_toggle.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/will_toggle.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/will_toggle/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "will_toggle"
|
6
|
+
gem.authors = ["John Otander"]
|
7
|
+
gem.email = ["johnotander@gmail.com"]
|
8
|
+
gem.description = %q{This gem will toggle page content, based on the current state of a check button.}
|
9
|
+
gem.summary = %q{Will toggle page content.}
|
10
|
+
gem.homepage = "https://github.com/johnotander/will_toggle"
|
11
|
+
gem.version = WillToggle::VERSION
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency "rails"
|
20
|
+
gem.add_dependency "jquery-rails"
|
21
|
+
|
22
|
+
gem.add_development_dependency "bundler"
|
23
|
+
gem.add_development_dependency "rspec"
|
24
|
+
gem.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: will_toggle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Otander
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
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: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This gem will toggle page content, based on the current state of a check
|
84
|
+
button.
|
85
|
+
email:
|
86
|
+
- johnotander@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- app/assets/javascripts/will_toggle.js.coffee
|
97
|
+
- lib/view_helpers.rb
|
98
|
+
- lib/will_toggle.rb
|
99
|
+
- lib/will_toggle/engine.rb
|
100
|
+
- lib/will_toggle/railtie.rb
|
101
|
+
- lib/will_toggle/version.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- will_toggle.gemspec
|
104
|
+
homepage: https://github.com/johnotander/will_toggle
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.0.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Will toggle page content.
|
128
|
+
test_files:
|
129
|
+
- spec/spec_helper.rb
|