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



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

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 = ''
    if top_class
      html += template('div', classes: "s-#{top_class.gsub(/m[ty]{1}-/, '')}", contents: nil)
    end
    html += node.to_html
    if bottom_class
      html += template('div', classes: "s-#{bottom_class.gsub(/m[by]{1}-/, '')}", contents: nil)
    end
    node.replace(html)
  end
end