delocalize 0.1.6 → 0.2.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.
- data/README.markdown +29 -8
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/lib/delocalize/rails_ext/active_record.rb +11 -9
- data/test/delocalize_test.rb +2 -2
- data/test/test_helper.rb +1 -2
- metadata +4 -4
data/README.markdown
CHANGED
@@ -4,10 +4,22 @@ delocalize
|
|
4
4
|
delocalize provides localized date/time and number parsing functionality for Rails.
|
5
5
|
|
6
6
|
Installation
|
7
|
-
|
7
|
+
------------
|
8
8
|
|
9
9
|
You can use delocalize either as a gem (preferred) or as a Rails plugin.
|
10
10
|
|
11
|
+
### Rails 3
|
12
|
+
|
13
|
+
To use the gem version, put the following gem requirement in your `Gemfile`:
|
14
|
+
|
15
|
+
gem "delocalize", :source => 'http://gemcutter.org'
|
16
|
+
|
17
|
+
To install it as a plugin, fire up your terminal, go to your Rails app and type:
|
18
|
+
|
19
|
+
$ ruby rails plugin install git://github.com/clemens/delocalize.git
|
20
|
+
|
21
|
+
### Rails 2
|
22
|
+
|
11
23
|
To use the gem version, put the following gem requirement in your `environment.rb`:
|
12
24
|
|
13
25
|
config.gem "delocalize", :source => 'http://gemcutter.org'
|
@@ -18,7 +30,7 @@ To install it as a plugin, fire up your terminal, go to your Rails app and type:
|
|
18
30
|
|
19
31
|
|
20
32
|
What does it do? And how do I use it?
|
21
|
-
|
33
|
+
--------------------------------------
|
22
34
|
|
23
35
|
Delocalize, just as the name suggest, does pretty much the opposite of localize.
|
24
36
|
|
@@ -96,20 +108,29 @@ You can also customize the output using some options:
|
|
96
108
|
Since `I18n.localize` supports localizing `strftime` strings, we can also do this:
|
97
109
|
<%= f.text_field :released_on, :format => "%B %Y" %>
|
98
110
|
|
99
|
-
###
|
111
|
+
### Compatibility
|
112
|
+
|
113
|
+
* Tested with Rails 2.3.5 in Ruby 1.8.7, Ruby 1.9.1 and Ruby 1.9.2 (head)
|
114
|
+
* Tested with Rails 3 Beta 3 in Ruby 1.9.2 (head)
|
115
|
+
|
116
|
+
### Contributors
|
117
|
+
|
118
|
+
People who have contributed to delocalize (in no particular order):
|
100
119
|
|
101
|
-
|
102
|
-
|
120
|
+
* [Fernando Luizao](http://github.com/fernandoluizao)
|
121
|
+
* [Stephan](http://github.com/stepahn)
|
122
|
+
* [Lailson Bandeira](http://github.com/lailsonbm)
|
123
|
+
* [Carlos Antonio da Silva](http://github.com/carlosantoniodasilva)
|
124
|
+
* [Michele Franzin](http://github.com/michelefranzin)
|
103
125
|
|
104
126
|
### TODO
|
105
127
|
|
106
128
|
* Improve test coverage
|
107
129
|
* Separate Ruby/Rails stuff to make it usable outside Rails
|
108
|
-
* Verify correct behavior with time zones
|
109
130
|
* Decide on other ActionView hacks (e.g. `text_field_tag`)
|
110
131
|
* Implement AM/PM support
|
111
132
|
* Cleanup, cleanup, cleanup ...
|
112
133
|
|
113
|
-
Copyright (c) 2009-2010 Clemens Kofler
|
114
|
-
http://www.railway.at
|
134
|
+
Copyright (c) 2009-2010 Clemens Kofler <clemens@railway.at>
|
135
|
+
<http://www.railway.at/>
|
115
136
|
Released under the MIT license
|
data/Rakefile
CHANGED
@@ -2,9 +2,9 @@ require 'rake'
|
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
|
5
|
-
require 'tasks/distribution'
|
6
|
-
require 'tasks/documentation'
|
7
|
-
require 'tasks/testing'
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'tasks/distribution'))
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'tasks/documentation'))
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'tasks/testing'))
|
8
8
|
|
9
9
|
desc 'Default: run unit tests.'
|
10
10
|
task :default => :test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract/schema_definitions'
|
2
|
+
|
1
3
|
# let's hack into ActiveRecord a bit - everything at the lowest possible level, of course, so we minimalize side effects
|
2
4
|
ActiveRecord::ConnectionAdapters::Column.class_eval do
|
3
5
|
def date?
|
@@ -36,8 +38,15 @@ ActiveRecord::Base.class_eval do
|
|
36
38
|
evaluate_attribute_method attr_name, method_body, "#{attr_name}="
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
def convert_number_column_value_with_localization(value)
|
42
|
+
value = convert_number_column_value_without_localization(value)
|
43
|
+
value = Numeric.parse_localized(value) if I18n.delocalization_enabled?
|
44
|
+
value
|
45
|
+
end
|
46
|
+
alias_method_chain :convert_number_column_value, :localization
|
47
|
+
end
|
48
|
+
|
49
|
+
ActiveRecord::Dirty.module_eval do
|
41
50
|
def field_changed?(attr, old, value)
|
42
51
|
if column = column_for_attribute(attr)
|
43
52
|
if column.number? && column.null && (old.nil? || old == 0) && value.blank?
|
@@ -53,11 +62,4 @@ ActiveRecord::Base.class_eval do
|
|
53
62
|
|
54
63
|
old != value
|
55
64
|
end
|
56
|
-
|
57
|
-
def convert_number_column_value_with_localization(value)
|
58
|
-
value = convert_number_column_value_without_localization(value)
|
59
|
-
value = Numeric.parse_localized(value) if I18n.delocalization_enabled?
|
60
|
-
value
|
61
|
-
end
|
62
|
-
alias_method_chain :convert_number_column_value, :localization
|
63
65
|
end
|
data/test/delocalize_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.dirname(__FILE__)
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
4
4
|
|
5
5
|
class DelocalizeActiveRecordTest < ActiveRecord::TestCase
|
6
6
|
def setup
|
@@ -230,7 +230,7 @@ class DelocalizeActionViewTest < ActionView::TestCase
|
|
230
230
|
text_field(:product, :price, :value => "1.499,90")
|
231
231
|
end
|
232
232
|
|
233
|
-
test "
|
233
|
+
test "doesn't convert the value if field has errors" do
|
234
234
|
@product = ProductWithValidation.new(:price => 'this is not a number')
|
235
235
|
@product.valid?
|
236
236
|
assert_dom_equal '<div class="fieldWithErrors"><input id="product_price" name="product[price]" size="30" type="text" value="this is not a number" /></div>',
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
ENV["RAILS_ENV"] = "test"
|
4
|
-
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/rails_app/config/environment")
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'rails_app/config/environment'))
|
6
5
|
require 'test_help'
|
7
6
|
|
8
7
|
require 'rubygems'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Clemens Kofler
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|