volt-fields 0.1.0 → 0.1.1

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: 1439533100b56c28c830163650ed66c139b97d51
4
- data.tar.gz: a8751d2290e98ee055610ac4e0a369f17aa90688
3
+ metadata.gz: a8fbd4ca3326c03ca5fe299a8b9dbd51cbe68686
4
+ data.tar.gz: 1aecd87172a5df4526e934462c71bdc5ac066def
5
5
  SHA512:
6
- metadata.gz: 22d1f41dc895b0f2105d8920fcc80195940de1ab501c3b4bc0ca057b20f89211f26615d88c9c58ad0fd74d36512a9300ff158da65a84a721c56ff0184025ea7e
7
- data.tar.gz: f11244872e08ec3ff7c73af1784f34f51d11c7b00e7984becf173f1eaebcdf72c4677586f7c59a617200116e4d02169cccdc5014e5cebfe9ab4d1d1cc40727e2
6
+ metadata.gz: b42b0d8240b4bb29a8b6b82f15f07de95ced62454b8c3863efa8cda3093342e09f20036e1736fe8bd3802753f28809c6b69a8b8adce9d99b2d8e9fabf4af3650
7
+ data.tar.gz: 7eba0115f8fd567281c3ad1f5ac6909e91e9eee25a094ff0355d6506d3560aa9d306d13338aaa6a438816f8d61abd501d6a124b09d0247c6b868dbbc8849f857
data/README.md CHANGED
@@ -1,9 +1,56 @@
1
1
  # Volt::Fields
2
2
 
3
- Provides controls for text and textarea fields (at the moment) with the following:
3
+ Provides controls with the following:
4
4
 
5
5
  1. the necessary html for bootstrap
6
6
  2. mark the fields when the blur event happens
7
7
  3. display any marked errors below the field
8
8
 
9
- ### Note: there's some duplication in here that needs to be removed
9
+ Currently supported control types:
10
+ * Text
11
+ * Textarea
12
+ * Select
13
+ * Radio
14
+ * Checkbox
15
+
16
+ ## How to Use
17
+ ### Setup
18
+ Include in your gemfile:
19
+
20
+ ```
21
+ gem 'volt-fields'
22
+ ```
23
+
24
+ Then use fields as tags in your views:
25
+ ```
26
+ <:fields:text value="{{ model.first_name }}"/>
27
+ ```
28
+
29
+ ### Text and Textarea
30
+ ```
31
+ <:fields:text value="{{ model.first_name }}"/>
32
+ ```
33
+
34
+ ### Select
35
+ Select fields accept either an array of options, or an array of {label: '', value: ''} hashes.
36
+
37
+ ```
38
+ <:fields:select value="{{ model.role }}" options="{{ ['User', 'Admin', 'Something Else']}}"/>
39
+ ```
40
+
41
+ ### Radio
42
+ For radio buttons, pass an options array of {label: '', value: ''} hashes.
43
+
44
+ ```
45
+ <:fields:radio value="{{ model.active }}" options="{{[{label: 'Active', value: true},{label:'Inactive', value: false}]}}"/>
46
+ ```
47
+
48
+ For inline radio buttons, use ```:fields:radio:inline```.
49
+
50
+ ### Checkbox
51
+ For checkboxes, use 'checked' instead of 'value' to bind the checkbox to a boolean field.
52
+ ```
53
+ <:fields:checkbox checked="{{ model.active }}"/>
54
+ ```
55
+
56
+ For inline radio buttons, use ```:fields:radio:inline```.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1 +1 @@
1
- # Component dependencies
1
+ # Component dependencies
@@ -1 +1 @@
1
- # Component routes
1
+ # Component routes
@@ -0,0 +1,24 @@
1
+ require 'fields/controllers/main_controller'
2
+
3
+ module Fields
4
+ class CheckboxController < MainController
5
+ before_action :setup_field
6
+
7
+ def setup_field
8
+ # Get the name of the field by looking at the method scope
9
+ @field_name = attrs.checked_last_method.gsub(/^[_]/, '')
10
+ end
11
+
12
+ def inline
13
+ # Get the name of the field by looking at the method scope
14
+ @field_name = attrs.checked_last_method.gsub(/^[_]/, '')
15
+ end
16
+
17
+ # Find the parent reactive value that produced the value
18
+ # (usually just model._field)
19
+ def model
20
+ attrs.checked_parent
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ module Fields
2
+ class MainController < Volt::ModelController
3
+ before_action :setup_field
4
+
5
+ def setup_field
6
+ # Default to text fields
7
+ if attrs.respond_to?(:type)
8
+ @type = attrs.type
9
+ else
10
+ @type = 'text'
11
+ end
12
+
13
+ # Get the name of the field by looking at the method scope
14
+ @field_name = attrs.value_last_method.gsub(/^[_]/, '')
15
+ end
16
+
17
+ # Find the parent reactive value that produced the value
18
+ # (usually just model._field)
19
+ def model
20
+ attrs.value_parent
21
+ end
22
+
23
+ def label
24
+ attrs.label || @field_name.titleize
25
+ end
26
+
27
+ # Find the errors for this field
28
+ def errors
29
+ model.marked_errors[@field_name]
30
+ end
31
+
32
+ # When a field goes out of focus, then we want to start checking a field
33
+ def blur
34
+ model.mark_field!(@field_name)
35
+ end
36
+
37
+ def marked
38
+ model.marked_fields[@field_name]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,15 @@
1
+ require 'fields/controllers/main_controller'
2
+
3
+ module Fields
4
+ class RadioController < MainController
5
+ # When a radio button is clicked, set the value of the field and start checking the field
6
+ def set_field(value)
7
+ model.send("#{@field_name}=", value)
8
+ model.mark_field!(@field_name)
9
+ end
10
+
11
+ def checked?(value)
12
+ value == model.send(@field_name)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ require 'fields/controllers/main_controller'
2
+
3
+ module Fields
4
+ class SelectController < MainController
5
+ def options
6
+ if attrs.options[0].is_a?(Hash)
7
+ options = attrs.options
8
+ else
9
+ options = attrs.options.collect { |option| { value: option, label: option } }
10
+ end
11
+ options
12
+ end
13
+
14
+ def selected?(value)
15
+ true if value == model.send(@field_name)
16
+ end
17
+ end
18
+ end
@@ -1,39 +1,6 @@
1
- module Fields
2
- class TextController < Volt::ModelController
3
- def index
4
- # Default to text fields
5
- if attrs.respond_to?(:type)
6
- @type = attrs.type
7
- else
8
- @type = 'text'
9
- end
10
-
11
- # Get the name of the field by looking at the method scope
12
- @field_name = attrs.value_last_method.gsub(/^[_]/, '')
13
- end
14
-
15
- # Find the parent reactive value that produced the value
16
- # (usually just model._field)
17
- def model
18
- attrs.value_parent
19
- end
20
-
21
- def label
22
- return attrs.label || @field_name.titleize
23
- end
1
+ require 'fields/controllers/main_controller'
24
2
 
