trenni-formatters 2.8.0 → 2.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trenni/formatters.rb +2 -0
- data/lib/trenni/formatters/formatter.rb +9 -1
- data/lib/trenni/formatters/html/accept_checkbox.rb +73 -0
- data/lib/trenni/formatters/html/definition_list_form.rb +61 -36
- data/lib/trenni/formatters/html/form_formatter.rb +68 -51
- 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 +2 -0
- data/lib/trenni/formatters/version.rb +3 -1
- metadata +69 -49
- data/.gitignore +0 -17
- data/.rspec +0 -4
- data/.simplecov +0 -9
- data/.travis.yml +0 -8
- 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 -186
- 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,129 +0,0 @@
|
|
1
|
-
# Copyright, 2014, 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
|
-
require 'trenni/formatters/html/option_select'
|
24
|
-
|
25
|
-
module Trenni::Formatters::HTML::OptionSelectSpec
|
26
|
-
class FormFormatter < Trenni::Formatters::Formatter
|
27
|
-
include Trenni::Formatters::HTML::DefinitionListForm
|
28
|
-
|
29
|
-
def select(options = {}, &block)
|
30
|
-
element(Trenni::Formatters::HTML::OptionSelect, options, &block)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def capture(&block)
|
35
|
-
_out = ""
|
36
|
-
|
37
|
-
Trenni::Template.capture do
|
38
|
-
formatter.select :field => :bar do |select|
|
39
|
-
_out << select.item(:title => "A", :value => 0)
|
40
|
-
_out << select.item(:title => "B", :value => 10)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe Trenni::Formatters::HTML::OptionSelect do
|
46
|
-
let(:formatter) {FormFormatter.new(:object => double(:bar => 10))}
|
47
|
-
|
48
|
-
it "should list items" do
|
49
|
-
_out = ""
|
50
|
-
|
51
|
-
captured = Trenni::Template.capture do
|
52
|
-
formatter.select :field => :bar do |select|
|
53
|
-
_out << select.item(:title => "A", :value => 0)
|
54
|
-
_out << select.item(:title => "B", :value => 10)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
expect(captured).to be == "<dt>Bar</dt>\n<dd>\n\t<select name=\"bar\">\n\t\t<option value=\"0\">A</option><option value=\"10\" selected>B</option>\n\t</select>\n</dd>"
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should list items with data attributes" do
|
62
|
-
_out = ""
|
63
|
-
|
64
|
-
captured = Trenni::Template.capture do
|
65
|
-
formatter.select :field => :bar do |select|
|
66
|
-
_out << select.item(:title => "A", :value => 0, :data => {foo: 'bar'})
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
expect(captured).to be == "<dt>Bar</dt>\n<dd>\n\t<select name=\"bar\">\n\t\t<option value=\"0\" data-foo=\"bar\">A</option>\n\t</select>\n</dd>"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should list items for multiple selection" do
|
74
|
-
_out = ""
|
75
|
-
|
76
|
-
captured = Trenni::Template.capture do
|
77
|
-
formatter.select :field => :bar, multiple: true do |select|
|
78
|
-
_out << select.item(:title => "A", :value => 0)
|
79
|
-
_out << select.item(:title => "B", :value => 10)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
expect(captured).to be == "<dt>Bar</dt>\n<dd>\n\t<select name=\"bar[]\" multiple>\n\t\t<option value=\"0\">A</option><option value=\"10\" selected>B</option>\n\t</select>\n</dd>"
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should add optional item" do
|
87
|
-
_out = ""
|
88
|
-
|
89
|
-
captured = Trenni::Template.capture do
|
90
|
-
formatter.select :field => :bar, optional: true do |select|
|
91
|
-
_out << select.item(:title => "A", :value => 0)
|
92
|
-
_out << select.item(:title => "B", :value => 10)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
expect(captured).to be == "<dt>Bar</dt>\n<dd>\n\t<select name=\"bar\">\n\t\t<option></option>\t\t<option value=\"0\">A</option><option value=\"10\" selected>B</option>\n\t</select>\n</dd>"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should add optional item in group" do
|
100
|
-
_out = ""
|
101
|
-
|
102
|
-
captured = Trenni::Template.capture do
|
103
|
-
formatter.select :field => :bar do |select|
|
104
|
-
select.group(title: 'group', optional: true) do
|
105
|
-
_out << select.item(:title => "A", :value => 0)
|
106
|
-
end
|
107
|
-
_out << select.item(:title => "B", :value => 10)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
expect(captured).to be == "<dt>Bar</dt>\n<dd>\n\t<select name=\"bar\">\n\t\t<optgroup label=\"group\">\n\t\t\t<option></option>\t\t\t<option value=\"0\">A</option>\n\t\t</optgroup>\t\t<option value=\"10\" selected>B</option>\n\t</select>\n</dd>"
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should add a group" do
|
115
|
-
_out = ""
|
116
|
-
|
117
|
-
captured = Trenni::Template.capture do
|
118
|
-
formatter.select :field => :bar do |select|
|
119
|
-
select.group(title: 'group') do
|
120
|
-
_out << select.item(:title => "A", :value => 0)
|
121
|
-
end
|
122
|
-
_out << select.item(:title => "B", :value => 10)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
expect(captured).to be == "<dt>Bar</dt>\n<dd>\n\t<select name=\"bar\">\n\t\t<optgroup label=\"group\">\n\t\t\t<option value=\"0\">A</option>\n\t\t</optgroup>\t\t<option value=\"10\" selected>B</option>\n\t</select>\n</dd>"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Copyright, 2014, 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/radio_select'
|
23
|
-
|
24
|
-
module Trenni::Formatters::HTML::RadioSelectSpec
|
25
|
-
class FormFormatter < Trenni::Formatters::Formatter
|
26
|
-
include Trenni::Formatters::HTML::DefinitionListForm
|
27
|
-
|
28
|
-
def select(options = {}, &block)
|
29
|
-
element(Trenni::Formatters::HTML::RadioSelect, options, &block)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe Trenni::Formatters::HTML::RadioSelect do
|
34
|
-
let(:formatter) {FormFormatter.new(:object => double(:bar => 10))}
|
35
|
-
|
36
|
-
it "should list items" do
|
37
|
-
_out = ""
|
38
|
-
|
39
|
-
captured = Trenni::Template.capture do
|
40
|
-
formatter.select :field => :bar do |select|
|
41
|
-
_out << select.item(:title => "A", :value => 0)
|
42
|
-
_out << select.item(:title => "B", :value => 10)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
expect(captured).to be == %Q{<dt>Bar</dt>\n<dd>\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td class="handle"><input type="radio" name="bar" value="0"/></td>\n\t\t\t\t<td class="item">A</td>\n\t\t\t</tr><tr>\n\t\t\t\t<td class="handle"><input type="radio" name="bar" value="10" checked/></td>\n\t\t\t\t<td class="item">B</td>\n\t\t\t</tr>\n\t\t</tbody>\n\t</table>\n</dd>}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright, 2017, 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/formatter'
|
22
|
-
require 'trenni/formatters/markdown'
|
23
|
-
|
24
|
-
describe Trenni::Formatters::Markdown do
|
25
|
-
subject {Class.new(Trenni::Formatters::Formatter).include(Trenni::Formatters::Markdown).new}
|
26
|
-
|
27
|
-
let(:sample_text) {"# Heading\n\nParagraph\n"}
|
28
|
-
|
29
|
-
it "should format markdown" do
|
30
|
-
result = subject.markdown(sample_text)
|
31
|
-
|
32
|
-
expect(result).to include('<h1>', '<p>')
|
33
|
-
end
|
34
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# Copyright, 2017, 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/formatter'
|
22
|
-
require 'trenni/formatters/relative_time'
|
23
|
-
|
24
|
-
describe Trenni::Formatters::RelativeTime do
|
25
|
-
subject {Class.new(Trenni::Formatters::Formatter).include(Trenni::Formatters::RelativeTime).new}
|
26
|
-
|
27
|
-
let(:now) {Time.now}
|
28
|
-
let(:time_this_year) {Time.mktime(now.year, 1, 1)}
|
29
|
-
let(:time_last_year) {Time.mktime(now.year - 1, 1, 1)}
|
30
|
-
|
31
|
-
it "should format without year" do
|
32
|
-
expect(subject.format(time_this_year, current_time: now)).to be == "January 1, 12:00am"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should format with year" do
|
36
|
-
expect(subject.format(time_last_year, current_time: now)).to be == "January 1, 12:00am, #{time_last_year.year}"
|
37
|
-
end
|
38
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# Copyright, 2017, 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/formatter'
|
22
|
-
require 'trenni/formatters/truncated_text'
|
23
|
-
|
24
|
-
describe Trenni::Formatters::TruncatedText do
|
25
|
-
subject {Class.new(Trenni::Formatters::Formatter).include(Trenni::Formatters::TruncatedText).new}
|
26
|
-
|
27
|
-
let(:sample_text) {"The quick brown fox jumped over the lazy dog!"}
|
28
|
-
|
29
|
-
it "should truncate text" do
|
30
|
-
expect(subject.truncated_text(sample_text)).to be == "The quick brown fox jumped ..."
|
31
|
-
end
|
32
|
-
end
|
data/trenni-formatters.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'trenni/formatters/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "trenni-formatters"
|
8
|
-
spec.version = Trenni::Formatters::VERSION
|
9
|
-
spec.authors = ["Samuel Williams"]
|
10
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
-
spec.description = <<-EOF
|
12
|
-
Trenni is a templating system, and these formatters assist with the development
|
13
|
-
of typical view and form based web interface. A formatter is a high-level
|
14
|
-
adapter that turns model data into presentation text.
|
15
|
-
|
16
|
-
Formatters are designed to be customised, typically per-project, for specific
|
17
|
-
formatting needs.
|
18
|
-
EOF
|
19
|
-
spec.summary = %q{Formatters for Trenni, to assist with typical views and form based interfaces.}
|
20
|
-
spec.homepage = "https://github.com/ioquatix/trenni-formatters"
|
21
|
-
|
22
|
-
spec.files = `git ls-files`.split($/)
|
23
|
-
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
24
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
-
spec.require_paths = ["lib"]
|
26
|
-
|
27
|
-
spec.add_dependency "trenni", "~> 3.4"
|
28
|
-
spec.add_dependency "mapping", "~> 1.1"
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler"
|
31
|
-
spec.add_development_dependency "rspec", "~> 3.4"
|
32
|
-
spec.add_development_dependency "rake"
|
33
|
-
end
|