rerails 2.3.5.1 → 2.3.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,9 +1,17 @@
1
+ === 2.3.5.2 / 2010-01-02
2
+
3
+ * 1 major enhancement
4
+
5
+ * Add form helpers for HTML5 inputs of type search, tel, url, email, number,
6
+ range.
7
+
8
+
1
9
  === 2.3.5.1 / 2009-12-23
2
10
 
3
11
  * 2 major enhancements
4
12
 
5
13
  * Add Array#first and Array#last limit functionality to
6
14
  ActiveRecord::Base.first and ActiveRecord::Base.last; optimize LIMIT SQL
7
- for "first" and "last" in associations and named scopes.
15
+ for "first" and "last" in association collections and named scopes.
8
16
 
9
17
  * Let label helpers accept blocks.
data/README.rdoc CHANGED
@@ -14,6 +14,19 @@ Reinforcing the Rails with assorted patches.
14
14
  <% end %>
15
15
 
16
16
 
17
+ * HTML5 form helpers.
18
+
19
+ <% form_tag "user_search" do %>
20
+ <%= search_field_tag "user_search", nil, :autosave => true %>
21
+ <% end %>
22
+
23
+ <% form_for @user do |f| %>
24
+ <%= f.email_field :email %>
25
+ <%= f.url_field :homepage %>
26
+ <%= f.phone_field :phone %>
27
+ <% end %>
28
+
29
+
17
30
  === ReactiveRecord
18
31
 
19
32
  * <tt>Array#first</tt> and <tt>Array#last</tt> functionality and
@@ -44,16 +57,16 @@ As a plugin:
44
57
 
45
58
  Setup (to run tests):
46
59
 
47
- [sudo] gem install bundler
48
- gem bundle
49
- bin/rake
60
+ % [sudo] gem install bundler
61
+ % gem bundle
62
+ % bin/rake
50
63
 
51
64
 
52
65
  == License
53
66
 
54
67
  Released under the same license as Ruby on Rails (The MIT License).
55
68
 
56
- (c) 2009 Stephen Celis, stephen@stephencelis.com.
69
+ (c) 2009-2010 Stephen Celis, stephen@stephencelis.com.
57
70
 
58
71
  Permission is hereby granted, free of charge, to any person obtaining a copy