25
- # Find the errors for this field
26
- def errors
27
- model.marked_errors[@field_name]
28
- end
29
-
30
- # When a field goes out of focus, then we want to start checking a field
31
- def blur
32
- attrs.value_parent.mark_field!(@field_name)
33
- end
34
-
35
- def marked
36
- model.marked_fields[@field_name]
37
- end
3
+ module Fields
4
+ class TextController < MainController
38
5
  end
39
6
  end
@@ -1,6 +1,6 @@
1
- require 'fields/controllers/text_controller'
1
+ require 'fields/controllers/main_controller'
2
2
 
3
3
  module Fields
4
- class TextareaController < TextController
4
+ class TextareaController < MainController
5
5
  end
6
- end
6
+ end
@@ -0,0 +1,13 @@
1
+ <:Body>
2
+ <div class="checkbox {{ if errors }}has-error{{ elsif marked }}has-success{{ end }}">
3
+ <label>
4
+ <input type="checkbox" checked="{{ attrs.checked }}" e-focusout="blur" />
5
+ {{ label }}
6
+ </label>
7
+ {{ if errors }}
8
+ <span class="glyphicon glyphicon-remove"></span>
9
+ <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
10
+ {{ elsif marked }}
11
+ <span class="glyphicon glyphicon-ok"></span>
12
+ {{ end }}
13
+ </div>
@@ -0,0 +1,13 @@
1
+ <:Body>
2
+ <div class="checkbox-inline {{ if errors }}has-error{{ elsif marked }}has-success{{ end }}">
3
+ <label class="checkbox-inline">
4
+ <input type="checkbox" checked="{{ attrs.checked }}" e-focusout="blur" />
5
+ {{ label }}
6
+ </label>
7
+ {{ if errors }}
8
+ <span class="glyphicon glyphicon-remove"></span>
9
+ <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
10
+ {{ elsif marked }}
11
+ <span class="glyphicon glyphicon-ok"></span>
12
+ {{ end }}
13
+ </div>
@@ -0,0 +1,24 @@
1
+ <:Body>
2
+ <div class="{{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
3
+ {{ attrs.options.each do |option| }}
4
+ <div class="radio">
5
+ {{ if checked?(option['value']) }}
6
+ <label>
7
+ <input type="radio" e-click="set_field(option['value'])" name="{{ @field_name }}_radio" value="{{option['value']}}" checked/>
8
+ {{ option['label'] }}
9
+ </label>
10
+ {{ if errors }}
11
+ <span class="glyphicon glyphicon-remove"></span>
12
+ <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
13
+ {{ elsif marked }}
14
+ <span class="glyphicon glyphicon-ok"></span>
15
+ {{ end }}
16
+ {{ else }}
17
+ <label>
18
+ <input type="radio" e-click="set_field(option['value'])" name="{{ @field_name }}_radio" value="{{option['value']}}"/>
19
+ {{ option['label'] }}
20
+ </label>
21
+ {{ end }}
22
+ {{ end }}
23
+ </div>
24
+ </div>
@@ -0,0 +1,24 @@
1
+ <:Body>
2
+ <div class="{{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
3
+ {{ attrs.options.each do |option| }}
4
+ <div class="radio-inline">
5
+ {{ if checked?(option['value']) }}
6
+ <label class="radio-inline">
7
+ <input type="radio" e-click="set_field(option['value'])" name="{{ @field_name }}_radio" value="{{option['value']}}" checked/>
8
+ {{ option['label'] }}
9
+ </label>
10
+ {{ if errors }}
11
+ <span class="glyphicon glyphicon-remove"></span>
12
+ <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
13
+ {{ elsif marked }}
14
+ <span class="glyphicon glyphicon-ok"></span>
15
+ {{ end }}
16
+ {{ else }}
17
+ <label class="radio-inline">
18
+ <input type="radio" e-click="set_field(option['value'])" name="{{ @field_name }}_radio" value="{{option['value']}}"/>
19
+ {{ option['label'] }}
20
+ </label>
21
+ {{ end }}
22
+ {{ end }}
23
+ </div>
24
+ </div>
@@ -0,0 +1,21 @@
1
+ <:Body>
2
+ <div class="form-group {{ if errors }}has-error{{ elsif marked }}has-success{{ end }} has-feedback">
3
+ {{ if label }}
4
+ <label class="control-label">{{ label }}</label>
5
+ {{ end }}
6
+ <select value="{{ attrs.value }}" e-focusout="blur" class="form-control">
7
+ {{ options.each do |option| }}
8
+ {{ if selected?(option[:value]) }}
9
+ <option value="{{ option[:value] }}" selected> {{ option[:label] }}</option>
10
+ {{ else }}
11
+ <option value="{{ option[:value] }}"> {{ option[:label] }}</option>
12
+ {{ end }}
13
+ {{ end }}
14
+ </select>
15
+ {{ if errors }}
16
+ <span class="glyphicon glyphicon-remove form-control-feedback"></span>
17
+ <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
18
+ {{ elsif marked }}
19
+ <span class="glyphicon glyphicon-ok form-control-feedback"></span>
20
+ {{ end }}
21
+ </div>
@@ -3,7 +3,7 @@
3
3
  {{ if label }}
