trenni-formatters 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc3cefa3c833f41f4a54287eb8b4e49b38a386f2
4
- data.tar.gz: 4c87174bfcb5aa9892beb03918bc4bcc0fabfaa2
3
+ metadata.gz: 1d07510393a4aecacebc320982d9382532413cce
4
+ data.tar.gz: b6a714803a220c15b55bd7b231fb2b62c60b1b14
5
5
  SHA512:
6
- metadata.gz: 3c9a7c3eb4efc74fe0c99bbaf69e15c89caad2b17f9837981a8e4c8554e4447dd4885db509ab09dfed02179ff134c7baae45b9a3321b5415e61cebd9f890e6e6
7
- data.tar.gz: dc8837a2db6db5a06a8b484b765549eafc304dfe191e65972693dd0e88f802151e5dbb3f113658ab7c06bd63a0bc99177f9e96db121fb0fc67f82f705f068546
6
+ metadata.gz: 828c3ea8d67b34e7d1f5d3ab04aa5666d6b47028e45f2e63585bbff812a4baeced3ef6b6d7550b5b28b23c6b311c3e0a304ea763ad04ac260cfccc1fafe7ae52
7
+ data.tar.gz: 2add9c98f3c1af745192bf3acadc3c6112b3a67406fa0c31df25c85af48072956599ee3dbf486e3c75e0f8056207074ac9621e60789d5993c2f8d298a30dcb05
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'trenni/builder'
22
+ require 'trenni/template'
22
23
 
23
24
  require_relative 'form_formatter'
24
25
 
@@ -85,9 +86,9 @@ module Trenni
85
86
  # A submission button
86
87
  def submit(options = {})
87
88
  options = @options.merge(options)
88
-
89
- unless options[:field]
90
- options[:title] ||= self.object.saved? ? 'Update' : 'Create'
89
+
90
+ unless title = title_for(options)
91
+ options[:title] ||= new_record? ? 'Create' : 'Update'
91
92
  end
92
93
 
93
94
  Builder.fragment do |builder|
@@ -29,6 +29,15 @@ module Trenni
29
29
  @options[:object]
30
30
  end
31
31
 
32
+ # Return true if the object is begin created or false if it is being updated.
33
+ def new_record?
34
+ if object.respond_to? :new_record?
35
+ return object.new_record?
36
+ elsif self.object.respond_to? :saved?
37
+ return !object.saved?
38
+ end
39
+ end
40
+
32
41
  # The name of the field, used for the name attribute of an input.
33
42
  def name_for(options)
34
43
  options[:name] || options[:field]
@@ -37,12 +46,14 @@ module Trenni
37
46
  def field_for(options)
38
47
  options[:field]
39
48
  end
40
-
41
- # The human presentable title for the field.
49
+
50
+ # A title is a text string that will be displayed next to or on top of the control to describe it or its value:
42
51
  def title_for(options)
43
- title = options[:title] || Strings::to_title(options[:field].to_s)
52
+ title = options[:title]
53
+ return Strings::to_html(title) if title
44
54
 
45
- Strings::to_html(title)
55
+ field_name = field_for(options)
56
+ return Strings::to_title(field_name.to_s) if field_name
46
57
  end
47
58
 
48
59
  def object_value_for(options)
@@ -85,6 +96,9 @@ module Trenni
85
96
  :min => options[:min],
86
97
  :max => options[:max],
87
98
  :step => options[:step],
99
+ # for <input type="text">
100
+ :minlength => options[:minlength],
101
+ :maxlength => options[:maxlength],
88
102
  }
89
103
 
90
104
  return attributes
@@ -110,7 +124,10 @@ module Trenni
110
124
  :required => options[:required],
111
125
  :disabled => options[:disabled],
112
126
  :readonly => options[:readonly],
127
+ :pattern => pattern_for(options),
113
128
  :placeholder => placeholder_for(options),
129
+ :minlength => options[:minlength],
130
+ :maxlength => options[:maxlength],
114
131
  }
115
132
  end
116
133
 
@@ -131,10 +148,10 @@ module Trenni
131
148
  def submit_attributes_for(options)
132
149
  return {
133
150
  :type => options[:type] || 'submit',
151
+ :name => name_for(options),
134
152
  :id => options[:id],
135
153
  :class => options[:class],
136
154
  :disabled => options[:disabled],
137
- :name => name_for(options),
138
155
  :value => title_for(options),
139
156
  }
140
157
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Trenni
22
22
  module Formatters
23
- VERSION = "0.4.2"
23
+ VERSION = "0.4.3"
24
24
  end
25
25
  end
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
2
  #
5
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -31,21 +29,22 @@ module Trenni::Formatters::FormFormatterSpec
31
29
  end
32
30
 
33
31
  describe Trenni::Formatters do
32
+ let(:formatter) {FormFormatter.new(:object => double(:bar => 10))}
33
+
34
34
  it "should generate form" do
35
- object = double(:bar => 10)
36
-
37
- formatter = FormFormatter.new(:object => object)
38
-
39
35
  output_tag = formatter.input(:field => :bar)
40
36
  expect(output_tag).to be == %Q{<dt>Bar</dt>\n<dd><input name="bar" value="10"/></dd>}
41
37
  end
42
38
 
43
39
  it "should have default value" do
44
- formatter = FormFormatter.new
45
-
46
40
  expect(formatter.value_for(:value => 10)).to be == "10"
47
41
  expect(formatter.value_for(:value => nil, :default => 10)).to be == "10"
48
42
  end
43
+
44
+ it "should have a different title" do
45
+ output_tag = formatter.input(:field => :bar, :title => "Title")
46
+ expect(output_tag).to be == %Q{<dt>Title</dt>\n<dd><input name="bar" value="10"/></dd>}
47
+ end
49
48
  end
50
49
 
51
50
  describe "<input>" do
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
3
1
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
2
  #
5
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -0,0 +1,46 @@
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
+
23
+ module Trenni::Formatters::HTML::OptionSelectSpec
24
+ class FormFormatter < Trenni::Formatters::Formatter
25
+ include Trenni::Formatters::HTML::DefinitionListForm
26
+
27
+ def select(options = {}, &block)
28
+ element(Trenni::Formatters::HTML::OptionSelect, options, &block)
29
+ end
30
+ end
31
+
32
+ describe Trenni::Formatters::HTML::OptionSelect do
33
+ let(:formatter) {FormFormatter.new(:object => double(:bar => 10))}
34
+
35
+ it "should format items" do
36
+ _out = []
37
+
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
+
43
+ expect(_out.join).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>"
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni-formatters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-07 00:00:00.000000000 Z
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni
@@ -90,6 +90,7 @@ files:
90
90
  - lib/trenni/formatters/version.rb
91
91
  - spec/trenni/formatters/form_formatter_spec.rb
92
92
  - spec/trenni/formatters/formatters_spec.rb
93
+ - spec/trenni/formatters/html/option_select_spec.rb
93
94
  - trenni-formatters.gemspec
94
95
  homepage: https://github.com/ioquatix/trenni-formatters
95
96
  licenses: []
@@ -117,3 +118,4 @@ summary: Formatters for Trenni, to assist with typical views and form based inte
117
118
  test_files:
118
119
  - spec/trenni/formatters/form_formatter_spec.rb
119
120
  - spec/trenni/formatters/formatters_spec.rb
121
+ - spec/trenni/formatters/html/option_select_spec.rb