lightgraf 0.1.1.pre.beta.2 → 0.1.2.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +2 -1
- data/Gemfile.lock +5 -5
- data/lib/lightgraf/fixtures.rb +27 -15
- data/lib/lightgraf/internal.rb +26 -11
- data/lib/lightgraf/version.rb +1 -1
- data/lib/lightgraf.rb +10 -9
- data/lightgraf.gemspec +3 -3
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f42e55aa76e452a1f8c6161ae839f18903d413f620d4422d716f93007c00b52c
|
4
|
+
data.tar.gz: e013d4eadbe41ef6c9ff13b4dfd10b655397c497a147b6af0cc686fe9bd209ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27a36ac1441718ba1384347a63bce7f09e68ab25b9831229f08de73918273ecaba9cf20b8ae17a27f57bcde0224241f04a1ca5d1669c0746846402ecdf9aac84
|
7
|
+
data.tar.gz: 7cbe398dd363ca780fb92a0acb2132aacbc548b65235f5595e6788c0c600a6e5c3e4d5df84c0c634474a076d73cca5b70f4443286594b5bcb228d261eb65f6bd
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lightgraf (0.1.
|
4
|
+
lightgraf (0.1.2.pre.beta.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
parser (3.2.2.1)
|
15
15
|
ast (~> 2.4.1)
|
16
16
|
rainbow (3.1.1)
|
17
|
-
rake (
|
17
|
+
rake (13.0.6)
|
18
18
|
regexp_parser (2.8.0)
|
19
19
|
rexml (3.2.5)
|
20
20
|
rubocop (1.50.2)
|
@@ -36,12 +36,12 @@ PLATFORMS
|
|
36
36
|
ruby
|
37
37
|
|
38
38
|
DEPENDENCIES
|
39
|
-
bundler (
|
39
|
+
bundler (>= 2.2.33)
|
40
40
|
irb
|
41
41
|
lightgraf!
|
42
42
|
minitest (~> 5.0)
|
43
|
-
rake (~>
|
43
|
+
rake (~> 13.0)
|
44
44
|
rubocop
|
45
45
|
|
46
46
|
BUNDLED WITH
|
47
|
-
|
47
|
+
2.4.13
|
data/lib/lightgraf/fixtures.rb
CHANGED
@@ -7,21 +7,33 @@ module Lightgraf
|
|
7
7
|
INCORRECT_QUOTES = %w[' " `].freeze
|
8
8
|
HYPHENS = %w[- – —].freeze
|
9
9
|
SPACES = [' ', ' ', ' ', ' ', ' ', '', '', '', 'ㅤ', ' ', ' ', ' ', '⠀', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ''].freeze
|
10
|
-
TAG_L
|
11
|
-
TAG_R
|
12
|
-
QUOT_RU_A_L
|
13
|
-
QUOT_RU_A_R
|
14
|
-
QUOT_RU_B_L
|
15
|
-
QUOT_RU_B_R
|
16
|
-
QUOT_EN_A_L
|
17
|
-
QUOT_EN_A_R
|
18
|
-
QUOT_EN_B_L
|
19
|
-
QUOT_EN_B_R
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
TAG_L = %(<)
|
11
|
+
TAG_R = %(>)
|
12
|
+
QUOT_RU_A_L = %(«)
|
13
|
+
QUOT_RU_A_R = %(»)
|
14
|
+
QUOT_RU_B_L = %(„)
|
15
|
+
QUOT_RU_B_R = %(“)
|
16
|
+
QUOT_EN_A_L = %(“)
|
17
|
+
QUOT_EN_A_R = %(”)
|
18
|
+
QUOT_EN_B_L = %(‘)
|
19
|
+
QUOT_EN_B_R = %(’)
|
20
|
+
AMPERSAND = %(&)
|
21
|
+
HYPHEN = HYPHENS[2]
|
22
|
+
SPACE = SPACES[0]
|
23
|
+
NBSP = SPACES[2]
|
24
|
+
HTML_AMPERSAND = %(&)
|
25
|
+
HTML_QUOT_RU_A_L = %(«)
|
26
|
+
HTML_QUOT_RU_A_R = %(»)
|
27
|
+
HTML_QUOT_RU_B_L = %(„)
|
28
|
+
HTML_QUOT_RU_B_R = %(“)
|
29
|
+
HTML_QUOT_EN_A_L = %(“)
|
30
|
+
HTML_QUOT_EN_A_R = %(”)
|
31
|
+
HTML_QUOT_EN_B_L = %(‘)
|
32
|
+
HTML_QUOT_EN_B_R = %(’)
|
33
|
+
HTML_NOBR_L = %(<nobr>)
|
34
|
+
HTML_NOBR_R = %(</nobr>)
|
35
|
+
HTML_HYPHEN = %(—)
|
36
|
+
HTML_NBSP = %( )
|
25
37
|
end
|
26
38
|
|
27
39
|
end
|
data/lib/lightgraf/internal.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# Handcrafted by Aydar N.
|
2
|
+
# 2023
|
3
|
+
#
|
4
|
+
# me@aydar.media
|
5
|
+
#
|
6
|
+
|
1
7
|
# frozen_string_literal: true
|
2
8
|
|
3
9
|
require 'lightgraf/fixtures'
|
@@ -11,11 +17,12 @@ module Lightgraf
|
|
11
17
|
|
12
18
|
def self.fix(
|
13
19
|
text,
|
14
|
-
|
20
|
+
format: :plaintext,
|
15
21
|
disable_quotes: false,
|
16
22
|
disable_hyphens: false,
|
17
23
|
disable_nbsp: false,
|
18
24
|
disable_nobr: false,
|
25
|
+
disable_escape: false,
|
19
26
|
lang_check_max_take: 5,
|
20
27
|
nbsp_max_length: 3
|
21
28
|
)
|
@@ -29,6 +36,7 @@ module Lightgraf
|
|
29
36
|
last_space = nil
|
30
37
|
last_hyphen = nil
|
31
38
|
need_nobr_r = false
|
39
|
+
offset = 0
|
32
40
|
(0..text.length - 1).each do |i|
|
33
41
|
char = text[i]
|
34
42
|
if char == TAG_L
|
@@ -42,6 +50,9 @@ module Lightgraf
|
|
42
50
|
elsif inside.last == :tag
|
43
51
|
fixed += char
|
44
52
|
next
|
53
|
+
elsif !disable_escape and format == :html and char == AMPERSAND
|
54
|
+
fixed += HTML_AMPERSAND
|
55
|
+
next
|
45
56
|
elsif [QUOT_RU_A_L, QUOT_EN_A_L].include?(char)
|
46
57
|
inside << :quote_a
|
47
58
|
elsif [QUOT_RU_A_R, QUOT_EN_A_R].include?(char)
|
@@ -53,7 +64,9 @@ module Lightgraf
|
|
53
64
|
end
|
54
65
|
need_next = false
|
55
66
|
if !disable_nbsp and (i < nbsp_max_length or (!last_space.nil? and last_hyphen != i - 1 and (i - last_space) <= nbsp_max_length) or HYPHENS.include?(text[i + 1]))
|
56
|
-
|
67
|
+
ins = case format; when :html then HTML_NBSP; when :plaintext then NBSP; end
|
68
|
+
fixed += ins
|
69
|
+
offset += ins.length - 1
|
57
70
|
need_next = true
|
58
71
|
end
|
59
72
|
if need_nobr_r
|
@@ -67,10 +80,12 @@ module Lightgraf
|
|
67
80
|
elsif HYPHENS.include?(char)
|
68
81
|
need_next = false
|
69
82
|
if !disable_hyphens and (i.zero? or last_space == i - 1)
|
70
|
-
|
83
|
+
ins = case format; when :html then HTML_HYPHEN; when :plaintext then HYPHEN; end
|
84
|
+
fixed += ins
|
85
|
+
offset += ins.length - 1
|
71
86
|
need_next = true
|
72
|
-
elsif
|
73
|
-
fixed.insert (last_space.nil? ? 0 : last_space + 1), HTML_NOBR_L
|
87
|
+
elsif format == :html and !disable_nobr and !need_nobr_r and last_space != i - 1 and !whitespace?(text[i + 1])
|
88
|
+
fixed.insert (last_space.nil? ? 0 : last_space + offset + 1), HTML_NOBR_L
|
74
89
|
need_nobr_r = true
|
75
90
|
end
|
76
91
|
last_hyphen = i
|
@@ -79,37 +94,37 @@ module Lightgraf
|
|
79
94
|
case inside.last
|
80
95
|
when :quote_a
|
81
96
|
if char == quote_char.last
|
82
|
-
fixed += quote_lang.last == :ru ? QUOT_RU_A_R : QUOT_EN_A_R
|
97
|
+
fixed += case format; when :html then (quote_lang.last == :ru ? HTML_QUOT_RU_A_R : HTML_QUOT_EN_A_R); when :plaintext then (quote_lang.last == :ru ? QUOT_RU_A_R : QUOT_EN_A_R); end
|
83
98
|
inside.pop
|
84
99
|
quote_char.pop
|
85
100
|
quote_lang.pop
|
86
101
|
else
|
87
102
|
quote_lang << (cyrillic?(text[i, lang_check_max_take]) ? :ru : :en)
|
88
|
-
fixed += quote_lang.last == :ru ? QUOT_RU_B_L : QUOT_EN_B_L
|
103
|
+
fixed += case format; when :html then (quote_lang.last == :ru ? HTML_QUOT_RU_B_L : HTML_QUOT_EN_B_L); when :plaintext then (quote_lang.last == :ru ? QUOT_RU_B_L : QUOT_EN_B_L); end
|
89
104
|
inside << :quote_b
|
90
105
|
quote_char << char
|
91
106
|
end
|
92
107
|
when :quote_b
|
93
108
|
if char == quote_char.last
|
94
|
-
fixed += quote_lang.last == :ru ? QUOT_RU_B_R : QUOT_EN_B_R
|
109
|
+
fixed += case format; when :html then (quote_lang.last == :ru ? HTML_QUOT_RU_B_R : HTML_QUOT_EN_B_R); when :plaintext then (quote_lang.last == :ru ? QUOT_RU_B_R : QUOT_EN_B_R); end
|
95
110
|
inside << :quote_a
|
96
111
|
quote_char.pop
|
97
112
|
quote_lang.pop
|
98
113
|
else
|
99
114
|
quote_lang << (cyrillic?(text[i, lang_check_max_take]) ? :ru : :en)
|
100
|
-
fixed += quote_lang.last == :ru ? QUOT_RU_A_L : QUOT_EN_A_L
|
115
|
+
fixed += case format; when :html then (quote_lang.last == :ru ? HTML_QUOT_RU_A_L : HTML_QUOT_EN_A_L); when :plaintext then (quote_lang.last == :ru ? QUOT_RU_A_L : QUOT_EN_A_L); end
|
101
116
|
inside << :quote_a
|
102
117
|
quote_char << char
|
103
118
|
end
|
104
119
|
when nil
|
105
120
|
quote_lang = (cyrillic?(text[i, lang_check_max_take]) ? [:ru] : [:en])
|
106
|
-
fixed += quote_lang.last == :ru ? QUOT_RU_A_L : QUOT_EN_A_L
|
121
|
+
fixed += case format; when :html then (quote_lang.last == :ru ? HTML_QUOT_RU_A_L : HTML_QUOT_EN_A_L); when :plaintext then (quote_lang.last == :ru ? QUOT_RU_A_L : QUOT_EN_A_L); end
|
107
122
|
inside << :quote_a
|
108
123
|
quote_char = [char]
|
109
124
|
end
|
110
125
|
next
|
111
126
|
end
|
112
|
-
fixed +=
|
127
|
+
fixed += char
|
113
128
|
end
|
114
129
|
fixed += HTML_NOBR_R if need_nobr_r
|
115
130
|
fixed
|
data/lib/lightgraf/version.rb
CHANGED
data/lib/lightgraf.rb
CHANGED
@@ -15,17 +15,18 @@ module Lightgraf
|
|
15
15
|
|
16
16
|
# Fixes formatting of a block of text, returning formatted text
|
17
17
|
# == Parameters:
|
18
|
-
# +text+:: +String
|
19
|
-
# +
|
20
|
-
# +disable_quotes+::
|
21
|
-
# +disable_hyphens+::
|
22
|
-
# +disable_nbsp+::
|
23
|
-
# +disable_nobr+::
|
24
|
-
# +
|
18
|
+
# +text+:: +String+: Text to format
|
19
|
+
# +format+:: Optional +Sym+: How to format output (+:plaintext+ / +:html+)
|
20
|
+
# +disable_quotes+:: Optional +Bool+: Whether to disable fixing quotation
|
21
|
+
# +disable_hyphens+:: Optional +Bool+: Whether to disable fixing hyphens
|
22
|
+
# +disable_nbsp+:: Optional +Bool+: Whether to disable fixing whitespaces
|
23
|
+
# +disable_nobr+:: Optional +Bool+: Whether to disable adding <nobr>
|
24
|
+
# +disable_escape+:: Optional +Bool+: Whether to disable escaping html-specific chars like +&+
|
25
|
+
# +lang_check_max_take+:: Optional +Int+: Max number of chars to consider while analyzing quotation language
|
25
26
|
# == Returns:
|
26
27
|
# +String+:: Formatted text
|
27
|
-
def self.fix(text,
|
28
|
-
Internal.fix text,
|
28
|
+
def self.fix(text, format: :plaintext, disable_quotes: false, disable_hyphens: false, disable_nbsp: false, disable_nobr: false, disable_escape: false, lang_check_max_take: 5)
|
29
|
+
Internal.fix text, format: format, disable_quotes: disable_quotes, disable_hyphens: disable_hyphens, disable_nbsp: disable_nbsp, disable_nobr: disable_nobr, disable_escape: disable_escape, lang_check_max_take: lang_check_max_take
|
29
30
|
end
|
30
31
|
|
31
32
|
end
|
data/lightgraf.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.required_ruby_version = '>= 2.6.3'
|
14
14
|
|
15
15
|
spec.summary = 'Lightweight typography helper for Russian language'
|
16
|
-
|
16
|
+
spec.description = 'Lightgraf is a lightweight typography tool intended for use in Rails primarily with Russian. Formats quotes, hyphens and whitespaces.'
|
17
17
|
spec.homepage = 'https://rubygems.org/gems/lightgraf'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
|
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
|
-
spec.add_development_dependency 'bundler', '
|
29
|
+
spec.add_development_dependency 'bundler', '>= 2.2.33'
|
30
30
|
spec.add_development_dependency 'irb'
|
31
31
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
32
|
-
spec.add_development_dependency 'rake', '~>
|
32
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
33
33
|
spec.add_development_dependency 'rubocop'
|
34
34
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightgraf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2.pre.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aydar N.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: irb
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,8 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: Lightgraf is a lightweight typography tool intended for use in Rails
|
84
|
+
primarily with Russian. Formats quotes, hyphens and whitespaces.
|
84
85
|
email:
|
85
86
|
- me@aydar.media
|
86
87
|
executables: []
|
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
- !ruby/object:Gem::Version
|
123
124
|
version: 1.3.1
|
124
125
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.2.3
|
126
127
|
signing_key:
|
127
128
|
specification_version: 4
|
128
129
|
summary: Lightweight typography helper for Russian language
|