orthotypo 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2f6a258873f18c7dc354138d1c32a75eb53c185ff8df8352222d5ea67eff0cf
4
- data.tar.gz: be6d6756ec6f2925304776c150448c0e34469a32b95e92cbf3e54b64a9f581ac
3
+ metadata.gz: b39450aef34318976f5708d105828cbc0792ff8d6c81a1f3c3eb51d2ce27713b
4
+ data.tar.gz: d2a701e7525d6babcf406c702fc1e181ecae671840344df66f0d3d02538a702a
5
5
  SHA512:
6
- metadata.gz: 1138ac9e055c6b87db9117b6640bb32457dd20a35306e87da7665a5496485aa89a82e18f9bde2329c77533a64815cdfbfbd44bb6fa2d17c2f5b0f576f80adee0
7
- data.tar.gz: fd5f3571d645b7facf19afa56d7c6700724dbe6d8f5372ce3bc8a68bfa14d346408cf7a64fe8c8b34fc3db5e5037f4173ed268651c8fdcde133e3a89a39e3542
6
+ metadata.gz: 8066e337bf64b472bf9610e5e96c41819c5e0148a8725d22781c3d26a987835cc098745f8f12de4d3f087d745186006f6fe11f8fd7daa64e870d0175e458f3f6
7
+ data.tar.gz: b9d9e4398cbc8e7516f6eb475abc0a22ae291b12b38706ed08bbc18e568abb415da8ec45ed7a6a3658a911efe68df0b6d15b0950b1f007d108dadf6de5ab1e0d
@@ -0,0 +1,18 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@2.1.1
4
+ jobs:
5
+ test:
6
+ docker:
7
+ - image: cimg/ruby:3.3
8
+ steps:
9
+ - checkout
10
+ - ruby/install-deps
11
+ - run:
12
+ name: Run tests
13
+ command: bundle exec rake
14
+ workflows:
15
+ version: 2
16
+ deploy:
17
+ jobs:
18
+ - test
data/Gemfile CHANGED
@@ -6,5 +6,4 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
-
10
9
  gem "rubocop", "~> 1.21"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orthotypo (1.0.2)
4
+ orthotypo (1.0.4)
5
5
  htmlentities
6
6
  nokogiri
7
7
 
@@ -18,6 +18,8 @@ GEM
18
18
  racc (~> 1.4)
19
19
  nokogiri (1.16.2-x86_64-darwin)
20
20
  racc (~> 1.4)
21
+ nokogiri (1.16.2-x86_64-linux)
22
+ racc (~> 1.4)
21
23
  parallel (1.24.0)
22
24
  parser (3.3.0.5)
23
25
  ast (~> 2.4.1)
@@ -42,8 +44,10 @@ GEM
42
44
  rspec-nc (0.3.0)
43
45
  rspec (>= 3)
44
46
  terminal-notifier (>= 1.4)
45
- rspec-support (3.13.0)
46
- rubocop (1.60.2)
47
+ rspec-support (3.13.1)
48
+ rspec_junit_formatter (0.6.0)
49
+ rspec-core (>= 2, < 4, != 2.12.0)
50
+ rubocop (1.62.1)
47
51
  json (~> 2.3)
48
52
  language_server-protocol (>= 3.17.0)
49
53
  parallel (~> 1.10)
@@ -51,11 +55,11 @@ GEM
51
55
  rainbow (>= 2.2.2, < 4.0)
52
56
  regexp_parser (>= 1.8, < 3.0)
53
57
  rexml (>= 3.2.5, < 4.0)
54
- rubocop-ast (>= 1.30.0, < 2.0)
58
+ rubocop-ast (>= 1.31.1, < 2.0)
55
59
  ruby-progressbar (~> 1.7)
56
60
  unicode-display_width (>= 2.4.0, < 3.0)
57
- rubocop-ast (1.30.0)
58
- parser (>= 3.2.1.0)
61
+ rubocop-ast (1.31.2)
62
+ parser (>= 3.3.0.4)
59
63
  ruby-progressbar (1.13.0)
