Module: Konjak::Segment::GTT
Defined Under Namespace
Classes: Tag
Instance Method Summary collapse
- #compile_gtt_html_pattern ⇒ Object
- #extract_gtt_tags_from(text) ⇒ Object
- #interpolate_gtt_tags(tags) ⇒ Object
Instance Method Details
#compile_gtt_html_pattern ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/konjak/segment/gtt.rb', line 10 def compile_gtt_html_pattern regexp = Regexp.escape(text) gtt_tag_ns.each do |n| regexp.sub!(/\\\{#{n}\\\}/) { "(?<n#{n}><(?<_#{n}>\\w+)[^>]*>)" } regexp.gsub!(/\\\{#{n}\\\}/) { "\\k<n#{n}>" } regexp.gsub!(/\\\{\/#{n}\\\}/) { "</\\k<_#{n}>>" } end regexp.gsub!(/\\\s/) { '\s' } regexp.gsub!(/(?<!^)(?:\\s)+(?!$)/) {|s| s + '++' } Regexp.compile(regexp) end |
#extract_gtt_tags_from(text) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/konjak/segment/gtt.rb', line 22 def (text) m = text.match(compile_gtt_html_pattern) gtt_tag_ns.each_with_object([]) do |n, | << Tag.new("{#{n}}", m["n#{n}"]) << Tag.new("{/#{n}}", "</#{m["_#{n}"]}>") end end |
#interpolate_gtt_tags(tags) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/konjak/segment/gtt.rb', line 30 def () new_text = self.text.dup .each do |tag| new_text = new_text.gsub(tag[:gtt], tag[:html]) end new_text end |