text_hyphen_rails 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c6a77398d5a3b09a1b3742cf1358fa7bcb408e7
4
- data.tar.gz: 06873e4f1d3e7c34820b457cd83ce4a085fff799
3
+ metadata.gz: a1349b1d23da1677d97669eeb5b9d6c536004b0b
4
+ data.tar.gz: 2b44bfcf8a999f624e91a8614d5de21bac2d68cc
5
5
  SHA512:
6
- metadata.gz: 232b1ab239d085f78f1d05ed05357b1b1ce7d3f31617910da0b9fb1f85c36c1aa36389ba6af78b4269ba7c33f96b7a70e8964da026b62f3b410f90232f037268
7
- data.tar.gz: b2f0954b578f54dbaee87c2afe9cf4895a2152dd9bc0023b5473659d27d6c51cfded1c376c7ada686363a2927e42b3917ece248d9b53f95a0519f449a756844c
6
+ metadata.gz: ee307fee9d10ac0c68eebbc6657a0ade8ea81923fa751cc73ce15d4add1a893e1df5cff7924b706ef180e26ca477bf28ec4f69d0a7407e2434de8cef13347d51
7
+ data.tar.gz: c2e5b65212e66f7b4ccc7fc664f176d20ec0568d71a15f5d68b14ce63840a9aeae7bf6ea18c8d960763c2bf0bd767c0327c063f07cea69c7c6360cbf4fbddeee
@@ -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
- g_opts = thr_g_opts att, opts
26
- self.send(:define_method, thr_meth_name(att, g_opts)) do
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
- opts = thr_opts g_opts
29
- h_class.new(str, opts).result
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 thr_g_opts(meth, opts)
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
- def thr_opts opts
50
+ private
51
+
52
+ def _thr_lang(opts)
50
53
  if opts[:lang_att]
51
- lang = self.send(opts[:lang_att])
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
- def initialize text, options
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
- raise 'don\'t use this class directly'
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
- @rx ||= /[[:alpha:]]{#{@opts[:min_word_length]},}/m
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: @opts[:lang],
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 text, options
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
@@ -1,3 +1,3 @@
1
1
  module TextHyphenRails
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  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.3
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-01 00:00:00.000000000 Z
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/active_record_extensions.rb
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