dumb_quotes 1.2 → 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.rdoc CHANGED
@@ -32,19 +32,14 @@ the following changes to your model attributes before validation:
32
32
 
33
33
  === Installation
34
34
 
35
- 1. On rails 2.3
35
+ Option 1. Load the plugin as a gem
36
36
 
37
- * gem install strip_control_chars
38
- * add the following to your environment.rb
37
+ gem install dumb_quotes
38
+ add "config.gem 'dumb_quotes'" to your environment.rb
39
39
 
40
- config.gem 'dumb_quotes', version => < 2.0"
40
+ Option 2. Use the standard Rails plugin install (assuming Rails 2.1).
41
41
 
42
- 2. On rails 3
43
-
44
- * gem install strip_control_chars
45
- * add the following to your Gemfile
46
-
47
- gem 'dumb_quotes', ">=2.0"
42
+ ./script/plugin install git://github.com/yob/dumb_quotes.git
48
43
 
49
44
  === Caveats
50
45
 
data/lib/dumb_quotes.rb CHANGED
@@ -1,43 +1,2 @@
1
- # coding: utf-8
2
-
3
- module DumbQuotes
4
- # Strips whitespace from model fields and converts blank values to nil.
5
- def dumb_quotes!(options = nil)
6
- before_validation do |record|
7
- attributes = DumbQuotes.narrow(record.attributes, options)
8
- attributes.each do |attr, value|
9
- if value.respond_to?(:gsub)
10
- # single quotes
11
- value = value.gsub("\xE2\x80\x98","'") # U+2018
12
- value = value.gsub("\xE2\x80\x99","'") # U+2019
13
- value = value.gsub("\xCA\xBC","'") # U+02BC
14
-
15
- # double quotes
16
- value = value.gsub("\xE2\x80\x9C",'"') # U+201C
17
- value = value.gsub("\xE2\x80\x9D",'"') # U+201D
18
- value = value.gsub("\xCB\xAE",'"') # U+02EE
19
-
20
- record[attr] = value
21
- end
22
- end
23
- end
24
- end
25
-
26
- # Necessary because Rails has removed the narrowing of attributes using :only
27
- # and :except on Base#attributes
28
- def self.narrow(attributes, options)
29
- if options.nil?
30
- attributes
31
- else
32
- if except = options[:except]
33
- except = Array(except).collect { |attribute| attribute.to_s }
34
- attributes.except(*except)
35
- elsif only = options[:only]
36
- only = Array(only).collect { |attribute| attribute.to_s }
37
- attributes.slice(*only)
38
- else
39
- raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"
40
- end
41
- end
42
- end
43
- end
1
+ require 'dumb_quotes/ar_extend'
2
+ require 'dumb_quotes/railtie'
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ module DumbQuotes
4
+ module ArExtend
5
+ # Strips whitespace from model fields and converts blank values to nil.
6
+ def dumb_quotes!(options = nil)
7
+ before_validation do |record|
8
+ attributes = DumbQuotes::ArExtend.narrow(record.attributes, options)
9
+ attributes.each do |attr, value|
10
+ if value.respond_to?(:gsub)
11
+ # single quotes
12
+ value = value.gsub("\xE2\x80\x98","'") # U+2018
13
+ value = value.gsub("\xE2\x80\x99","'") # U+2019
14
+ value = value.gsub("\xCA\xBC","'") # U+02BC
15
+
16
+ # double quotes
17
+ value = value.gsub("\xE2\x80\x9C",'"') # U+201C
18
+ value = value.gsub("\xE2\x80\x9D",'"') # U+201D
19
+ value = value.gsub("\xCB\xAE",'"') # U+02EE
20
+
21
+ record[attr] = value
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ # Necessary because Rails has removed the narrowing of attributes using :only
28
+ # and :except on Base#attributes
29
+ def self.narrow(attributes, options)
30
+ if options.nil?
31
+ attributes
32
+ else
33
+ if except = options[:except]
34
+ except = Array(except).collect { |attribute| attribute.to_s }
35
+ attributes.except(*except)
36
+ elsif only = options[:only]
37
+ only = Array(only).collect { |attribute| attribute.to_s }
38
+ attributes.slice(*only)
39
+ else
40
+ raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require 'dumb_quotes'
2
+ require 'rails'
3
+
4
+ module DumbQuotes
5
+ class Railtie < Rails::Railtie
6
+
7
+ initializer "dumb_quotes.active_record" do |app|
8
+ if defined?(::ActiveRecord)
9
+ ::ActiveRecord::Base.extend(DumbQuotes::ArExtend)
10
+
11
+ end
12
+ end
13
+
14
+ end
15
+ end
data/test/test_helper.rb CHANGED
@@ -5,9 +5,11 @@ require 'active_record'
5
5
  PLUGIN_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
6
6
 
7
7
  $LOAD_PATH.unshift "#{PLUGIN_ROOT}/lib"
8
- require "#{PLUGIN_ROOT}/init"
8
+ require 'dumb_quotes'
9
9
 
10
10
  class ActiveRecord::Base
11
+ extend DumbQuotes::ArExtend
12
+
11
13
  alias_method :save, :valid?
12
14
  def self.columns()
13
15
  @columns ||= []
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumb_quotes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
- - 1
8
7
  - 2
9
- version: "1.2"
8
+ - 0
9
+ version: "2.0"
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Healy
@@ -23,13 +23,15 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - <=
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 197
28
+ hash: 7712042
29
29
  segments:
30
- - 2
31
- - 99
32
- version: "2.99"
30
+ - 3
31
+ - 0
32
+ - 0
33
+ - rc
34
+ version: 3.0.0.rc
33
35
  type: :runtime
34
36
  version_requirements: *id001
35
37
  description: a small ActiveRecord plugin that converts 'smart quotes' to their ASCII equivalents
@@ -41,16 +43,16 @@ extensions: []
41
43
  extra_rdoc_files: []
42
44
 
43
45
  files:
44
- - init.rb
45
- - rails/init.rb
46
46
  - lib/dumb_quotes.rb
47
+ - lib/dumb_quotes/ar_extend.rb
48
+ - lib/dumb_quotes/railtie.rb
47
49
  - Rakefile
48
50
  - MIT-LICENSE
49
51
  - README.rdoc
50
52
  - test/dumb_quotes_test.rb
51
53
  - test/test_helper.rb
52
54
  has_rdoc: true
53
- homepage: http://github.com/yob/dumb_quotes/tree/master
55
+ homepage: http://github.com/yob/dumb_quotes
54
56
  licenses: []
55
57
 
56
58
  post_install_message:
@@ -80,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  version: "0"
81
83
  requirements: []
82
84
 
83
- rubyforge_project: yob-projects
85
+ rubyforge_project:
84
86
  rubygems_version: 1.3.7
85
87
  signing_key:
86
88
  specification_version: 3
data/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'dumb_quotes'
2
- ActiveRecord::Base.extend(DumbQuotes)
data/rails/init.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'dumb_quotes'
2
- ActiveRecord::Base.extend(DumbQuotes)