lightgraf 0.1.1.pre.beta.1 → 0.1.2.pre.beta.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +38 -0
- data/CHANGELOG.md +3 -1
- data/Gemfile.lock +5 -5
- data/README.md +13 -1
- data/lib/lightgraf/fixtures.rb +28 -16
- data/lib/lightgraf/internal.rb +32 -11
- data/lib/lightgraf/version.rb +1 -1
- data/lib/lightgraf.rb +10 -9
- data/lightgraf.gemspec +3 -3
- metadata +12 -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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ "master" ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ "master" ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
strategy:
|
24
|
+
matrix:
|
25
|
+
ruby-version: ['2.6']
|
26
|
+
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Set up Ruby
|
30
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
31
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
32
|
+
# uses: ruby/setup-ruby@v1
|
33
|
+
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
|
34
|
+
with:
|
35
|
+
ruby-version: ${{ matrix.ruby-version }}
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rake
|
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/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Lightgraf
|
2
|
+
[](https://badge.fury.io/rb/lightgraf)
|
2
3
|
|
3
4
|
Lightweight typography tool for Rails. It handles for you:
|
4
5
|
- __Quotes__:
|
@@ -18,6 +19,14 @@ Lightweight typography tool for Rails. It handles for you:
|
|
18
19
|
А что я? А я ничего\
|
19
20
|
`↓` \
|
20
21
|
А(NBSP)что я?(NBSP)А(NBSP)я(NBSP)ничего
|
22
|
+
|
23
|
+
- __No-breakables__:
|
24
|
+
|
25
|
+
Call me: 232-12-34\
|
26
|
+
`↓` \
|
27
|
+
Call me: \<nobr\>232-12-34\</nobr\>
|
28
|
+
|
29
|
+
It is fast and efficient, handling complex text of ~5800 characters at 0.06 sec
|
21
30
|
|
22
31
|
## Installation
|
23
32
|
|
@@ -37,7 +46,10 @@ Or install it yourself as:
|
|
37
46
|
|
38
47
|
## Usage
|
39
48
|
|
40
|
-
|
49
|
+
```ruby
|
50
|
+
require 'lightgraf'
|
51
|
+
fixed_text = Lightgraf.fix "My text"
|
52
|
+
```
|
41
53
|
|
42
54
|
## Development
|
43
55
|
|
data/lib/lightgraf/fixtures.rb
CHANGED
@@ -6,22 +6,34 @@ module Lightgraf
|
|
6
6
|
module Fixtures
|
7
7
|
INCORRECT_QUOTES = %w[' " `].freeze
|
8
8
|
HYPHENS = %w[- – —].freeze
|
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
|
-
|
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
|
+
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,14 +50,23 @@ 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)
|
48
59
|
inside.pop if inside.last == :quote_a
|
49
60
|
elsif SPACES.include?(char)
|
61
|
+
if last_space == i - 1
|
62
|
+
last_space = i
|
63
|
+
next
|
64
|
+
end
|
50
65
|
need_next = false
|
51
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]))
|
52
|
-
|
67
|
+
ins = case format; when :html then HTML_NBSP; when :plaintext then NBSP; end
|
68
|
+
fixed += ins
|
69
|
+
offset += ins.length - 1
|
53
70
|
need_next = true
|
54
71
|
end
|
55
72
|
if need_nobr_r
|
@@ -58,13 +75,17 @@ module Lightgraf
|
|
58
75
|
end
|
59
76
|
last_space = i
|
60
77
|
next if need_next
|
78
|
+
fixed += SPACE
|
79
|
+
next
|
61
80
|
elsif HYPHENS.include?(char)
|
62
81
|
need_next = false
|
63
82
|
if !disable_hyphens and (i.zero? or last_space == i - 1)
|
64
|
-
|
83
|
+
ins = case format; when :html then HTML_HYPHEN; when :plaintext then HYPHEN; end
|
84
|
+
fixed += ins
|
85
|
+
offset += ins.length - 1
|
65
86
|
need_next = true
|
66
|
-
elsif
|
67
|
-
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
|
68
89
|
need_nobr_r = true
|
69
90
|
end
|
70
91
|
last_hyphen = i
|
@@ -73,37 +94,37 @@ module Lightgraf
|
|
73
94
|
case inside.last
|
74
95
|
when :quote_a
|
75
96
|
if char == quote_char.last
|
76
|
-
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
|
77
98
|
inside.pop
|
78
99
|
quote_char.pop
|
79
100
|
quote_lang.pop
|
80
101
|
else
|
81
102
|
quote_lang << (cyrillic?(text[i, lang_check_max_take]) ? :ru : :en)
|
82
|
-
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
|
83
104
|
inside << :quote_b
|
84
105
|
quote_char << char
|
85
106
|
end
|
86
107
|
when :quote_b
|
87
108
|
if char == quote_char.last
|
88
|
-
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
|
89
110
|
inside << :quote_a
|
90
111
|
quote_char.pop
|
91
112
|
quote_lang.pop
|
92
113
|
else
|
93
114
|
quote_lang << (cyrillic?(text[i, lang_check_max_take]) ? :ru : :en)
|
94
|
-
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
|
95
116
|
inside << :quote_a
|
96
117
|
quote_char << char
|
97
118
|
end
|
98
119
|
when nil
|
99
120
|
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
|
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
|
101
122
|
inside << :quote_a
|
102
123
|
quote_char = [char]
|
103
124
|
end
|
104
125
|
next
|
105
126
|
end
|
106
|
-
fixed +=
|
127
|
+
fixed += char
|
107
128
|
end
|
108
129
|
fixed += HTML_NOBR_R if need_nobr_r
|
109
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,13 +80,15 @@ 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: []
|
87
88
|
extensions: []
|
88
89
|
extra_rdoc_files: []
|
89
90
|
files:
|
91
|
+
- ".github/workflows/ruby.yml"
|
90
92
|
- ".gitignore"
|
91
93
|
- ".rubocop.yml"
|
92
94
|
- CHANGELOG.md
|
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
123
|
- !ruby/object:Gem::Version
|
122
124
|
version: 1.3.1
|
123
125
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.2.3
|
125
127
|
signing_key:
|
126
128
|
specification_version: 4
|
127
129
|
summary: Lightweight typography helper for Russian language
|