will_toggle 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec5374cc59fe4999fbaff5aa7fbddcd6ea1baebe
4
- data.tar.gz: 2aeb74a444061a42da77e3eb02dda0ce4becc552
3
+ metadata.gz: f0379145658338008a18ebc2962829c29a0e30b5
4
+ data.tar.gz: d90ebc68ba570b87101d2ae0b6b3024388d61da3
5
5
  SHA512:
6
- metadata.gz: b555f16b6213474981cb1f3781df2054e1ee2796ea7269b9170957d57151400485e569309c7898bcd958b66462ea7fbd941d948c3d06549c0fcb12a42ea22ece
7
- data.tar.gz: 5c00f2042b86c036a87d38360913a97517f13600c06ef35e8be2acb6d478789de8adc02acd9e527fcf433d5c00907984bc51de3e0a56f6ec9ec503aa4f2262ea
6
+ metadata.gz: a894e6325a0a2c1548f253104602cd42ed9f19b8397cfdd9844fdb8121d7fe3491eef88adea32b244eb47499e849d82c5bb855d627be2eb3ca64dc133cb435f8
7
+ data.tar.gz: 412063d25ddbc3a30d10027a1798fb84be23b18e3c35949fc3162f0900e654059ba5f4a23696a9b7efd8e1c5b1a9fefb9c6eecbb3ea6eb29ebe3ee8dfd1ecaa9
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/README.md CHANGED
@@ -12,9 +12,9 @@ This gem is intended to clean up RoR views for jQuery toggling between hidden an
12
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
13
 
14
14
 
15
- ### How does it work?
15
+ ## How does it work?
16
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.
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. Will Toggle allows you to abstract out the javascript functions, div wrappers, and other view elements so that your HTML/ERB/HAML is simple and organized.
18
18
 
19
19
  __Currently will\_toggle only supports a checkbox toggle, however, you can expect many more implementations to come.__
20
20
 
@@ -33,6 +33,9 @@ Or, install it yourself as:
33
33
 
34
34
  $ gem install will_toggle
35
35
 
36
+ In your application.js, you will have to include will\_toggle's scripts with:
37
+
38
+ //= require will_toggle
36
39
 
37
40
  ## Usage
38
41
 
@@ -40,13 +43,6 @@ A minimalist:
40
43
  ```ruby
41
44
  <%= will_toggle label: 'Change Your Password', partial: 'users/password_fields', locals: { f: f } %>
42
45
  ```
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
46
 
51
47
  All the bells and whistles:
52
48
  ```ruby
@@ -57,6 +53,13 @@ All the bells and whistles:
57
53
  locals: { f: f } %>
58
54
  ```
59
55
 
