trenni-formatters 2.6.0 → 2.11.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.
@@ -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,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
@@ -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.0"
28
- spec.add_dependency "mapping", "~> 1.1"
29
-
30
- spec.add_development_dependency "bundler", "~> 1.3"
31
- spec.add_development_dependency "rspec", "~> 3.4"
32
- spec.add_development_dependency "rake"
33
- end