Class: ExtractI18n::Slimkeyfy::Whitespacer
- Inherits:
-
Object
- Object
- ExtractI18n::Slimkeyfy::Whitespacer
- Defined in:
- lib/extract_i18n/slimkeyfy/whitespacer.rb
Constant Summary collapse
- HTML =
/([a-z\.]+[0-9\-]*)+/.freeze
- HTML_TAGS =
/^(?<html_tag>'|\||#{HTML})/.freeze
Class Method Summary collapse
- .convert_nbsp(body, tag) ⇒ Object
- .convert_slim(string) ⇒ Object
- .has_equals_tag?(string, html_tag) ⇒ Boolean
- .leading_nbsp(body) ⇒ Object
- .trailing_nsbp(body, tag) ⇒ Object
Class Method Details
.convert_nbsp(body, tag) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/extract_i18n/slimkeyfy/whitespacer.rb', line 25 def self.convert_nbsp(body, tag) lead = leading_nbsp(body) trail = trailing_nsbp(body, tag) tag = tag.gsub(tag, "#{tag}#{lead}#{trail}") [body.sub(/^ /, '').sub(/ $/, '').gsub(" ", " "), tag.gsub("=><", "=<>")] end |
.convert_slim(string) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/extract_i18n/slimkeyfy/whitespacer.rb', line 8 def self.convert_slim(string) m = string.match(HTML_TAGS) return string if m.nil? or m[:html_tag].nil? return string if has_equals_tag?(string, m[:html_tag]) tag = m[:html_tag] case tag when /\|/ string.gsub("|", "=") when /\'/ string.gsub("'", "=>") when HTML string.gsub(string, "#{string} =") else string end end |
.has_equals_tag?(string, html_tag) ⇒ Boolean
42 43 44 |
# File 'lib/extract_i18n/slimkeyfy/whitespacer.rb', line 42 def self.has_equals_tag?(string, html_tag) string.gsub(html_tag, "").strip.start_with?("=") end |
.leading_nbsp(body) ⇒ Object
33 34 35 |
# File 'lib/extract_i18n/slimkeyfy/whitespacer.rb', line 33 def self.leading_nbsp(body) return "<" if body.start_with?(" ") end |
.trailing_nsbp(body, tag) ⇒ Object
37 38 39 40 |
# File 'lib/extract_i18n/slimkeyfy/whitespacer.rb', line 37 def self.trailing_nsbp(body, tag) return '' if tag.start_with?("=>") return ">" if body.end_with?(" ") end |