truty 0.2.1 → 0.3.0
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/bin/truty +12 -4
- data/lib/truty/conversion.rb +40 -0
- data/lib/truty/czech.rb +3 -3
- data/lib/truty/general.rb +10 -1
- data/lib/truty.rb +2 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06eaf24a439e783faee1611fc66b4342506adb45
|
4
|
+
data.tar.gz: d77ee705f0291cb4b49dd03e139cd8e1ecc3cea9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed88d0bacf40000e0d0259251319472c8a3da5b243ca113ab4aacb71a890d731a47baac05b2bc29b9e25e64fe56429dd3cc94d7c608688d817dcaf69fa8a2a37
|
7
|
+
data.tar.gz: d376ee6b2b30c1cce8aef57aa0a898bcc58a2354bbc2592b1c12002aadafa468b9f948fba8bbd9ccac54464c0ddcdf10a5992852f95728b25cfae88a4143e66f
|
data/bin/truty
CHANGED
@@ -4,11 +4,19 @@ require "truty"
|
|
4
4
|
|
5
5
|
def main
|
6
6
|
language = :general
|
7
|
-
|
8
|
-
|
9
|
-
ARGV
|
7
|
+
conversion = :none
|
8
|
+
while true do
|
9
|
+
if ARGV[0] == "-l" || ARGV[0] == "--language" then
|
10
|
+
language = ARGV[1]
|
11
|
+
ARGV.shift(2)
|
12
|
+
elsif ARGV[0] == "-c" || ARGV[0] == "--convert" then
|
13
|
+
conversion = ARGV[1]
|
14
|
+
ARGV.shift(2)
|
15
|
+
else
|
16
|
+
break
|
17
|
+
end
|
10
18
|
end
|
11
|
-
puts Truty.send :
|
19
|
+
puts Truty.send :convert, ARGF.read, conversion, language
|
12
20
|
end
|
13
21
|
|
14
22
|
main
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
require 'htmlentities'
|
3
|
+
|
4
|
+
module Truty
|
5
|
+
|
6
|
+
# Module with conversion engine for plain text. Converts to HTML.
|
7
|
+
# @author Matěj Kašpar Jirásek
|
8
|
+
module Conversion
|
9
|
+
|
10
|
+
# Fixes the typography and also converts the string.
|
11
|
+
#
|
12
|
+
# @param input [String] Text input.
|
13
|
+
# @param conversion [Symbol] Coversion type ("html" or "none")
|
14
|
+
# @return [String] Fixed and converted text.
|
15
|
+
def convert(input, conversion = :html, lang = :general)
|
16
|
+
if !Truty.respond_to? conversion then
|
17
|
+
conversion = :none
|
18
|
+
end
|
19
|
+
Truty.send(conversion, Truty.fix(input, lang))
|
20
|
+
end
|
21
|
+
|
22
|
+
# Escapes string to HTML entities.
|
23
|
+
#
|
24
|
+
# @param input [String] Text input.
|
25
|
+
# @return [String] Text with HTML entities.
|
26
|
+
def html(input)
|
27
|
+
coder = HTMLEntities.new
|
28
|
+
coder.encode(input, :named, :decimal)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the input as it is.
|
32
|
+
#
|
33
|
+
# @param input [String] Input for conversion.
|
34
|
+
# @return [String] Not changed string from input.
|
35
|
+
def none(input)
|
36
|
+
input
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/truty/czech.rb
CHANGED
@@ -40,8 +40,8 @@ module Truty
|
|
40
40
|
# @param input [String] The paragraph which will be converted.
|
41
41
|
# @return [String] Paragraph with non-breaking spaces in and after abbreviations.
|
42
42
|
def czech_abbreviations(input)
|
43
|
-
abbreviations = /(a
|
44
|
-
input.gsub(abbreviations) {
|
43
|
+
abbreviations = /(\s|^|\Z)(a\. s\.|abl\. |absol\. |adj\. |adm\. |adv\. |aj\.|ak\. |ak\. sl\.|akt\. |alch\. |amer\. |anat\. |angl\. |anglosas\. |ap\.|apod\.|arab\. |arch\. |archit\. |arg\. |arm\. gen\. |astr\. |astrol\. |atd\.|atp\.|att\. |b\. k\.|Bc\. |BcA\. |belg\. |bibl\. |biol\. |bl\. |boh\. |bot\. |br\. |brig\. gen\. |brit\. |bulh\. |bás\. |býv\. |chcsl\. |chem\. |chil\. |CSc\. |csl\. |círk\. |dat\. |dep\. |des\. |dial\. |DiS\.|dl\. |doc\. |dol\. |dop\. |dopr\. |dosl\. |dán\. |dór\. |děj\. |dět\. |ekon\. |epic\. |etnonym\. |eufem\. |ev\. |event\. |f\. |fam\. |fem\. |fil\. |film\. |fin\. |form\. |fot\. |fr\. |fut\. |fyz\. |gen\. |genmjr\. |genplk\. |genpor\. |geogr\. |geol\. |geom\. |germ\. |gram\. |hebr\. |herald\. |hist\. |hl\. |hod\. |hor\. |horn\. |hovor\. |hud\. |hut\. |ie\. |imp\. |impf\. |ind\. |indoevr\. |inf\. |Ing\. |instr\. |interj\. |iron\. |it\. |ión\. |j\. č\.|jap\. |JUDr\. |k\. s\.|kanad\. |katalán\. |klas\. |kniž\. |komp\. |konj\. |konkr\. |kpt\. |kr\. |kuch\. |kř\. |lat\. |les\. |lid\. |lit\. |liturg\. |log\. |lok\. |lék\. |m\. |mat\. |meteor\. |metr\. |MgA\. |Mgr\. |mil\. |mj\. |mjr\. |ml\. |mld\. |mn\. č\.|mod\. |ms\. |MUDr\. |MVDr\. |mysl\. |n\. |n\. l\.|např\. |neklas\. |nesklon\. |než\. |niz\. |nom\. |nor\. |npor\. |nprap\. |nrtm\. |nstržm\. |náb\. |nám\. |námoř\. |něm\. |o\. p\. s\.|o\. s\.|ob\. |obch\. |obyč\. |odd\. |odp\. |ojed\. |opt\. |p\. |p\. n\. l\.|p\. o\.|P\. S\. |P\. T\. |part\. |pas\. |pejor\. |pers\. |pf\. |PharmDr\. |PhDr\. |pl\. |plk\. |plpf\. |po Kr\.|pol\. |pomn\. |popř\. |por\. |pplk\. |ppor\. |pprap\. |prap\. |prep\. |prof\. |práv\. |př\. Kr\.|př\. n\. l\.|před n\. l\.|předl\. |přivl\. |r\. |rak\. |rcsl\. |refl\. |reg\. |resp\. |rkp\. |RNDr\. |roč\. |RSDr\. |rtm\. |rtn\. |rum\. |rus\. |s\. |s\. p\.|s\. r\. o\.|samohl\. |Sb\. |sg\. |sl\. |slang\. |slov\. |souhl\. |spec\. |spol\. s r\. o\.|sport\. |srov\. |st\. |stfr\. |stol\. |str\. |stržm\. |stsl\. |střv\. |subj\. |subst\. |superl\. |sv\. |svob\. |sz\. |t\. r\.|tech\. |telev\. |teol\. |ThDr\. |tis\. |tj\. |trans\. |tur\. |typogr\. |tzn\. |tzv\. |táz\. |v z\.|v\. o\. s\.|v\. r\.|v\. v\. i\.|var\. |vedl\. |verb\. |vl\. jm\. |voj\. |vok\. |vulg\. |vztaž\. |výtv\. |vč\. |vůb\. |z\. s\.|zahr\. |zast\. |zejm\. |zeměd\. |zkr\. |zn\. |zvl\. |zájm\. |zř\. |č\. |č\. j\.|č\. p\. |čas\. |čes\. |čet\. |čj\. |čp\. |čín\. |čís\. |ř\. |řec\. |říj\. |škpt\. |špan\. |šprap\. |št\. prap\. |švýc\. )/i
|
44
|
+
input.gsub(abbreviations) { $1 + $2.gsub(/ /, ' ') }
|
45
45
|
end
|
46
46
|
|
47
47
|
# Converts single quotes to the typograhic ones.
|
@@ -57,7 +57,7 @@ module Truty
|
|
57
57
|
# @param input [String] The paragraph which will be converted.
|
58
58
|
# @return [String] Paragraph with correct double quotes.
|
59
59
|
def czech_double_quotes(input)
|
60
|
-
quotes(input, "\"", "„", "
|
60
|
+
quotes(input, "\"", "„", "“")
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
data/lib/truty/general.rb
CHANGED
@@ -28,6 +28,7 @@ module Truty
|
|
28
28
|
input = brackets_whitespace(input)
|
29
29
|
input = emdash(input)
|
30
30
|
input = endash(input)
|
31
|
+
input = name_abbreviations(input)
|
31
32
|
input = multiplication_sign(input)
|
32
33
|
input = space_between_numbers(input)
|
33
34
|
input = units(input)
|
@@ -89,7 +90,7 @@ module Truty
|
|
89
90
|
# @return [String] Paragraph with correct double quotes.
|
90
91
|
def quotes(input, type = '"', start_quotes = "“", end_quotes = "”")
|
91
92
|
regexp = Regexp.new(type + '[^' + type + ']*' + type)
|
92
|
-
input.gsub(regexp) { |s| start_quotes + s[1..-2].
|
93
|
+
input.gsub(regexp) { |s| start_quotes + s[1..-2].gsub(/(^[\s ]+|[\s ]+$)/, "") + end_quotes }
|
93
94
|
end
|
94
95
|
|
95
96
|
# Adds multiplication sign between numbers instead of X.
|
@@ -170,5 +171,13 @@ module Truty
|
|
170
171
|
input.gsub(/\s*($|\z)/, '')
|
171
172
|
end
|
172
173
|
|
174
|
+
# Adds non-breaking space after one-character name abbreviation ("A.", "J.", etc.)
|
175
|
+
#
|
176
|
+
# @param input [String] The paragraph which will be converted.
|
177
|
+
# @return [String] Paragraph with non-breaking spaces after name abbreviations.
|
178
|
+
def name_abbreviations(input)
|
179
|
+
input.gsub(/(\s|^)(([A-Z]\.\s+)+)/) { $1 + $2.gsub(/ +/, " ")}
|
180
|
+
end
|
181
|
+
|
173
182
|
end
|
174
183
|
end
|
data/lib/truty.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'uri'
|
4
4
|
require 'text/hyphen'
|
5
5
|
require 'truty/general'
|
6
|
+
require 'truty/conversion'
|
6
7
|
require 'truty/english'
|
7
8
|
require 'truty/french'
|
8
9
|
require 'truty/czech'
|
@@ -13,6 +14,7 @@ module Truty
|
|
13
14
|
|
14
15
|
extend General
|
15
16
|
extend English, French, Czech
|
17
|
+
extend Conversion
|
16
18
|
|
17
19
|
end
|
18
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matěj Kašpar Jirásek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-hyphen
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: htmlentities
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.3'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: test-unit
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +91,7 @@ files:
|
|
77
91
|
- README.md
|
78
92
|
- bin/truty
|
79
93
|
- lib/truty.rb
|
94
|
+
- lib/truty/conversion.rb
|
80
95
|
- lib/truty/czech.rb
|
81
96
|
- lib/truty/english.rb
|
82
97
|
- lib/truty/french.rb
|
@@ -101,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
116
|
version: '0'
|
102
117
|
requirements: []
|
103
118
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.4.
|
119
|
+
rubygems_version: 2.4.3
|
105
120
|
signing_key:
|
106
121
|
specification_version: 4
|
107
122
|
summary: True typography converter
|