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