trenni-formatters 2.6.0 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.6.0"
25
+ VERSION = "2.11.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.6.0
4
+ version: 2.11.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: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: trenni
14
+ name: mapping
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
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: '3.0'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: mapping
28
+ name: trenni
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
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: '1.1'
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: '1.3'
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: '1.3'
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
- name: rspec
98
+ name: covered
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
- - - "~>"
101
+ - - ">="
60
102
  - !ruby/object:Gem::Version
61
- version: '3.4'
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: '3.4'
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: rake
112
+ name: rspec
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - ">="
@@ -80,44 +122,28 @@ dependencies:
80
122
  - - ">="
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
- description: "\tTrenni is a templating system, and these formatters assist with the
84
- development\n\tof typical view and form based web interface. A formatter is a high-level\n\tadapter
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
102
133
  - lib/trenni/formatters/html/definition_list_form.rb
103
134
  - lib/trenni/formatters/html/form_formatter.rb
135
+ - lib/trenni/formatters/html/label_form.rb
104
136
  - lib/trenni/formatters/html/option_select.rb
105
137
  - lib/trenni/formatters/html/radio_select.rb
106
138
  - lib/trenni/formatters/markdown.rb
107
139
  - lib/trenni/formatters/relative_time.rb
108
140
  - lib/trenni/formatters/truncated_text.rb
109
141
  - lib/trenni/formatters/version.rb
110
- - spec/trenni/formatters/form_formatter_spec.rb
111
- - spec/trenni/formatters/formatters_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
142
  homepage: https://github.com/ioquatix/trenni-formatters
119
- licenses: []
120
- metadata: {}
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ funding_uri: https://github.com/sponsors/ioquatix/
121
147
  post_install_message:
122
148
  rdoc_options: []
123
149
  require_paths:
@@ -126,23 +152,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
152
  requirements:
127
153
  - - ">="
128
154
  - !ruby/object:Gem::Version
129
- version: '0'
155
+ version: '2.5'
130
156
  required_rubygems_version: !ruby/object:Gem::Requirement
131
157
  requirements:
132
158
  - - ">="
133
159
  - !ruby/object:Gem::Version
134
160
  version: '0'
135
161
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.6.10
162
+ rubygems_version: 3.1.2
138
163
  signing_key:
139
164
  specification_version: 4
140
165
  summary: Formatters for Trenni, to assist with typical views and form based interfaces.
141
- test_files:
142
- - spec/trenni/formatters/form_formatter_spec.rb
143
- - spec/trenni/formatters/formatters_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
166
+ test_files: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --format documentation
3
- --backtrace
4
- --warnings
data/.simplecov DELETED
@@ -1,9 +0,0 @@
1
-
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- if ENV['TRAVIS']
7
- require 'coveralls'
8
- Coveralls.wear!
9
- end
@@ -1,14 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.1.8
5
- - 2.2.4
6
- - 2.3.0
7
- - 2.4.0
8
- - ruby-head
9
- - rbx-2
10
- env: COVERAGE=true
11
- matrix:
12
- allow_failures:
13
- - rvm: "rbx-2"
14
- - rvm: "ruby-head"
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in trenni-formatters.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'sanitize'
8
- gem 'kramdown'
9
-
10
- gem 'simplecov'
11
- gem 'coveralls', require: false
12
- end
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
- [![Build Status](https://travis-ci.org/ioquatix/trenni-formatters.svg?branch=master)](https://travis-ci.org/ioquatix/trenni-formatters)
11
- [![Code Climate](https://codeclimate.com/github/ioquatix/trenni-formatters.png)](https://codeclimate.com/github/ioquatix/trenni-formatters)
12
- [![Coverage Status](https://coveralls.io/repos/ioquatix/trenni-formatters/badge.svg)](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,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
7
-
8
- task :default => :spec
@@ -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>\nDetails</dt>\n<dd><textarea name=\"details\">foo&lt;bar&gt;</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