formkeeper 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module FormKeeper
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/formkeeper.rb CHANGED
@@ -44,6 +44,17 @@ module FormKeeper
44
44
  end
45
45
  end
46
46
 
47
+ class ToUTF8 < Base
48
+ def initialize(encoding)
49
+ @encoding = encoding
50
+ end
51
+ def process(value)
52
+ value.force_encoding(@encoding)
53
+ return value.encode('UTF-8') if value.valid_encoding?
54
+ value.encode('UTF-16', :invalid => :replace, :undef => :repace, :replace => '').encode('UTF-8')
55
+ end
56
+ end
57
+
47
58
  class UpCase < Base
48
59
  def process(value)
49
60
  return value.upcase
@@ -673,6 +684,10 @@ module FormKeeper
673
684
  @@filter_store[name] = filter
674
685
  end
675
686
 
687
+ def self.register_utf8_encoding_filter(name, encoding)
688
+ @@filter_store[name] = Filter::ToUTF8.new(encoding)
689
+ end
690
+
676
691
  def self.register_constraint(name, constraint)
677
692
  @@constraint_store[name] = constraint
678
693
  end
@@ -686,6 +701,8 @@ module FormKeeper
686
701
  register_filter :upcase, Filter::UpCase.new
687
702
  register_filter :capitalize, Filter::Capitalize.new
688
703
 
704
+ register_utf8_encoding_filter :utf8, 'UTF-8'
705
+
689
706
  register_constraint :ascii, Constraint::Ascii.new
690
707
  register_constraint :ascii_space, Constraint::AsciiSpace.new
691
708
  register_constraint :regexp, Constraint::Regexp.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-24 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helper library for stuff around HTML forms
15
15
  email:
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: 1336204735364772822
73
+ hash: 681882896797215910
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 1336204735364772822
82
+ hash: 681882896797215910
83
83
  requirements: []
84
84
  rubyforge_project:
85
85
  rubygems_version: 1.8.24