60
64
  terminal-notifier (2.0.0)
61
65
  unicode-display_width (2.5.0)
@@ -64,6 +68,7 @@ PLATFORMS
64
68
  arm64-darwin-22
65
69
  arm64-darwin-23
66
70
  x86_64-darwin-22
71
+ x86_64-linux
67
72
 
68
73
  DEPENDENCIES
69
74
  byebug
@@ -71,6 +76,7 @@ DEPENDENCIES
71
76
  rake (~> 13.0)
72
77
  rspec
73
78
  rspec-nc
79
+ rspec_junit_formatter
74
80
  rubocop (~> 1.21)
75
81
 
76
82
  BUNDLED WITH
@@ -2,10 +2,12 @@ module Orthotypo
2
2
  class Analyzer
3
3
 
4
4
  def self.url?(string)
5
- (string =~ /\A#{URI::DEFAULT_PARSER.regexp[:ABS_URI]}\z/) &&
6
- (string =~ /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/ix) ? true : false
5
+ uri = URI.parse(string)
6
+ uri.class != URI::Generic
7
+ rescue URI::InvalidURIError
8
+ false
7
9
  end
8
-
10
+
9
11
  def self.email?(string)
10
12
  string =~ /\A#{URI::MailTo::EMAIL_REGEXP}\z/ ? true : false
11
13
  end
@@ -13,6 +15,6 @@ module Orthotypo
13
15
  def self.precious?(string)
14
16
  email?(string) || url?(string)
15
17
  end
16
-
18
+
17
19
  end
18
20
  end
@@ -114,7 +114,7 @@ module Orthotypo
114
114
  end
115
115
 
116
116
  def preserve_precious_things
117
- @precious_things = []
117
+ @precious_things = {}
118
118
  @nokogiri.traverse do |node|
119
119
  if node.text?
120
120
  has_leading_space = node.content.start_with? SPACE
@@ -143,16 +143,17 @@ module Orthotypo
143
143
 
144
144
  def store_precious_thing(string)
145
145
  # Create token identifier
146
- token = "#{PRECIOUS_TOKEN}#{@precious_things.length}"
146
+ uid = SecureRandom.hex
147
+ token = "#{PRECIOUS_TOKEN}-#{uid}"
147
148
  # Store value
148
- @precious_things << string
149
+ @precious_things[uid] = string
149
150
  # Return identifier
150
151
  token
151
152
  end
152
153
 
153
154
  def restore_precious_things
154
- @precious_things.each_with_index do |value, index|
155
- @ortho.gsub! "#{PRECIOUS_TOKEN}#{index}", value
155
+ @precious_things.each do |uid, value|
156
+ @ortho.gsub! "#{PRECIOUS_TOKEN}-#{uid}", value
156
157
  end
157
158
  end
158
159
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthotypo
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.4"
5
5
  end
data/lib/orthotypo.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "htmlentities"
4
4
  require "nokogiri"
5
+ require "securerandom"
5
6
  require "uri"
6
7
  require_relative "orthotypo/analyzer"
7
8
  require_relative "orthotypo/composer"
data/orthotypo.gemspec CHANGED
@@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "rspec"
27
27
  spec.add_development_dependency "rspec-nc"
28
+ spec.add_development_dependency "rspec_junit_formatter"
28
29
  spec.add_development_dependency "byebug"
29
30
  end
@@ -3,6 +3,8 @@ require 'spec_helper'
3
3
  describe Orthotypo::Analyzer do
4
4
  it 'find urls' do
5
5
  expect(Orthotypo::Analyzer.url?("https://unsplash.com/@lusvardi?utm_source=osuny")).to be true
6
+ expect(Orthotypo::Analyzer.url?("https://hal.science/hal-02455856")).to be true
7
+ expect(Orthotypo::Analyzer.url?("mailto:test@example.com")).to be true
6
8
  expect(Orthotypo::Analyzer.url?("mot:")).to be false
7
9
  end
8
10
  end
@@ -5,7 +5,7 @@ describe Orthotypo::Composer::Fr do
5
5
  it 'adds spaces before double punctuation marks' do
6
6
  expect("mot: suite".ortho).to(eq("mot : suite"))
7
7
  expect("é: suite".ortho).to(eq("é : suite"))
8
- # Pas automatisable, parce que 11:20
8
+ # Pas automatisable, parce qu'on peut écrire une heure 11:20
9
9
  # expect("1: suite".ortho).to(eq("1 : suite"))
10
10
  expect("mot; suite".ortho).to(eq("mot ; suite"))
11
11
  expect("mot!".ortho).to(eq("mot !"))
@@ -27,11 +27,12 @@ describe Orthotypo::Composer::Fr do
27
27
 
28
28
  it 'fixes space after simple punctuation' do
29
29
  expect("mot,suite".ortho).to(eq("mot, suite"))
30
+ expect("84.Paris".ortho).to(eq("84.Paris"))
30
31
  expect("etudiant.gouv.fr".ortho).to(eq("etudiant.gouv.fr"))
31
32
  expect("4,5".ortho).to(eq("4,5"))
32
33
  expect("4.5".ortho).to(eq("4.5"))
33
- # Le test suivant, on ne fait rien, on ne peut pas résoudre, car s'apparente au cas précédent.
34
- expect("Il est né en 1984.5 maisons en paille".ortho).to(eq("Il est né en 1984.5 maisons en paille"))
34
+ # Le test suivant, on ne fait rien, on ne peut pas résoudre, car s'apparente au cas précédent (1984.5)
35
+ # expect("Il est né en 1984.5 maisons en paille".ortho).to(eq("Il est né en 1984. 5 maisons en paille"))
35
36
  end
36
37
 
37
38
  it 'fixes quotation marks' do
@@ -68,6 +69,10 @@ describe Orthotypo::Composer::Fr do
68
69
  expect("A parallel between wildlife and urban ensembles.\r\rShot during summer 2014 on our trip from north to south of Portugal.".ortho).to(eq("A parallel between wildlife and urban ensembles.<br><br>Shot during summer 2014 on our trip from north to south of Portugal."))
69
70
  end
70
71
 
72
+ it 'preserves URLs' do
73
+ expect("https://hal.science/hal-02455856".ortho).to(eq("https://hal.science/hal-02455856"))
74
+ end
75
+
71
76
  # https://www.scribbr.fr/elements-linguistiques/les-espaces/
72
77
  it 'tests de Justine Debret' do
73
78
  # FIXME
@@ -92,4 +97,12 @@ describe Orthotypo::Composer::Fr do
92
97
  # expect("Il en compte 1,000, 10,000, 36,742, 500,000, puis 1,000,000, 25,000,000, etc.".ortho).to(eq("Il en compte 1 000, 10 000, 36 742, 500 000, puis 1 000 000, 25 000 000, etc."))
93
98
  # expect("Le numéro gagnant est le 3 541 672.".ortho).to(eq("Le numéro gagnant est le 3541672."))
94
99
  end
100
+
101
+ it 'preserves all URLs' do
102
+ # Generates '<a href="https://example0.fr\">Example 0</a><a href="https://example1.fr\">Example 1</a><a href="https://example2.fr\">Example 2</a>...'
103
+ input = (0..12).map { |n|
104
+ "<a href=\"https://example#{n}.fr\">Example #{n}</a>"
105
+ }.join
106
+ expect(input.ortho).to(eq(input))
107
+ end
95
108
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'byebug'
2
- require 'Orthotypo'
2
+ require 'orthotypo'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthotypo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Levy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-15 00:00:00.000000000 Z
11
+ date: 2024-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: byebug
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,7 @@ executables: []
89
103
  extensions: []
90
104
  extra_rdoc_files: []
91
105
  files:
106
+ - ".circleci/config.yml"
92
107
  - ".gitignore"
93
108
  - ".rubocop.yml"
94
109
  - CHANGELOG.md