59
72
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,163 @@
1
+ module ActionView #:nodoc:
2
+ module Helpers #:nodoc:
3
+ module FormTagHelper
4
+ # Creates a search field.
5
+ #
6
+ # ==== Options
7
+ # * <tt>:autosave</tt> - If set to true, will generate a domain-based
8
+ # namespace (e.g., for blog.rubyonrails.com, "com.rubyonrails.blog").
9
+ # Also accepts string values.
10
+ # * <tt>:results</tt> - The number of previous searches displayed in the
11
+ # drop-down. Default: 10, with <tt>:autosave</tt>.
12
+ # * Otherwise accepts the same options as text_field_tag.
13
+ #
14
+ # ==== Examples
15
+ # search_field_tag 'query'
16
+ # # => <input id="query" name="query" type="search" />
17
+ #
18
+ # search_field_tag 'query', nil, :autosave => true
19
+ # # => <input id="query" name="query" type="search" autosave="tld.yourdomain" results="10">
20
+ #
21
+ # search_field_tag 'site_search', nil, :autosave => 'com.rubyonrails', :results => 5
22
+ # # => <input id="site_search" name="site_search" type="search" autosave="com.rubyonrails" results="5">
23
+ def search_field_tag(name, value = nil, options = {})
24
+ options = options.stringify_keys
25
+
26
+ if options["autosave"]
27
+ if options["autosave"] == true
28
+ options["autosave"] = request.host.split(".").reverse.join(".")
29
+ end
30
+ options["results"] ||= 10
31
+ end
32
+
33
+ if options["onsearch"]
34
+ options["incremental"] = true unless options.has_key?("incremental")
35
+ end
36
+
37
+ text_field_tag(name, value, options.update("type" => "search"))
38
+ end
39
+
40
+ # Creates a text field of type "tel".
41
+ #
42
+ # ==== Options
43
+ # * Accepts the same options as text_field_tag.
44
+ def telephone_field_tag(name, value = nil, options = {})
45
+ text_field_tag(name, value, options.stringify_keys.update("type" => "tel"))
46
+ end
47
+ alias phone_field_tag telephone_field_tag
48
+
49
+ # Creates a text field of type "url".
50
+ #
51
+ # ==== Options
52
+ # * Accepts the same options as text_field_tag.
53
+ def url_field_tag(name, value = nil, options = {})
54
+ text_field_tag(name, value, options.stringify_keys.update("type" => "url"))
55
+ end
56
+
57
+ # Creates a text field of type "email".
58
+ #
59
+ # ==== Options
60
+ # * Accepts the same options as text_field_tag.
61
+ def email_field_tag(name, value = nil, options = {})
62
+ text_field_tag(name, value, options.stringify_keys.update("type" => "email"))
63
+ end
64
+
65
+ # Creates a number field.
66
+ #
67
+ # ==== Options
68
+ # * <tt>:min</tt> - The minimum acceptable value.
69
+ # * <tt>:max</tt> - The maximum acceptable value.
70
+ # * <tt>:in</tt> - A range specifying the <tt>:min</tt> and
71
+ # <tt>:max</tt> values.
72
+ # * <tt>:step</tt> - The acceptable value granularity.
73
+ # * Otherwise accepts the same options as text_field_tag.
74
+ #
75
+ # ==== Examples
76
+ # number_field_tag 'quantity', nil, :in => 1...10
77
+ # => <input id="quantity" name="quantity" min="1" max="9" />
78
+ def number_field_tag(name, value = nil, options = {})
79
+ options = options.stringify_keys
80
+ options["type"] ||= "number"
81
+ if range = options.delete("in") || options.delete("within")
82
+ options.update("min" => range.min, "max" => range.max)
83
+ end
84
+ text_field_tag(name, value, options)
85
+ end
86
+
87
+ # Creates a range form element.
88
+ #
89
+ # ==== Options
90
+ # * Accepts the same options as number_field_tag.
91
+ def range_field_tag(name, value = nil, options = {})
92
+ number_field_tag(name, value, options.stringify_keys.update("type" => "range"))
93
+ end
94
+ end
95
+
96
+ module FormHelper #:nodoc:
97
+ def search_field(object_name, method, options = {})
98
+ options = options.stringify_keys
99
+
100
+ if options["autosave"]
101
+ if options["autosave"] == true
102
+ options["autosave"] = request.host.split(".").reverse.join(".")
103
+ end
104
+ options["results"] ||= 10
105
+ end
106
+
107
+ if options["onsearch"]
108
+ options["incremental"] = true unless options.has_key?("incremental")
109
+ end
110
+
111
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("search", options)
112
+ end
113
+
114
+ def telephone_field(object_name, method, options = {})
115
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("tel", options)
116
+ end
117
+ alias phone_field telephone_field
118
+
119
+ def url_field(object_name, method, options = {})
120
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("url", options)
121
+ end
122
+
123
+ def email_field(object_name, method, options = {})
124
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("email", options)
125
+ end
126
+
127
+ def number_field(object_name, method, options = {})
128
+ options = options.stringify_keys
129
+ options["type"] ||= "number"
130
+ if range = options.delete("in") || options.delete("within")
131
+ options.update("min" => range.min, "max" => range.max)
132
+ end
133
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("number", options)
134
+ end
135
+
136
+ def range_field(object_name, method, options = {})
137
+ options = options.stringify_keys
138
+ options["type"] ||= "number"
139
+ if range = options.delete("in") || options.delete("within")
140
+ options.update("min" => range.min, "max" => range.max)
141
+ end
142
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("range", options)
143
+ end
144
+ end
145
+
146
+ class FormBuilder #:nodoc:
147
+ %w(search_field telephone_field url_field email_field number_field range_field).each do |selector|
148
+ src = <<-end_src
149
+ def #{selector}(method, options = {})
150
+ @template.send(
151
+ #{selector.inspect},
152
+ @object_name,
153
+ method,
154
+ objectify_options(options))
155
+ end
156
+ end_src
157
+ class_eval src, __FILE__, __LINE__
158
+ end
159
+
160
+ alias phone_field telephone_field
161
+ end
162
+ end
163
+ end
data/lib/reaction_view.rb CHANGED
@@ -1 +1,2 @@
1
1
  require "reaction_view/block_labels"
2
+ require "reaction_view/html5_forms"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rerails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.5.1
4
+ version: 2.3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Celis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-23 00:00:00 -05:00
12
+ date: 2010-01-02 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,6 +35,7 @@ files:
35
35
  - CHANGELOG.rdoc
36
36
  - README.rdoc
37
37
  - lib/reaction_view/block_labels.rb
38
+ - lib/reaction_view/html5_forms.rb
38
39
  - lib/reaction_view.rb
39
40
  - lib/reactive_record/first_last_limits.rb
40
41
  - lib/reactive_record.rb