improve_typography 0.1.14 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/improve_typography.gemspec +2 -2
- data/lib/config/locales/da.yml +2 -0
- data/lib/improve_typography/base.rb +16 -8
- data/lib/improve_typography/processor.rb +17 -2
- data/lib/improve_typography/processors/apostrophe.rb +2 -1
- data/lib/improve_typography/processors/double_quotes.rb +2 -1
- data/lib/improve_typography/processors/ellipsis.rb +2 -2
- data/lib/improve_typography/processors/em_dash.rb +2 -1
- data/lib/improve_typography/processors/en_dash.rb +2 -1
- data/lib/improve_typography/processors/multiply_sign.rb +2 -2
- data/lib/improve_typography/processors/single_quotes.rb +4 -3
- data/lib/improve_typography/version.rb +1 -1
- data/lib/improve_typography.rb +19 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1b2c092429e7061298051978b7e283e506720e521f9e56a20f31b599194df39
|
4
|
+
data.tar.gz: 02c3b65a7e6c7c7ab0ef36fd3772e83aa23fd6dbea1755db361466ea858b4dc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43da94383330d521447b7d7be4560c3f539a2718d8e853ee05edeb3a26a2b08e78239f67030b85aee101a8bdaf000edf7bfe4f10a4b8e3014b6afb94e5dfc58d
|
7
|
+
data.tar.gz: d9521e056f4867743541d1a40b3614aba9149ba59c7707ed5fd80a5b0a53a2aaf2765ce92545a8b570d97ae0fedcfafd3c80328c67112807bc588bba50b9b593
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.1.17
|
4
|
+
|
5
|
+
* fix single quote capturing apostrophes (@asgerb)
|
6
|
+
|
7
|
+
## 0.1.16
|
8
|
+
|
9
|
+
* guard for missing `i18n` translations (@asgerb)
|
10
|
+
* refactor inheritance logic (@asgerb)
|
11
|
+
|
12
|
+
## 0.1.15
|
13
|
+
|
14
|
+
* fix the `ImproveTypography.configure` method
|
15
|
+
|
3
16
|
## 0.1.14
|
4
17
|
|
5
18
|
* first run simplest `match?` before `gsub` to make sure the replacement is actually needed
|
data/README.md
CHANGED
data/improve_typography.gemspec
CHANGED
@@ -24,9 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency 'i18n'
|
25
25
|
spec.add_dependency 'nokogiri'
|
26
26
|
|
27
|
-
spec.add_development_dependency 'bundler'
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
28
|
spec.add_development_dependency 'guard'
|
29
29
|
spec.add_development_dependency 'guard-minitest'
|
30
30
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
31
|
-
spec.add_development_dependency 'rake', '~>
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
32
32
|
end
|
@@ -2,8 +2,20 @@ require 'nokogiri'
|
|
2
2
|
|
3
3
|
module ImproveTypography
|
4
4
|
class Base < Struct.new(:str, :options)
|
5
|
-
|
6
|
-
|
5
|
+
class << self
|
6
|
+
def all_processor_classes
|
7
|
+
@@all_processor_classes ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_processor_class(klass)
|
11
|
+
unless all_processor_classes.include?(klass)
|
12
|
+
all_processor_classes << klass
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(*args)
|
17
|
+
new(*args).call
|
18
|
+
end
|
7
19
|
end
|
8
20
|
|
9
21
|
def initialize(str, options = {})
|
@@ -30,12 +42,8 @@ module ImproveTypography
|
|
30
42
|
@doc ||= Nokogiri::HTML::DocumentFragment.parse("<div>#{str}</div>")
|
31
43
|
end
|
32
44
|
|
33
|
-
def configuration
|
34
|
-
@configuration ||= Configuration.new
|
35
|
-
end
|
36
|
-
|
37
45
|
def processors
|
38
|
-
options.fetch(:processors, configuration.processors)
|
46
|
+
options.fetch(:processors, ImproveTypography.configuration.processors)
|
39
47
|
end
|
40
48
|
|
41
49
|
def processor_classes
|
@@ -45,7 +53,7 @@ module ImproveTypography
|
|
45
53
|
end
|
46
54
|
|
47
55
|
def all_processor_classes
|
48
|
-
|
56
|
+
self.class.all_processor_classes
|
49
57
|
end
|
50
58
|
|
51
59
|
def processor_for_locale(klass)
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module ImproveTypography
|
2
2
|
class Processor < Struct.new(:str, :options)
|
3
|
-
|
4
|
-
|
3
|
+
class << self
|
4
|
+
def call(*args)
|
5
|
+
new(*args).call
|
6
|
+
end
|
7
|
+
|
8
|
+
def inherited(klass)
|
9
|
+
ImproveTypography::Base.add_processor_class(klass)
|
10
|
+
super
|
11
|
+
end
|
5
12
|
end
|
6
13
|
|
7
14
|
def initialize(str, options = {})
|
@@ -14,6 +21,14 @@ module ImproveTypography
|
|
14
21
|
|
15
22
|
private
|
16
23
|
|
24
|
+
def translation(key)
|
25
|
+
I18n.t(key, scope: %i(improve_typography), locale: locale)
|
26
|
+
end
|
27
|
+
|
28
|
+
def sign_exists?(sign)
|
29
|
+
!sign.nil? && !sign.match?(/translation missing/)
|
30
|
+
end
|
31
|
+
|
17
32
|
def configuration
|
18
33
|
@configuration ||= Configuration.new
|
19
34
|
end
|
@@ -4,6 +4,7 @@ module ImproveTypography
|
|
4
4
|
REGEXP = /(\w+)'(\w*)/i
|
5
5
|
|
6
6
|
def call
|
7
|
+
return str unless sign_exists?(apostrophe_sign)
|
7
8
|
return str unless str.match?(/'/)
|
8
9
|
replace_apostrophe
|
9
10
|
end
|
@@ -15,7 +16,7 @@ module ImproveTypography
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def apostrophe_sign
|
18
|
-
options.fetch(:apostrophe_sign,
|
19
|
+
options.fetch(:apostrophe_sign, translation(:apostrophe_sign))
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -2,6 +2,7 @@ module ImproveTypography
|
|
2
2
|
module Processors
|
3
3
|
class DoubleQuotes < Processor
|
4
4
|
def call
|
5
|
+
return str unless sign_exists?(double_quotes)
|
5
6
|
return str unless str.match?(/[\"#{double_quotes[0]}#{double_quotes[1]}]/)
|
6
7
|
replace_double_quotes
|
7
8
|
end
|
@@ -17,7 +18,7 @@ module ImproveTypography
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def double_quotes
|
20
|
-
options.fetch(:double_quotes,
|
21
|
+
options.fetch(:double_quotes, translation(:double_quotes))
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -4,7 +4,7 @@ module ImproveTypography
|
|
4
4
|
REGEXP = /(\.\s*?){3,}/i
|
5
5
|
|
6
6
|
def call
|
7
|
-
return str unless ellipsis_sign
|
7
|
+
return str unless sign_exists?(ellipsis_sign)
|
8
8
|
return str unless str.match?(REGEXP)
|
9
9
|
|
10
10
|
str.gsub(REGEXP, ellipsis_sign)
|
@@ -13,7 +13,7 @@ module ImproveTypography
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def ellipsis_sign
|
16
|
-
options.fetch(:ellipsis_sign,
|
16
|
+
options.fetch(:ellipsis_sign, translation(:ellipsis_sign))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -4,6 +4,7 @@ module ImproveTypography
|
|
4
4
|
REGEXP = /(\w+?)\s+-{1,3}\s+(\w+?)/i
|
5
5
|
|
6
6
|
def call
|
7
|
+
return str unless sign_exists?(em_dash_sign)
|
7
8
|
return str unless str.match?(/-{1,3}/)
|
8
9
|
str.gsub(REGEXP, '\1'+em_dash_sign+'\2')
|
9
10
|
end
|
@@ -11,7 +12,7 @@ module ImproveTypography
|
|
11
12
|
private
|
12
13
|
|
13
14
|
def em_dash_sign
|
14
|
-
options.fetch(:em_dash_sign,
|
15
|
+
options.fetch(:em_dash_sign, translation(:em_dash_sign))
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -4,6 +4,7 @@ module ImproveTypography
|
|
4
4
|
REGEXP = /(\w+?)\s+-{1,2}\s+(\w+?)/i
|
5
5
|
|
6
6
|
def call
|
7
|
+
return str unless sign_exists?(en_dash_sign)
|
7
8
|
return str unless str.match?(/-{1,3}/)
|
8
9
|
str.gsub(REGEXP, '\1'+en_dash_sign+'\2')
|
9
10
|
end
|
@@ -11,7 +12,7 @@ module ImproveTypography
|
|
11
12
|
private
|
12
13
|
|
13
14
|
def en_dash_sign
|
14
|
-
options.fetch(:en_dash_sign,
|
15
|
+
options.fetch(:en_dash_sign, translation(:en_dash_sign))
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -4,7 +4,7 @@ module ImproveTypography
|
|
4
4
|
REGEXP = /(\d+|[½⅓¼⅔⅛⅜⅝⅞])(\s*)x(\s*)(\d+|[½⅓¼⅔⅛⅜⅝⅞])/i
|
5
5
|
|
6
6
|
def call
|
7
|
-
return str unless multiply_sign
|
7
|
+
return str unless sign_exists?(multiply_sign)
|
8
8
|
return str unless str.match?(REGEXP)
|
9
9
|
|
10
10
|
str.gsub(REGEXP, '\1'+multiply_sign+'\4')
|
@@ -13,7 +13,7 @@ module ImproveTypography
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def multiply_sign
|
16
|
-
options.fetch(:multiply_sign,
|
16
|
+
options.fetch(:multiply_sign, translation(:multiply_sign))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -2,7 +2,8 @@ module ImproveTypography
|
|
2
2
|
module Processors
|
3
3
|
class SingleQuotes < Processor
|
4
4
|
def call
|
5
|
-
return str unless
|
5
|
+
return str unless sign_exists?(single_quotes)
|
6
|
+
return str unless str.match?(regexp)
|
6
7
|
replace_single_quotes
|
7
8
|
end
|
8
9
|
|
@@ -13,11 +14,11 @@ module ImproveTypography
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def regexp
|
16
|
-
@regexp ||= Regexp.new("['#{single_quotes[0]}#{single_quotes[1]}](.*?)['#{single_quotes[0]}#{single_quotes[1]}](?!\\w)")
|
17
|
+
@regexp ||= Regexp.new("(?<=\\A|\\W)['#{single_quotes[0]}#{single_quotes[1]}](.*?)['#{single_quotes[0]}#{single_quotes[1]}](?!\\w)")
|
17
18
|
end
|
18
19
|
|
19
20
|
def single_quotes
|
20
|
-
options.fetch(:single_quotes,
|
21
|
+
options.fetch(:single_quotes, translation(:single_quotes))
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/lib/improve_typography.rb
CHANGED
@@ -8,6 +8,24 @@ require 'improve_typography/processor'
|
|
8
8
|
Dir["#{File.dirname(__FILE__)}/improve_typography/processors/**/*.rb"].each { |f| require f }
|
9
9
|
|
10
10
|
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
11
|
-
I18n.load_path += Dir.glob(File.join(
|
11
|
+
I18n.load_path += Dir.glob(File.join(File.dirname(__FILE__), 'config', 'locales', '*.yml'))
|
12
12
|
|
13
13
|
require 'improve_typography/version'
|
14
|
+
|
15
|
+
module ImproveTypography
|
16
|
+
class << self
|
17
|
+
attr_accessor :configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration=(config)
|
25
|
+
@configuration = config
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield configuration
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: improve_typography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: guard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '13.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '13.0'
|
111
111
|
description:
|
112
112
|
email:
|
113
113
|
- tomas.celizna@gmail.com
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- bin/setup
|
128
128
|
- improve_typography.gemspec
|
129
129
|
- lib/config/locales/cs.yml
|
130
|
+
- lib/config/locales/da.yml
|
130
131
|
- lib/config/locales/en.yml
|
131
132
|
- lib/improve_typography.rb
|
132
133
|
- lib/improve_typography/base.rb
|
@@ -163,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
164
|
- !ruby/object:Gem::Version
|
164
165
|
version: '0'
|
165
166
|
requirements: []
|
166
|
-
|
167
|
-
rubygems_version: 2.7.6
|
167
|
+
rubygems_version: 3.1.4
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: Improves typography (quotes, hyphens, etc.) of a given string. Works well
|