formtastic-fake_input 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a93a5466905326193469f4585ef3a5229810fd8bbb20fbc0d6edc1e019c90b8
4
+ data.tar.gz: '09b73445470716adec812de6a9f81affffb1d0f1ef1310e82da86824960696c8'
5
+ SHA512:
6
+ metadata.gz: 4117a9668a164e1cb3de473e42dae5a4ab6bdd7f298bcf3adc66e99fbd044067220d343899d4d419da670465954353a330c12a7f2d37d396c927319dce1d6f83
7
+ data.tar.gz: 8f52c4e1ee2d3a5af4fa08a5a030d147d1774d035c584d36eedde22ef356fbce15c89877ec978938078e6191b9936ea2af3f32db16193d4882453e812cd6a299
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Onlinetours.Ru
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Formtastic FakeInput
2
+
3
+ Fake input class for Formtastic.
4
+
5
+ It generates `<span>` tags for data values instead of `<input>`s.
6
+
7
+ This is useful when you need to show read-only value in the resource edit form using all regular input decorations, giving user a clear understanding of its "readonly-ness" and without the ability to pass its value in the form POST request.
8
+
9
+ It outputs a simple `<label>` with a `<span />` wrapped in the standard `<li>` wrapper.
10
+
11
+ You can also use the `:value` option to set custom value.
12
+
13
+ ## Usage example
14
+ ```erb
15
+ <%= semantic_form_for(@user) do |f| %>
16
+ <%= f.inputs do %>
17
+ <%= f.input :id, :as => :fake %>
18
+ <%= f.input :tax_class, :as => :fake, :value => "Class #{f.object.tax_class}" %>
19
+ <%= f.input :first_name, :as => :string %>
20
+ <% end %>
21
+ <% end %>
22
+ ```
23
+ ```html
24
+ <form ...>
25
+ <fieldset>
26
+ <ol>
27
+ <li class="fake">
28
+ <label for="user_id">Id</label>
29
+ <span id="user_id">123</span>
30
+ </li>
31
+ <li class="fake">
32
+ <label for="user_tax_class">Id</label>
33
+ <span id="user_tax_class">Class 5</span>
34
+ </li>
35
+ <li class="string">
36
+ <label for="user_first_name">First name</label>
37
+ <input type="text" id="user_first_name" name="user[first_name]">
38
+ </li>
39
+ </ol>
40
+ </fieldset>
41
+ </form>
42
+ ```
43
+
44
+ # Copyright
45
+ Copyright © 2018 Michael Klimenko. See LICENSE for details.
@@ -0,0 +1,4 @@
1
+ require 'formtastic'
2
+
3
+ require_relative 'formtastic/inputs/fake_input'
4
+
@@ -0,0 +1,61 @@
1
+ module Formtastic
2
+ module Inputs
3
+ # Outputs a simple `<label>` with a `<span />` wrapped in the standard
4
+ # `<li>` wrapper. This is useful when you need to show read-only value in the form
5
+ # using all regular input decorations, but without the ability to pass its value
6
+ # in the form POST request.
7
+ # Use the `:value` option to set custom value.
8
+ #
9
+ # @example Full form context and output
10
+ #
11
+ # <%= semantic_form_for(@user) do |f| %>
12
+ # <%= f.inputs do %>
13
+ # <%= f.input :id, :as => :fake %>
14
+ # <%= f.input :tax_class, :as => :fake, :value => "Class #{f.object.tax_class}"
15
+ # <%= f.input :first_name, :as => :string %>
16
+ # <% end %>
17
+ # <% end %>
18
+ #
19
+ # <form...>
20
+ # <fieldset>
21
+ # <ol>
22
+ # <li class="fake">
23
+ # <label for="user_id">Id</label>
24
+ # <span id="user_id">123</span>
25
+ # </li>
26
+ # <li class="fake">
27
+ # <label for="user_tax_class">Id</label>
28
+ # <span id="user_tax_class">Class 5</span>
29
+ # </li>
30
+ # <li class="string">
31
+ # <label for="user_first_name">First name</label>
32
+ # <input type="text" id="user_first_name" name="user[first_name]">
33
+ # </li>
34
+ # </ol>
35
+ # </fieldset>
36
+ # </form>
37
+ #
38
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
39
+ class FakeInput
40
+ include Base
41
+ include Base::Stringish
42
+
43
+ def to_html
44
+ input_wrapping do
45
+ label_html << content_html
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def content_html
52
+ builder.template
53
+ .content_tag(:span, input_options, input_html_options) { content }
54
+ end
55
+
56
+ def content
57
+ input_options.delete(:value) || object.public_send(method).to_s
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formtastic-fake_input
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Klimenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: formtastic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ description: |
28
+ It generates `<span>` tags for data values instead of `<input>`s.
29
+ This is useful when you need to show read-only value in the resource edit form using all regular input decorations, giving user a clear understanding of its "readonly-ness" and without the ability to pass its value in the form POST request.
30
+ email: m@klimenko.site
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - lib/formtastic-fake_input.rb
39
+ - lib/formtastic/inputs/fake_input.rb
40
+ homepage: https://github.com/michaelkl/formtastic-fake_input
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ allowed_push_host: https://rubygems.org
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.7.7
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Fake input class for Formtastic
65
+ test_files: []