als_typograf 0.1.1 → 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/als_typograf.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{als_typograf}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Semyonov"]
12
- s.date = %q{2010-02-07}
12
+ s.date = %q{2010-09-13}
13
13
  s.description = %q{ruby-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)}
14
14
  s.email = %q{rotuka@rotuka.com}
15
15
  s.extra_rdoc_files = [
@@ -24,8 +24,8 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "als_typograf.gemspec",
27
+ "lib/active_model/typograf.rb",
27
28
  "lib/als_typograf.rb",
28
- "lib/als_typograf/active_record.rb",
29
29
  "lib/als_typograf/request.rb",
30
30
  "rails/init.rb",
31
31
  "test/database.yml",
@@ -37,20 +37,20 @@ Gem::Specification.new do |s|
37
37
  s.homepage = %q{http://github.com/rotuka/als_typograf}
38
38
  s.rdoc_options = ["--charset=UTF-8"]
39
39
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.5}
40
+ s.rubygems_version = %q{1.3.7}
41
41
  s.summary = %q{ArtLebedevStudio.RemoteTypograf}
42
42
  s.test_files = [
43
- "test/helper.rb",
44
- "test/schema.rb",
45
- "test/unit/als_typograf_test.rb",
46
- "test/unit/article_test.rb"
43
+ "test/schema.rb",
44
+ "test/helper.rb",
45
+ "test/unit/article_test.rb",
46
+ "test/unit/als_typograf_test.rb"
47
47
  ]
48
48
 
49
49
  if s.respond_to? :specification_version then
50
50
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
51
  s.specification_version = 3
52
52
 
53
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
54
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
55
55
  s.add_development_dependency(%q<shoulda>, [">= 0"])
56
56
  s.add_development_dependency(%q<yard>, [">= 0"])
@@ -0,0 +1,57 @@
1
+ module ActiveModel
2
+ module Typograf
3
+ module InstanceMethods
4
+ # Run AlsTypograf#process on configured columns.
5
+ # Used to run as before_validation filter (automaticaly added on ActiveRecord::Base.typograf)
6
+ def typograf_current_fields
7
+ self.class.typograf_fields.each do |column, options|
8
+ if send(:"#{column}?") && send(:"#{column}_changed?")
9
+ send(:"#{column}=", AlsTypograf.process(send(column).to_s, options))
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ # Specify columns to typograf
16
+ # @overload typograf(column_name, options)
17
+ # Typograf only specified column with specified or default options
18
+ # @example typograf column with default options
19
+ # typograf :content # will typograf +content+ with default AlsTypograf options
20
+ # @example typograf column with custom options
21
+ # typograf :title, :use_br => false # will typograf +title+ without replacing +\n+ with <br />
22
+ # @param [String, Symbol] column_name name of the column to typograf
23
+ # @param [Hash] options custom options to AlsTypograf#process method
24
+ # @overload typograf(column1, column2, ..., options)
25
+ # Typograf every specified columns with default options
26
+ # @example typograf columns with common custom options
27
+ # typograf :skills, :achievements, :description, :encoding => 'CP1251'
28
+ # @param [String, Symbol] column1 first column name
29
+ # @param [String, Symbol] column2 next column name
30
+ # @param [String, Symbol] ... specify all columns, you need
31
+ # @param [Hash] options options to AlsTypograf#process method for all specified fields
32
+ # @overload typograf(columns_with_options)
33
+ # Typograf specified columns with specified options
34
+ # @example typograf specified columns with specified options
35
+ # typograf :foo => {:use_br => false}, :bar => {:use_p => false}
36
+ # @param [Hash] columns_with_options column names with correspond options to AlsTypograf#process method
37
+ def typograf(*columns)
38
+ unless respond_to?(:typograf_fields)
39
+ cattr_accessor :typograf_fields
40
+ self.typograf_fields = {}
41
+ before_validation :typograf_current_fields
42
+ include InstanceMethods
43
+ end
44
+
45
+ common_options = columns.extract_options!
46
+ if columns == [] # There was an columns_with_options variant
47
+ common_options.each do |column, custom_options|
48
+ typograf_fields[column.to_sym] = custom_options
49
+ end
50
+ else
51
+ columns.each do |column|
52
+ typograf_fields[column.to_sym] = common_options
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/als_typograf.rb CHANGED
@@ -105,6 +105,12 @@ module AlsTypograf
105
105
  end
106
106
  end
107
107
 
108
- if defined? ActiveRecord
109
- require 'als_typograf/active_record'
108
+ if defined? ActiveModel
109
+ require 'active_model/typograf'
110
+
111
+ if defined? ActiveRecord
112
+ class ActiveRecord::Base
113
+ extend ActiveModel::Typograf
114
+ end
115
+ end
110
116
  end
data/test/helper.rb CHANGED
@@ -7,6 +7,7 @@ require 'shoulda'
7
7
  require 'redgreen' rescue nil
8
8
  require 'als_typograf'
9
9
  require 'active_support/test_case'
10
+ require 'logger'
10
11
 
11
12
  class ActiveSupport::TestCase
12
13
  def self.process_assertions(assertions)
@@ -13,8 +13,14 @@ end
13
13
  class ArticleTest < ActiveSupport::TestCase
14
14
  extend Shoulda::ActiveRecord::Macros
15
15
 
16
- should_have_class_methods :typograf
17
- should_have_instance_methods :typograf_fields, :typograf_current_fields
16
+ should "have class method #typograf" do
17
+ assert Article.respond_to?(:typograf)
18
+ end
19
+ %w(typograf_fields typograf_current_fields).each do |field|
20
+ should "have instance method \##{field}" do
21
+ assert Article.instance_methods.include?(field)
22
+ end
23
+ end
18
24
 
19
25
  should 'load schema correctly' do
20
26
  assert_equal [], Article.all
@@ -32,7 +38,7 @@ class ArticleTest < ActiveSupport::TestCase
32
38
  end
33
39
 
34
40
  should 'typograf article’s title with custom options' do
35
- assert_equal "— Does it Article”?", @article.title
41
+ assert_equal "— Does it «Article»?", @article.title
36
42
  end
37
43
  end
38
44
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: als_typograf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Alexander Semyonov
@@ -9,39 +15,53 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-07 00:00:00 +03:00
18
+ date: 2010-09-13 00:00:00 +04:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 11
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 4
23
34
  version: 2.3.4
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: shoulda
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
33
48
  version: "0"
34
- version:
49
+ type: :development
50
+ version_requirements: *id002
35
51
  - !ruby/object:Gem::Dependency
36
52
  name: yard
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
40
56
  requirements:
41
57
  - - ">="
42
58
  - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
43
62
  version: "0"
44
- version:
63
+ type: :development
64
+ version_requirements: *id003
45
65
  description: ruby-implementation of ArtLebedevStudio.RemoteTypograf class (web-service client)
46
66
  email: rotuka@rotuka.com
47
67
  executables: []
@@ -59,8 +79,8 @@ files:
59
79
  - Rakefile
60
80
  - VERSION
61
81
  - als_typograf.gemspec
82
+ - lib/active_model/typograf.rb
62
83
  - lib/als_typograf.rb
63
- - lib/als_typograf/active_record.rb
64
84
  - lib/als_typograf/request.rb
65
85
  - rails/init.rb
66
86
  - test/database.yml
@@ -78,26 +98,32 @@ rdoc_options:
78
98
  require_paths:
79
99
  - lib
80
100
  required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
81
102
  requirements:
82
103
  - - ">="
83
104
  - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
84
108
  version: "0"
85
- version:
86
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
87
111
  requirements:
88
112
  - - ">="
89
113
  - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
90
117
  version: "0"
91
- version:
92
118
  requirements: []
93
119
 
94
120
  rubyforge_project:
95
- rubygems_version: 1.3.5
121
+ rubygems_version: 1.3.7
96
122
  signing_key:
97
123
  specification_version: 3
98
124
  summary: ArtLebedevStudio.RemoteTypograf
99
125
  test_files:
100
- - test/helper.rb
101
126
  - test/schema.rb
102
- - test/unit/als_typograf_test.rb
127
+ - test/helper.rb
103
128
  - test/unit/article_test.rb
129
+ - test/unit/als_typograf_test.rb
@@ -1,57 +0,0 @@
1
- module AlsTypograf
2
- module ActiveRecord
3
- # Run AlsTypograf#process on configured columns.
4
- # Used to run as before_validation filter (automaticaly added on ActiveRecord::Base.typograf)
5
- def typograf_current_fields
6
- self.class.typograf_fields.each do |column, options|
7
- send(:"#{column}=",
8
- AlsTypograf.process(send(column).to_s,
9
- options)) if send(:"#{column}?") && send(:"#{column}_changed?")
10
- end
11
- end
12
- end
13
- end
14
-
15
- class ActiveRecord::Base
16
- # Specify columns to typograf
17
- # @overload typograf(column_name, options)
18
- # Typograf only specified column with specified or default options
19
- # @example typograf column with default options
20
- # typograf :content # will typograf +content+ with default AlsTypograf options
21
- # @example typograf column with custom options
22
- # typograf :title, :use_br => false # will typograf +title+ without replacing +\n+ with <br />
23
- # @param [String, Symbol] column_name name of the column to typograf
24
- # @param [Hash] options custom options to AlsTypograf#process method
25
- # @overload typograf(column1, column2, ..., options)
26
- # Typograf every specified columns with default options
27
- # @example typograf columns with common custom options
28
- # typograf :skills, :achievements, :description, :encoding => 'CP1251'
29
- # @param [String, Symbol] column1 first column name
30
- # @param [String, Symbol] column2 next column name
31
- # @param [String, Symbol] ... specify all columns, you need
32
- # @param [Hash] options options to AlsTypograf#process method for all specified fields
33
- # @overload typograf(columns_with_options)
34
- # Typograf specified columns with specified options
35
- # @example typograf specified columns with specified options
36
- # typograf :foo => {:use_br => false}, :bar => {:use_p => false}
37
- # @param [Hash] columns_with_options column names with correspond options to AlsTypograf#process method
38
- def self.typograf(*columns)
39
- unless respond_to?(:typograf_fields)
40
- cattr_accessor :typograf_fields
41
- self.typograf_fields = {}
42
- before_validation :typograf_current_fields
43
- include AlsTypograf::ActiveRecord
44
- end
45
-
46
- common_options = columns.extract_options!
47
- if columns == [] # There was an columns_with_options variant
48
- common_options.each do |column, custom_options|
49
- typograf_fields[column.to_sym] = custom_options
50
- end
51
- else
52
- columns.each do |column|
53
- typograf_fields[column.to_sym] = common_options
54
- end
55
- end
56
- end
57
- end