Class: BootstrapEmail::Converter::Margin

Inherits:
Base
  • Object
show all
Defined in:
lib/bootstrap-email/converters/margin.rb

Instance Attribute Summary

Attributes inherited from Base

#doc

Instance Method Summary collapse

Methods inherited from Base

build, #initialize

Constructor Details

This class inherits a constructor from BootstrapEmail::Converter::Base

Instance Method Details

#buildObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bootstrap-email/converters/margin.rb', line 6

def build
  each_node("*[class^='my-'], *[class^='mt-'], *[class^='mb-'], *[class*=' my-'], *[class*=' mt-'], *[class*=' mb-']") do |node|
    top_class = node['class'][/m[ty]{1}-(lg-)?(\d+)/]
    bottom_class = node['class'][/m[by]{1}-(lg-)?(\d+)/]
    node['class'] = node['class'].gsub(/(m[tby]{1}-(lg-)?\d+)/, '').strip
    html = ''
    html += template('div', classes: "s-#{top_class.gsub(/m[ty]{1}-/, '')}", contents: nil) if top_class
    html += node.to_html
    html += template('div', classes: "s-#{bottom_class.gsub(/m[by]{1}-/, '')}", contents: nil) if bottom_class
    node.replace(html)
  end
end