4
4
  <label class="control-label">{{ label }}</label>
5
5
  {{ end }}
6
- <input type="{{ @type }}" value="{{ attrs.value }}" e-focusout="blur" class="form-control" />
6
+ <input type="{{ @type }}" value="{{ attrs.value }}" e-focusout="blur" class="form-control" placeholder="{{ attrs.placeholder }}" />
7
7
  {{ if errors }}
8
8
  <span class="glyphicon glyphicon-remove form-control-feedback"></span>
9
9
  <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
@@ -3,7 +3,7 @@
3
3
  {{ if label }}
4
4
  <label class="control-label">{{ label }}</label>
5
5
  {{ end }}
6
- <textarea e-focusout="blur" class="form-control">{{ attrs.value }}</textarea>
6
+ <textarea e-focusout="blur" class="form-control" placeholder="{{ attrs.placeholder }}">{{ attrs.value }}</textarea>
7
7
  {{ if errors }}
8
8
  <span class="glyphicon glyphicon-remove form-control-feedback"></span>
9
9
  <span class="control-label errors">{{ (errors || []).join(', ') }}</span>
data/volt-fields.gemspec CHANGED
@@ -19,6 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "volt", "~> 0.7.0"
23
22
  spec.add_development_dependency "rake"
24
23
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt-fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: volt
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.7.0
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.7.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +38,17 @@ files:
52
38
  - VERSION
53
39
  - app/fields/config/dependencies.rb
54
40
  - app/fields/config/routes.rb
41
+ - app/fields/controllers/checkbox_controller.rb
42
+ - app/fields/controllers/main_controller.rb
43
+ - app/fields/controllers/radio_controller.rb
44
+ - app/fields/controllers/select_controller.rb
55
45
  - app/fields/controllers/text_controller.rb
56
46
  - app/fields/controllers/textarea_controller.rb
47
+ - app/fields/views/checkbox/index.html
48
+ - app/fields/views/checkbox/inline.html
49
+ - app/fields/views/radio/index.html
50
+ - app/fields/views/radio/inline.html
51
+ - app/fields/views/select/index.html
57
52
  - app/fields/views/text/index.html
58
53
  - app/fields/views/textarea/index.html
59
54
  - lib/volt/fields.rb
@@ -78,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
73
  version: '0'
79
74
  requirements: []
80
75
  rubyforge_project:
81
- rubygems_version: 2.2.2
76
+ rubygems_version: 2.4.5
82
77
  signing_key:
83
78
  specification_version: 4
84
79
  summary: Provides controls for text and textarea fields with built in error reporting