56
+ ### Available options:
57
+
58
+ - `label`: the string you will use to describe the toggled div, i.e. show details.
59
+ - `checked`: true or false, defaults to false. Specifies whether the checkbox will be checked.
60
+ - `locals`: a hash of necessary variables for your partial.
61
+ - `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.
62
+
60
63
  ## Contributing
61
64
 
62
65
  1. Fork it
@@ -1,4 +1,8 @@
1
1
  window.willToggle =
2
2
  toggleNext: (toggleID, clearData = false) ->
3
3
  $(toggleID).slideToggle(200)
4
- $(toggleID).find('input').val('') if clearData
4
+ $(toggleID).find('input').val('') if clearData
5
+
6
+ toggleRadios: (name, toggleID, clearData = false) ->
7
+ $("[name='" + name + "']").parent().parent().find(".will-toggle-content").slideUp(200)
8
+ $(toggleID).slideDown(200)
@@ -1,13 +1,18 @@
1
1
  module WillToggle
2
2
  module ViewHelpers
3
3
  @@toggle_index ||= 0
4
-
4
+
5
5
  def will_toggle(options = {})
6
- attribute = nil
7
6
  @@toggle_index += 1
7
+ attribute = nil
8
8
  generate_html(attribute, options).html_safe
9
9
  end
10
10
 
11
+ def will_toggle_radio(options = {})
12
+ @@toggle_index += 1
13
+ generate_radio_html(options).html_safe
14
+ end
15
+
11
16
  def generate_html(attribute, options = {})
12
17
  <<-HTML
13
18
  <div class='will-toggle-wrapper'>
@@ -20,6 +25,20 @@ module WillToggle
20
25
  </div>
21
26
  HTML
22
27
  end
28
+
29
+
30
+ def generate_radio_html(options = {})
31
+ <<-HTML
32
+ <div class='will-toggle-wrapper'>
33
+ <div class='field radio-button'>
34
+ #{ get_radio_button(options) }
35
+ </div>
36
+ <div class='will-toggle-content' id="will-toggle-#{ @@toggle_index }" style="display: #{ visibility(options[:checked]) };">
37
+ #{ get_partial(options) }
38
+ </div>
39
+ </div>
40
+ HTML
41
+ end
23
42
 
24
43
  def visibility(checked = false)
25
44
  checked ? :block : :none
@@ -36,6 +55,14 @@ module WillToggle
36
55
  end
37
56
  html
38
57
  end
58
+
59
+ def get_radio_button(options = {})
60
+ html = ''
61
+ html << radio_button_tag(options[:name], nil, options[:checked], onChange: js_radio_call(options[:name], options), class: 'check-box will-toggle-radio-button', value: options[:value])
62
+ html << label_tag(nil, options[:label], class: 'will-toggle-label')
63
+ html
64
+ end
65
+
39
66
 
40
67
  def get_partial(options = {})
41
68
  render partial: options[:partial],
@@ -45,7 +72,11 @@ module WillToggle
45
72
  def js_call(options)
46
73
  "willToggle.toggleNext(\'#will-toggle-#{ @@toggle_index }\'#{ js_options(options) });".html_safe
47
74
  end
48
-
75
+
76
+ def js_radio_call(name, options)
77
+ "willToggle.toggleRadios(name, \'#will-toggle-#{ @@toggle_index }\'#{ js_options(options) });".html_safe
78
+ end
79
+
49
80
  def js_options(options)
50
81
  " , #{ options[:clear_data] }" if options[:clear_data]
51
82
  end
@@ -1,3 +1,3 @@
1
1
  module WillToggle
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,74 @@
1
+ # Adopted from:
2
+ # https://github.com/mislav/will_paginate/blob/master/spec/view_helpers/action_view_spec.rb
3
+ Routes = ActionDispatch::Routing::RouteSet.new
4
+
5
+ class DummyController
6
+ attr_reader :request
7
+ attr_accessor :controller_name
8
+
9
+ include ActionController::UrlFor
10
+ include Routes.url_helpers
11
+
12
+ def initialize
13
+ @request = DummyRequest.new
14
+ end
15
+
16
+ def params
17
+ @request.params
18
+ end
19
+
20
+ def env
21
+ {}
22
+ end
23
+
24
+ def _prefixes
25
+ []
26
+ end
27
+ end
28
+
29
+ class IbocorpController < DummyController
30
+ end
31
+
32
+ class DummyRequest
33
+ attr_accessor :symbolized_path_parameters
34
+
35
+ def initialize
36
+ @get = true
37
+ @params = {}
38
+ @symbolized_path_parameters = { controller: :foo, action: :bar }
39
+ end
40
+
41
+ def get?
42
+ @get
43
+ end
44
+
45
+ def post
46
+ @get = false
47
+ end
48
+
49
+ def relative_url_root
50
+ ''
51
+ end
52
+
53
+ def script_name
54
+ ''
55
+ end
56
+
57
+ def params(more = nil)
58
+ @params.update(more) if more
59
+ @params
60
+ end
61
+
62
+ def host_with_port
63
+ 'example.com'
64
+ end
65
+ alias host host_with_port
66
+
67
+ def optional_port
68
+ ''
69
+ end
70
+
71
+ def protocol
72
+ 'http:'
73
+ end
74
+ end
@@ -1,6 +1,9 @@
1
1
  require 'rspec'
2
- require File.expand_path("../../config/environment", __FILE__)
2
+ require 'rails/engine'
3
+ require 'will_toggle'
4
+ require 'action_controller'
5
+ require 'helpers/dummy_controller'
3
6
 
4
7
  RSpec.configure do |config|
5
-
8
+ config.color_enabled = true
6
9
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ViewHelper' do
4
+
5
+ before(:each) do
6
+ @assigns = {}
7
+ @controller = DummyController.new
8
+ @request = @controller.request
9
+ @template = "<%= will_toggle %>"
10
+ end
11
+
12
+ def render(locals)
13
+ @view = ActionView::Base.new([], @assigns, @controller)
14
+ @view.request = @request
15
+ @view.singleton_class.send(:include, @controller._routes.url_helpers)
16
+ @view.render(:inline => @template, :locals => locals)
17
+ end
18
+
19
+ it 'should raise an error when no partial is passed' do
20
+
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_toggle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Otander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -99,7 +99,9 @@ files:
99
99
  - lib/will_toggle/engine.rb
100
100
  - lib/will_toggle/railtie.rb
101
101
  - lib/will_toggle/version.rb
102
+ - spec/helpers/dummy_controller.rb
102
103
  - spec/spec_helper.rb
104
+ - spec/view_helper_spec.rb
103
105
  - will_toggle.gemspec
104
106
  homepage: https://github.com/johnotander/will_toggle
105
107
  licenses:
@@ -126,4 +128,6 @@ signing_key:
126
128
  specification_version: 4
127
129
  summary: Will toggle page content.
128
130
  test_files:
131
+ - spec/helpers/dummy_controller.rb
129
132
  - spec/spec_helper.rb
133
+ - spec/view_helper_spec.rb