trenni-formatters 2.7.0 → 2.12.0
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 +5 -5
- data/lib/trenni/formatters.rb +2 -0
- data/lib/trenni/formatters/formatter.rb +52 -2
- data/lib/trenni/formatters/html/accept_checkbox.rb +73 -0
- data/lib/trenni/formatters/html/definition_list_form.rb +68 -38
- data/lib/trenni/formatters/html/form_formatter.rb +68 -61
- data/lib/trenni/formatters/html/label_form.rb +146 -0
- data/lib/trenni/formatters/html/option_select.rb +32 -29
- data/lib/trenni/formatters/html/radio_select.rb +24 -22
- data/lib/trenni/formatters/markdown.rb +7 -7
- data/lib/trenni/formatters/relative_time.rb +2 -0
- data/lib/trenni/formatters/truncated_text.rb +10 -8
- data/lib/trenni/formatters/version.rb +3 -1
- metadata +71 -52
- data/.gitignore +0 -17
- data/.rspec +0 -4
- data/.simplecov +0 -9
- data/.travis.yml +0 -14
- data/Gemfile +0 -12
- data/README.md +0 -77
- data/Rakefile +0 -8
- data/spec/trenni/formatters/formatters_spec.rb +0 -57
- data/spec/trenni/formatters/html/form_formatter_spec.rb +0 -165
- data/spec/trenni/formatters/html/option_select_spec.rb +0 -129
- data/spec/trenni/formatters/html/radio_select_spec.rb +0 -49
- data/spec/trenni/formatters/markdown_spec.rb +0 -34
- data/spec/trenni/formatters/relative_time_spec.rb +0 -38
- data/spec/trenni/formatters/truncated_text_spec.rb +0 -32
- data/trenni-formatters.gemspec +0 -33
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
4
|
#
|
3
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -20,6 +22,6 @@
|
|
20
22
|
|
21
23
|
module Trenni
|
22
24
|
module Formatters
|
23
|
-
VERSION = "2.
|
25
|
+
VERSION = "2.12.0"
|
24
26
|
end
|
25
27
|
end
|
metadata
CHANGED
@@ -1,73 +1,115 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trenni-formatters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: mapping
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: trenni
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bake
|
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: bake-bundler
|
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: bake-modernize
|
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'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: bundler
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
|
-
- - "
|
87
|
+
- - ">="
|
46
88
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
89
|
+
version: '0'
|
48
90
|
type: :development
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
52
|
-
- - "
|
94
|
+
- - ">="
|
53
95
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
96
|
+
version: '0'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
98
|
+
name: covered
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
|
-
- - "
|
101
|
+
- - ">="
|
60
102
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
103
|
+
version: '0'
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
|
-
- - "
|
108
|
+
- - ">="
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
110
|
+
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: rspec
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
115
|
- - ">="
|
@@ -80,44 +122,29 @@ dependencies:
|
|
80
122
|
- - ">="
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
|
-
description:
|
84
|
-
|
85
|
-
that turns model data into presentation text.\n\n\tFormatters are designed to be
|
86
|
-
customised, typically per-project, for specific\n\tformatting needs.\n"
|
87
|
-
email:
|
88
|
-
- samuel.williams@oriontransfer.co.nz
|
125
|
+
description:
|
126
|
+
email:
|
89
127
|
executables: []
|
90
128
|
extensions: []
|
91
129
|
extra_rdoc_files: []
|
92
130
|
files:
|
93
|
-
- ".gitignore"
|
94
|
-
- ".rspec"
|
95
|
-
- ".simplecov"
|
96
|
-
- ".travis.yml"
|
97
|
-
- Gemfile
|
98
|
-
- README.md
|
99
|
-
- Rakefile
|
100
131
|
- lib/trenni/formatters.rb
|
101
132
|
- lib/trenni/formatters/formatter.rb
|
133
|
+
- lib/trenni/formatters/html/accept_checkbox.rb
|
102
134
|
- lib/trenni/formatters/html/definition_list_form.rb
|
103
135
|
- lib/trenni/formatters/html/form_formatter.rb
|
136
|
+
- lib/trenni/formatters/html/label_form.rb
|
104
137
|
- lib/trenni/formatters/html/option_select.rb
|
105
138
|
- lib/trenni/formatters/html/radio_select.rb
|
106
139
|
- lib/trenni/formatters/markdown.rb
|
107
140
|
- lib/trenni/formatters/relative_time.rb
|
108
141
|
- lib/trenni/formatters/truncated_text.rb
|
109
142
|
- lib/trenni/formatters/version.rb
|
110
|
-
- spec/trenni/formatters/formatters_spec.rb
|
111
|
-
- spec/trenni/formatters/html/form_formatter_spec.rb
|
112
|
-
- spec/trenni/formatters/html/option_select_spec.rb
|
113
|
-
- spec/trenni/formatters/html/radio_select_spec.rb
|
114
|
-
- spec/trenni/formatters/markdown_spec.rb
|
115
|
-
- spec/trenni/formatters/relative_time_spec.rb
|
116
|
-
- spec/trenni/formatters/truncated_text_spec.rb
|
117
|
-
- trenni-formatters.gemspec
|
118
143
|
homepage: https://github.com/ioquatix/trenni-formatters
|
119
|
-
licenses:
|
120
|
-
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata:
|
147
|
+
funding_uri: https://github.com/sponsors/ioquatix/
|
121
148
|
post_install_message:
|
122
149
|
rdoc_options: []
|
123
150
|
require_paths:
|
@@ -126,23 +153,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
153
|
requirements:
|
127
154
|
- - ">="
|
128
155
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
156
|
+
version: '2.5'
|
130
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
158
|
requirements:
|
132
159
|
- - ">="
|
133
160
|
- !ruby/object:Gem::Version
|
134
161
|
version: '0'
|
135
162
|
requirements: []
|
136
|
-
|
137
|
-
rubygems_version: 2.6.10
|
163
|
+
rubygems_version: 3.1.2
|
138
164
|
signing_key:
|
139
165
|
specification_version: 4
|
140
166
|
summary: Formatters for Trenni, to assist with typical views and form based interfaces.
|
141
|
-
test_files:
|
142
|
-
- spec/trenni/formatters/formatters_spec.rb
|
143
|
-
- spec/trenni/formatters/html/form_formatter_spec.rb
|
144
|
-
- spec/trenni/formatters/html/option_select_spec.rb
|
145
|
-
- spec/trenni/formatters/html/radio_select_spec.rb
|
146
|
-
- spec/trenni/formatters/markdown_spec.rb
|
147
|
-
- spec/trenni/formatters/relative_time_spec.rb
|
148
|
-
- spec/trenni/formatters/truncated_text_spec.rb
|
167
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.simplecov
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# Trenni::Formatters
|
2
|
-
|
3
|
-
Trenni is a templating system, and these formatters assist with the development
|
4
|
-
of typical view and form based web interface. A formatter is a high-level
|
5
|
-
adapter that turns model data into presentation text.
|
6
|
-
|
7
|
-
Formatters are designed to be customised, typically per-project, for specific
|
8
|
-
formatting needs.
|
9
|
-
|
10
|
-
[](https://travis-ci.org/ioquatix/trenni-formatters)
|
11
|
-
[](https://codeclimate.com/github/ioquatix/trenni-formatters)
|
12
|
-
[](https://coveralls.io/r/ioquatix/trenni-formatters)
|
13
|
-
|
14
|
-
## Motivation
|
15
|
-
|
16
|
-
`Trenni::Formatters` was a library extracted from [Financier](https://github.com/ioquatix/financier) which is a CouchDB backed invoicing system, itself, derived from an old Rails app. I was a bit envious of `form_for` in terms of the ease of generating forms, but found that it wasn't very extendable. I also found myself generating code to format model data as rich HTML. `Trenni::Formatters` attempts to be an easily extendable formatting module which can generate rich text, links and HTML.
|
17
|
-
|
18
|
-
## Installation
|
19
|
-
|
20
|
-
Add this line to your application's Gemfile:
|
21
|
-
|
22
|
-
gem 'trenni-formatters'
|
23
|
-
|
24
|
-
And then execute:
|
25
|
-
|
26
|
-
$ bundle
|
27
|
-
|
28
|
-
Or install it yourself as:
|
29
|
-
|
30
|
-
$ gem install trenni-formatters
|
31
|
-
|
32
|
-
## Usage
|
33
|
-
|
34
|
-
The most basic usage involves converting model data into presentation text by
|
35
|
-
a mapping corresponding to the objects type:
|
36
|
-
|
37
|
-
formatter = Trenni::Formatters::Formatter.new
|
38
|
-
|
39
|
-
formatter.for(String) do |value, options|
|
40
|
-
"String: #{value}"
|
41
|
-
end
|
42
|
-
|
43
|
-
expect(formatter.format("foobar")).to be == "String: foobar"
|
44
|
-
|
45
|
-
For more examples please see `spec/`.
|
46
|
-
|
47
|
-
## Contributing
|
48
|
-
|
49
|
-
1. Fork it
|
50
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
-
5. Create new Pull Request
|
54
|
-
|
55
|
-
## License
|
56
|
-
|
57
|
-
Released under the MIT license.
|
58
|
-
|
59
|
-
Copyright, 2014, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
60
|
-
|
61
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
62
|
-
of this software and associated documentation files (the "Software"), to deal
|
63
|
-
in the Software without restriction, including without limitation the rights
|
64
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
65
|
-
copies of the Software, and to permit persons to whom the Software is
|
66
|
-
furnished to do so, subject to the following conditions:
|
67
|
-
|
68
|
-
The above copyright notice and this permission notice shall be included in
|
69
|
-
all copies or substantial portions of the Software.
|
70
|
-
|
71
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
72
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
73
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
74
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
75
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
76
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
77
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'trenni/formatters'
|
22
|
-
|
23
|
-
module Trenni::FormattersSpec
|
24
|
-
class TestFormatter < Trenni::Formatters::Formatter
|
25
|
-
def initialize(*)
|
26
|
-
@count = 0
|
27
|
-
|
28
|
-
super
|
29
|
-
end
|
30
|
-
|
31
|
-
attr :count
|
32
|
-
|
33
|
-
map(String) do |value, options|
|
34
|
-
@count += 1
|
35
|
-
|
36
|
-
"String: #{value}"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe Trenni::Formatters do
|
41
|
-
let(:test_formatter) {TestFormatter.new(foo: :bar)}
|
42
|
-
|
43
|
-
it "should format string" do
|
44
|
-
expect(test_formatter.format("foobar")).to be == "String: foobar"
|
45
|
-
expect(test_formatter.count).to be == 1
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should format numbers" do
|
49
|
-
expect(test_formatter.format(10)).to be == "10"
|
50
|
-
expect(test_formatter.count).to be == 0
|
51
|
-
end
|
52
|
-
|
53
|
-
it "has options" do
|
54
|
-
expect(test_formatter[:foo]).to be == :bar
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,165 +0,0 @@
|
|
1
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'trenni/formatters'
|
22
|
-
require 'trenni/formatters/html/definition_list_form'
|
23
|
-
|
24
|
-
module Trenni::Formatters::FormFormatterSpec
|
25
|
-
class FormFormatter < Trenni::Formatters::Formatter
|
26
|
-
include Trenni::Formatters::HTML::DefinitionListForm
|
27
|
-
end
|
28
|
-
|
29
|
-
describe Trenni::Formatters do
|
30
|
-
let(:formatter) {FormFormatter.new(:object => double(:bar => 10))}
|
31
|
-
|
32
|
-
it "should generate form" do
|
33
|
-
result = formatter.input(:field => :bar)
|
34
|
-
expect(result).to be == %Q{<dt>Bar</dt>\n<dd><input name="bar" value="10"/></dd>}
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should have default value" do
|
38
|
-
expect(formatter.value_for(:value => 10)).to be == "10"
|
39
|
-
expect(formatter.value_for(:value => nil, :default => 10)).to be == "10"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should have a different title" do
|
43
|
-
result = formatter.input(:field => :bar, :title => "Title")
|
44
|
-
expect(result).to be == %Q{<dt>Title</dt>\n<dd><input name="bar" value="10"/></dd>}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "<input>" do
|
49
|
-
let(:formatter) {FormFormatter.new(:object => double(bar: 10, bob: true, dole: false))}
|
50
|
-
|
51
|
-
it "should support support min, max and step" do
|
52
|
-
attributes = formatter.input_attributes_for(:min => 10, :max => 20, :step => 2)
|
53
|
-
|
54
|
-
expect(attributes[:min]).to be == 10
|
55
|
-
expect(attributes[:max]).to be == 20
|
56
|
-
expect(attributes[:step]).to be == 2
|
57
|
-
|
58
|
-
result = formatter.input(:field => :bar, :min => 10)
|
59
|
-
expect(result).to be == %Q{<dt>Bar</dt>\n<dd><input name="bar" value="10" min="10"/></dd>}
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not specify required, readonly or disabled" do
|
63
|
-
attributes = formatter.input_attributes_for(:field => :bar)
|
64
|
-
expect(attributes[:required]).to be nil
|
65
|
-
expect(attributes[:readonly]).to be nil
|
66
|
-
expect(attributes[:disabled]).to be nil
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should specify required, readonly or disabled" do
|
70
|
-
attributes = formatter.input_attributes_for(:field => :bar, :required => true, :readonly => true, :disabled => true)
|
71
|
-
expect(attributes[:required]).to be true
|
72
|
-
expect(attributes[:readonly]).to be true
|
73
|
-
expect(attributes[:disabled]).to be true
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should generate checked checkbox" do
|
77
|
-
attributes = formatter.checkbox_attributes_for(:value => true)
|
78
|
-
expect(attributes[:checked]).to be true
|
79
|
-
|
80
|
-
result = formatter.checkbox(:field => :bob)
|
81
|
-
expect(result).to be == %Q{<dd>\n\t<input type="hidden" name="bob" value="false"/>\n\t<label><input type="checkbox" name="bob" value="true" checked/> Bob</label>\n</dd>}
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should generate unchecked checkbox" do
|
85
|
-
attributes = formatter.checkbox_attributes_for(:value => false)
|
86
|
-
expect(attributes[:checked]).to be nil
|
87
|
-
|
88
|
-
result = formatter.checkbox(:field => :dole)
|
89
|
-
expect(result).to be == %Q{<dd>\n\t<input type="hidden" name="dole" value="false"/>\n\t<label><input type="checkbox" name="dole" value="true"/> Dole</label>\n</dd>}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe '<input type="hidden">' do
|
94
|
-
let(:formatter) {FormFormatter.new(:object => double(age: 20))}
|
95
|
-
|
96
|
-
it "should generate hidden field" do
|
97
|
-
result = formatter.hidden(:field => :age)
|
98
|
-
expect(result).to be == %Q{<input type="hidden" name="age" value="20"/>}
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should escape characters correctly" do
|
102
|
-
expect(formatter.object).to receive(:new_record?).and_return(false)
|
103
|
-
|
104
|
-
result = formatter.submit
|
105
|
-
expect(result).to be == %Q{<input type="submit" value="Update"/>}
|
106
|
-
end
|
107
|
-
|
108
|
-
it "can have custom title" do
|
109
|
-
result = formatter.submit(title: 'Alice')
|
110
|
-
expect(result).to be == %Q{<input type="submit" value="Alice"/>}
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '<input type="submit">' do
|
115
|
-
let(:new_record_formatter) {FormFormatter.new(:object => double(new_record?: true))}
|
116
|
-
let(:formatter) {FormFormatter.new(:object => double(new_record?: false))}
|
117
|
-
|
118
|
-
it "should have correct title for new_record?" do
|
119
|
-
result = new_record_formatter.submit
|
120
|
-
expect(result).to be == %Q{<input type="submit" value="Create"/>}
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should escape characters correctly" do
|
124
|
-
result = formatter.submit
|
125
|
-
expect(result).to be == %Q{<input type="submit" value="Update"/>}
|
126
|
-
end
|
127
|
-
|
128
|
-
it "can have custom title" do
|
129
|
-
result = formatter.submit(title: 'Alice')
|
130
|
-
expect(result).to be == %Q{<input type="submit" value="Alice"/>}
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "<textarea>" do
|
135
|
-
let(:formatter) {FormFormatter.new(:object => double(details: "foo<bar>"))}
|
136
|
-
|
137
|
-
it "should escape characters correctly" do
|
138
|
-
result = formatter.textarea(:field => :details)
|
139
|
-
expect(result).to be == %Q{<dt>\n\tDetails\n</dt>\n<dd><textarea name=\"details\">foo<bar></textarea></dd>}
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "<output>" do
|
144
|
-
let(:formatter) {FormFormatter.new(:object => double(bar: 10, bob: true, dole: false))}
|
145
|
-
|
146
|
-
it "should show output value" do
|
147
|
-
result = formatter.output(:field => :bar)
|
148
|
-
expect(result).to be == %Q{<dt>Bar</dt>\n<dd><output name=\"bar\">10</output></dd>}
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should show output value" do
|
152
|
-
result = formatter.output(:name => :total)
|
153
|
-
expect(result).to be == %Q{<dt></dt>\n<dd><output name=\"total\"></output></dd>}
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe "<button>" do
|
158
|
-
let(:formatter) {FormFormatter.new}
|
159
|
-
|
160
|
-
it "should generate reset button" do
|
161
|
-
result = formatter.button(:type => :reset)
|
162
|
-
expect(result).to be == %Q{<button type="reset">Reset</button>}
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|