typographer 0.4.1 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/typographer/parsers/basic.rb +44 -48
- data/lib/typographer/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +11 -14
@@ -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
|
18
|
-
string.gsub!(
|
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 \3')
|
39
|
-
string.gsub!(/(^|\s|\()&([A-Za-z0-9]{2,8}|#[\d]*);(\p{Word}{1,2})\s+([^\s])/i, '\1&\2;\3 \4') #entities
|
40
|
-
string.gsub!(/( |¡)(\p{Word}{1,2})\s+([^\s])/i, '\1\2 \3\4')
|
15
|
+
if (RUBY_VERSION > '1.9')
|
16
|
+
string.gsub!(Regexp.new('(\p{Word})\'(\p{Word})'), '\1’\2')
|
41
17
|
else
|
42
18
|
string.gsub!(/(\w)'(\w)/, '\1’\2')
|
19
|
+
end
|
43
20
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#english quotes
|
48
|
-
string = replace_quotes string
|
49
|
-
|
50
|
-
#mdash
|
51
|
-
string.gsub!(/--/, '—')
|
52
|
-
string.gsub!(/(\w|;|,)\s+(—|–|-)\s*(\w)/, '\1 — \3')
|
53
|
-
string.gsub!(/\s+—/, ' —')
|
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, '«', '»', '„', '“', 'а-яА-Я'
|
60
23
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
+
['--', '—'],
|
43
|
+
|
44
|
+
['(\p{Word}|;|,)\s+(—|–|-)\s*(\p{Word})', '\1 — \3'],
|
45
|
+
['\s+—', ' —'],
|
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 \3'],
|
55
|
+
['(^|\s|\()&([A-Za-z0-9]{2,8}|#[\d]*);(\p{Word}{1,2})\s+([^\s])', '\1&\2;\3 \4'], #entities
|
56
|
+
['( |¡)(\p{Word}{1,2})\s+([^\s])', '\1\2 \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 = '“', right1 = '”', left2 = '‘', right2 = '’', letters = 'a-zA-Z')
|
71
67
|
str = string.dup
|
data/lib/typographer/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
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
|
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
|
-
-
|
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.
|
122
|
+
rubygems_version: 1.8.6
|
126
123
|
signing_key:
|
127
124
|
specification_version: 3
|
128
|
-
summary: typographer-0.
|
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
|