typographer 0.4.1 → 0.5

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.
@@ -8,64 +8,60 @@ module TypographerHelper
8
8
 
9
9
  def parse(string)
10
10
  #apostrophe
11
- # Here comes 1.9 compatibility.
12
- # My eyes bleed !!
13
11
 
14
- string= string.gsub(/“/,'„')
12
+ string = string.gsub(/“/,'„')
15
13
  string.gsub!(/”/,'“')
16
14
 
17
- if Regexp.instance_methods.include?(:encoding)
18
- string.gsub!(/(\p{Word})'(\p{Word})/, '\1’\2')
19
-
20
- #russian quotes
21
- string = replace_quotes string, '«', '»', '„', '“', 'а-яА-Я'
22
-
23
- #english quotes
24
- string = replace_quotes string
25
-
26
- #mdash
27
- string.gsub!(/--/, '—')
28
- string.gsub!(/(\p{Word}|;|,)\s+(—|–|-)\s*(\p{Word})/, '\1 — \3')
29
- string.gsub!(/\s+—/, ' —')
30
-
31
- #nobr
32
- #around dash-separated words (что-то)
33
- string.gsub!(/(^|\s)((\p{Word}|0-9){1,3})-((\p{Word}|0-9){1,3})($|\s)/, '\1<span class="nobr">\2-\4</span>\6')
34
- #1980-x почему-то
35
- string.gsub!(/(^|\s)((\p{Word}|0-9)+)-((\p{Word}|0-9){1,3})($|\s)/, '\1<span class="nobr">\2-\4</span>\6')
36
-
37
- #non brake space
38
- string.gsub!(/(^|\s|\()(\p{Word}{1,2})\s+([^\s])/i, '\1\2&nbsp;\3')
39
- string.gsub!(/(^|\s|\()&([A-Za-z0-9]{2,8}|#[\d]*);(\p{Word}{1,2})\s+([^\s])/i, '\1&\2;\3&nbsp;\4') #entities
40
- string.gsub!(/(&nbsp;|&#161;)(\p{Word}{1,2})\s+([^\s])/i, '\1\2&nbsp;\3\4')
15
+ if (RUBY_VERSION > '1.9')
16
+ string.gsub!(Regexp.new('(\p{Word})\'(\p{Word})'), '\1&#146;\2')
41
17
  else
42
18
  string.gsub!(/(\w)'(\w)/, '\1&#146;\2')
19
+ end
43
20
 
44
- #russian quotes
45
- string = replace_quotes string, '&laquo;', '&raquo;', '&#132;', '&#147;', 'а-яА-Я'
46
-
47
- #english quotes
48
- string = replace_quotes string
49
-
50
- #mdash
51
- string.gsub!(/--/, '&mdash;')
52
- string.gsub!(/(\w|;|,)\s+(—|–|-)\s*(\w)/, '\1&nbsp;&mdash; \3')
53
- string.gsub!(/\s+&mdash;/, '&nbsp;&mdash;')
54
-
55
- #nobr
56
- #around dash-separated words (что-то)
57
- string.gsub!(/(^|\s)((\w|0-9){1,3})-((\w|0-9){1,3})($|\s)/, '\1<span class="nobr">\2-\4</span>\6')
58
- #1980-x почему-то
59
- string.gsub!(/(^|\s)((\w|0-9)+)-((\w|0-9){1,3})($|\s)/, '\1<span class="nobr">\2-\4</span>\6')
21
+ #russian quotes
22
+ string = replace_quotes string, '&laquo;', '&raquo;', '&#132;', '&#147;', 'а-яА-Я'
60
23
 
61
- #non brake space
62
- string.gsub!(/(^|\s|\()(\w{1,2})\s+([^\s])/i, '\1\2&nbsp;\3')
63
- string.gsub!(/(^|\s|\()&([A-Za-z0-9]{2,8}|#[\d]*);(\w{1,2})\s+([^\s])/i, '\1&\2;\3&nbsp;\4') #entities
64
- string.gsub!(/(&nbsp;|&#161;)(\w{1,2})\s+([^\s])/i, '\1\2&nbsp;\3\4')
24
+ #english quotes
25
+ string = replace_quotes string
26
+
27
+ replaces.each do |replacement|
28
+ string.gsub!(replacement[0], replacement[1])
65
29
  end
66
-
30
+
67
31
  string
68
32
  end
33
+
34
+ private
35
+
36
+ def replaces
37
+ @@replacements ||= make_replaces
38
+ end
39
+
40
+ def make_replaces
41
+ a = [
42
+ ['--', '&mdash;'],
43
+
44
+ ['(\p{Word}|;|,)\s+(—|–|-)\s*(\p{Word})', '\1&nbsp;&mdash; \3'],
45
+ ['\s+&mdash;', '&nbsp;&mdash;'],
46
+
47
+ #nobr
48
+ #around dash-separated words (что-то)
49
+ ['(^|\s)((\p{Word}|0-9){1,3})-((\p{Word}|0-9){1,3})($|\s)', '\1<span class="nobr">\2-\4</span>\6'],
50
+ #1980-x почему-то
51
+ ['(^|\s)((\p{Word}|0-9)+)-((\p{Word}|0-9){1,3})($|\s)', '\1<span class="nobr">\2-\4</span>\6'],
52
+
53
+ #non brake space
54
+ ['(^|\s|\()(\p{Word}{1,2})\s+([^\s])', '\1\2&nbsp;\3'],
55
+ ['(^|\s|\()&([A-Za-z0-9]{2,8}|#[\d]*);(\p{Word}{1,2})\s+([^\s])', '\1&\2;\3&nbsp;\4'], #entities
56
+ ['(&nbsp;|&#161;)(\p{Word}{1,2})\s+([^\s])', '\1\2&nbsp;\3\4'],
57
+ ]
58
+
59
+ a.collect do |regex, replacement|
60
+ regex = regex.gsub('\p{Word}', '\w') if (RUBY_VERSION < '1.9')
61
+ regex = Regexp.new(regex)
62
+ [regex, replacement]
63
+ end
64
+ end
69
65
 
70
66
  def replace_quotes(string, left1 = '&#147;', right1 = '&#148;', left2 = '&#145;', right2 = '&#146;', letters = 'a-zA-Z')
71
67
  str = string.dup
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module TypographerHelper
3
3
  GEM_NAME = "typographer"
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5"
5
5
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- $KCODE = 'u'
2
+ $KCODE = 'u' unless RUBY_VERSION > '1.9'
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
5
  Bundler.require(:default, :development)
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typographer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
4
+ hash: 1
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
8
+ - 5
9
+ version: "0.5"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Dmitry Shaposhnik
@@ -18,8 +17,7 @@ autorequire:
18
17
  bindir: bin
19
18
  cert_chain: []
20
19
 
21
- date: 2011-07-18 00:00:00 +03:00
22
- default_executable:
20
+ date: 2011-07-18 00:00:00 Z
23
21
  dependencies:
24
22
  - !ruby/object:Gem::Dependency
25
23
  name: actionpack
@@ -79,19 +77,18 @@ extensions: []
79
77
  extra_rdoc_files:
80
78
  - README.rdoc
81
79
  files:
82
- - lib/typographer.rb
83
80
  - lib/typographer/parsers/basic.rb
84
81
  - lib/typographer/parsers/simple_format.rb
85
- - lib/typographer/helper.rb
86
82
  - lib/typographer/version.rb
87
- - spec/typography_spec.rb
83
+ - lib/typographer/helper.rb
84
+ - lib/typographer.rb
88
85
  - spec/spec_helper.rb
86
+ - spec/typography_spec.rb
89
87
  - README.rdoc
90
88
  - Rakefile
91
89
  - Changelog
92
90
  - Gemfile
93
91
  - init.rb
94
- has_rdoc: true
95
92
  homepage: https://github.com/Slotos/typographer
96
93
  licenses: []
97
94
 
@@ -122,10 +119,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
119
  requirements: []
123
120
 
124
121
  rubyforge_project: ""
125
- rubygems_version: 1.3.7
122
+ rubygems_version: 1.8.6
126
123
  signing_key:
127
124
  specification_version: 3
128
- summary: typographer-0.4.1
125
+ summary: typographer-0.5
129
126
  test_files:
130
- - spec/typography_spec.rb
131
127
  - spec/spec_helper.rb
128
+ - spec/typography_spec.rb