text_hyphen_rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/initializers/{active_record_extensions.rb → load_files.rb} +0 -0
- data/lib/text_hyphen_rails/active_record_extension.rb +12 -11
- data/lib/text_hyphen_rails/html_hyphenator.rb +5 -2
- data/lib/text_hyphen_rails/hyphenator.rb +8 -4
- data/lib/text_hyphen_rails/text_hyphen_extension.rb +12 -0
- data/lib/text_hyphen_rails/text_hyphenator.rb +4 -2
- data/lib/text_hyphen_rails/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1349b1d23da1677d97669eeb5b9d6c536004b0b
|
4
|
+
data.tar.gz: 2b44bfcf8a999f624e91a8614d5de21bac2d68cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee307fee9d10ac0c68eebbc6657a0ade8ea81923fa751cc73ce15d4add1a893e1df5cff7924b706ef180e26ca477bf28ec4f69d0a7407e2434de8cef13347d51
|
7
|
+
data.tar.gz: c2e5b65212e66f7b4ccc7fc664f176d20ec0568d71a15f5d68b14ce63840a9aeae7bf6ea18c8d960763c2bf0bd767c0327c063f07cea69c7c6360cbf4fbddeee
|
File without changes
|
@@ -22,12 +22,13 @@ module TextHyphenRails
|
|
22
22
|
|
23
23
|
def thr_create_methods(h_class, args, opts)
|
24
24
|
args.each do |att|
|
25
|
-
|
26
|
-
self.send(:define_method, thr_meth_name(att,
|
25
|
+
m_opts = thr_m_opts att, opts
|
26
|
+
self.send(:define_method, thr_meth_name(att, m_opts)) do
|
27
27
|
str = read_attribute att
|
28
|
-
|
29
|
-
h_class.new(str,
|
28
|
+
lang = _thr_lang m_opts
|
29
|
+
h_class.new(str, lang, m_opts).result
|
30
30
|
end
|
31
|
+
self.send(:define_method, "#{att}_orig") { read_attribute att } if opts[:replace_meth]
|
31
32
|
end
|
32
33
|
|
33
34
|
end
|
@@ -40,22 +41,22 @@ module TextHyphenRails
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
+
def thr_m_opts(meth, opts)
|
44
45
|
raise UnknownOptionError if (opts.keys - TextHyphenRails.settings.keys).size > 0
|
45
46
|
TextHyphenRails.settings.merge opts
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
def _thr_lang(opts)
|
50
53
|
if opts[:lang_att]
|
51
|
-
|
52
|
-
nopts = opts.dup
|
53
|
-
nopts[:lang] = lang
|
54
|
-
nopts
|
54
|
+
self.send(opts[:lang_att])
|
55
55
|
else
|
56
|
-
opts
|
56
|
+
opts[:lang]
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module TextHyphenRails
|
2
|
+
|
2
3
|
class HtmlHyphenator < Hyphenator
|
3
|
-
|
4
|
+
|
5
|
+
def initialize(text, lang, options)
|
6
|
+
super
|
4
7
|
@doc = Nokogiri::HTML.fragment text
|
5
|
-
@opts = options
|
6
8
|
end
|
7
9
|
|
8
10
|
def result
|
@@ -22,5 +24,6 @@ module TextHyphenRails
|
|
22
24
|
# broken
|
23
25
|
@doc.xpath('//text()')
|
24
26
|
end
|
27
|
+
|
25
28
|
end
|
26
29
|
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
module TextHyphenRails
|
2
|
+
|
2
3
|
class Hyphenator
|
3
4
|
|
4
|
-
def initialize
|
5
|
-
|
5
|
+
def initialize(text, lang, options)
|
6
|
+
@opts = options
|
7
|
+
@lang = lang
|
6
8
|
end
|
7
9
|
|
8
10
|
private
|
9
11
|
|
10
12
|
def regex
|
11
|
-
|
13
|
+
n = @opts[:min_word_length]
|
14
|
+
@rx ||= Regexp.new("[[:alpha:]]{#{n},}")
|
12
15
|
end
|
13
16
|
|
14
17
|
def hyphenator
|
15
|
-
@hyph ||= ::Text::Hyphen.new(language: @
|
18
|
+
@hyph ||= ::Text::Hyphen.new(language: @lang,
|
16
19
|
left: @opts[:left],
|
17
20
|
right: @opts[:right])
|
18
21
|
end
|
22
|
+
|
19
23
|
end
|
20
24
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module TextHyphenRails
|
2
|
+
module TextHyphenEntension
|
3
|
+
def add_exception exc
|
4
|
+
poss, off = [], 0
|
5
|
+
exc.chars.each_with_index {|c, n| c == '-' && poss << n - off && off += 1}
|
6
|
+
exc_arr = (0..exc.size-off).map {|i| poss.include?(i) ? 1 : 0}
|
7
|
+
language.exceptions[exc.gsub('-', '')] = exc_arr
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
::Text::Hyphen.send(:include, TextHyphenRails::TextHyphenEntension)
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module TextHyphenRails
|
2
|
+
|
2
3
|
class TextHyphenator < Hyphenator
|
3
4
|
|
4
|
-
def initialize
|
5
|
+
def initialize(text, lang, options)
|
6
|
+
super
|
5
7
|
@text = text
|
6
|
-
@opts = options
|
7
8
|
end
|
8
9
|
|
9
10
|
def result
|
@@ -11,5 +12,6 @@ module TextHyphenRails
|
|
11
12
|
hyphenator.visualize(tok, @opts[:hyphen])
|
12
13
|
end
|
13
14
|
end
|
15
|
+
|
14
16
|
end
|
15
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_hyphen_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thelonius Kort
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -128,13 +128,14 @@ executables: []
|
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
|
-
- config/initializers/
|
131
|
+
- config/initializers/load_files.rb
|
132
132
|
- config/routes.rb
|
133
133
|
- lib/text_hyphen_rails.rb
|
134
134
|
- lib/text_hyphen_rails/active_record_extension.rb
|
135
135
|
- lib/text_hyphen_rails/engine.rb
|
136
136
|
- lib/text_hyphen_rails/html_hyphenator.rb
|
137
137
|
- lib/text_hyphen_rails/hyphenator.rb
|
138
|
+
- lib/text_hyphen_rails/text_hyphen_extension.rb
|
138
139
|
- lib/text_hyphen_rails/text_hyphenator.rb
|
139
140
|
- lib/text_hyphen_rails/version.rb
|
140
141
|
homepage: https://github.com/tnt/text_hyphen_rails
|