Module: Haml::I18n::Extractor::Helpers::StringHelpers
- Included in:
- InterpolationHelper, TextFinder, TextReplacer, YamlWriter
- Defined in:
- lib/haml-i18n-extractor/helpers.rb
Constant Summary collapse
- NOT_ALLOWED_IN_KEYNAME =
do not pollute the key space it will make it invalid yaml
%w( ~ ` ! @ # $ % ^ & * - ( ) , ? { } = ' " : ; \\ / . | > < [ ] )
- LIMIT_KEY_NAME =
limit the number of chars
30
Instance Method Summary collapse
- #change_one_interpolation(str) ⇒ Object
- #html_comment?(txt) ⇒ Boolean
- #interpolated?(str) ⇒ Boolean
- #link_to?(txt) ⇒ Boolean
- #normalize_interpolation(str) ⇒ Object
- #normalized_name(str) ⇒ Object
Instance Method Details
#change_one_interpolation(str) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/haml-i18n-extractor/helpers.rb', line 31 def change_one_interpolation(str) if interpolated?(str) scanner = StringScanner.new(str) scanner.scan_until(/\#{(.*?)}/) ret = "#{scanner.pre_match}" ret << "%{#{normalized_name(scanner.matched)}}" ret << "#{scanner.post_match}" else ret = str end ret end |
#html_comment?(txt) ⇒ Boolean
44 45 46 |
# File 'lib/haml-i18n-extractor/helpers.rb', line 44 def html_comment?(txt) txt.match(/<!--/) || txt.match(/-->\s*$/) end |
#interpolated?(str) ⇒ Boolean
13 14 15 |
# File 'lib/haml-i18n-extractor/helpers.rb', line 13 def interpolated?(str) str.match(/\#{/) end |
#link_to?(txt) ⇒ Boolean
48 49 50 |
# File 'lib/haml-i18n-extractor/helpers.rb', line 48 def link_to?(txt) txt.match(/link_to/) || txt.match(/^\s*['"]/) # %element= 'foo' end |
#normalize_interpolation(str) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/haml-i18n-extractor/helpers.rb', line 23 def normalize_interpolation(str) ret = change_one_interpolation(str) if ret && interpolated?(ret) ret = normalize_interpolation(ret) end ret end |
#normalized_name(str) ⇒ Object
17 18 19 20 21 |
# File 'lib/haml-i18n-extractor/helpers.rb', line 17 def normalized_name(str) NOT_ALLOWED_IN_KEYNAME.each{ |rm_me| str.gsub!(rm_me, "") } str = str.gsub(/\s+/, " ").strip str.downcase.tr(' ', '_')[0..LIMIT_KEY_NAME-1] end |