Class: Inkcite::Renderer::Button

Inherits:
Base
  • Object
show all
Defined in:
lib/inkcite/renderer/button.rb

Defined Under Namespace

Classes: Config

Constant Summary

Constants inherited from Base

Inkcite::Renderer::Base::BACKGROUND_COLOR, Inkcite::Renderer::Base::BACKGROUND_GRADIENT, Inkcite::Renderer::Base::BACKGROUND_IMAGE, Inkcite::Renderer::Base::BACKGROUND_POSITION, Inkcite::Renderer::Base::BACKGROUND_REPEAT, Inkcite::Renderer::Base::BACKGROUND_SIZE, Inkcite::Renderer::Base::BORDER_BOTTOM, Inkcite::Renderer::Base::BORDER_COLLAPSE, Inkcite::Renderer::Base::BORDER_LEFT, Inkcite::Renderer::Base::BORDER_RADIUS, Inkcite::Renderer::Base::BORDER_RIGHT, Inkcite::Renderer::Base::BORDER_SPACING, Inkcite::Renderer::Base::BORDER_TOP, Inkcite::Renderer::Base::BOX_SHADOW, Inkcite::Renderer::Base::DIMENSIONS, Inkcite::Renderer::Base::DIRECTIONS, Inkcite::Renderer::Base::FONT_FAMILY, Inkcite::Renderer::Base::FONT_SIZE, Inkcite::Renderer::Base::FONT_WEIGHT, Inkcite::Renderer::Base::LETTER_SPACING, Inkcite::Renderer::Base::LINE_HEIGHT, Inkcite::Renderer::Base::LINK_COLOR, Inkcite::Renderer::Base::MARGIN, Inkcite::Renderer::Base::MARGIN_BOTTOM, Inkcite::Renderer::Base::MARGIN_LEFT, Inkcite::Renderer::Base::MARGIN_RIGHT, Inkcite::Renderer::Base::MARGIN_TOP, Inkcite::Renderer::Base::MAX_WIDTH, Inkcite::Renderer::Base::NONE, Inkcite::Renderer::Base::PADDING_X, Inkcite::Renderer::Base::PADDING_Y, Inkcite::Renderer::Base::POUND_SIGN, Inkcite::Renderer::Base::TEXT_ALIGN, Inkcite::Renderer::Base::TEXT_DECORATION, Inkcite::Renderer::Base::TEXT_SHADOW, Inkcite::Renderer::Base::TEXT_SHADOW_BLUR, Inkcite::Renderer::Base::TEXT_SHADOW_OFFSET, Inkcite::Renderer::Base::VERTICAL_ALIGN, Inkcite::Renderer::Base::WEBKIT_ANIMATION, Inkcite::Renderer::Base::WHITE_SPACE, Inkcite::Renderer::Base::ZERO_WIDTH_NON_BREAKING_SPACE, Inkcite::Renderer::Base::ZERO_WIDTH_SPACE

Instance Method Summary collapse

Instance Method Details

#render(tag, opt, ctx) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/inkcite/renderer/button.rb', line 116

def render tag, opt, ctx

  html = ''

  if tag == 'button'

    id = opt[:id]
    href = opt[:href]

    cfg = Config.new(ctx, opt)

    # Wrap the table in a link to make the whole thing clickable.  This works
    # in most email clients but doesn't work in Outlook (for a change).
    html << "{a id=\"#{id}\" href=\"#{href}\" color=\"none\"}"

    # Responsive button is just a highly styled table/td combination with optional
    # curved corners and a lower bevel (border).
    bgcolor = cfg.bgcolor
    html << '{table'
    html << %Q( bgcolor="#{bgcolor}") unless bgcolor.blank?
    html << " padding=#{cfg.padding}" if cfg.padding > 0
    html << %Q( border="#{cfg.border}") if cfg.border
    html << " border-radius=#{cfg.border_radius}" if cfg.border_radius > 0
    html << %Q( border-bottom="#{cfg.border_bottom}") if cfg.bevel > 0

    # Need to separate borders that are collapsed by default - otherwise, the bevel
    # renders incorrectly.
    html << ' border-collapse=separate' if cfg.border || cfg.bevel > 0

    html << " margin-top=#{cfg.margin_top}" if cfg.margin_top > 0
    html << " width=#{cfg.width}" if cfg.width > 0
    html << " float=#{cfg.float}" if cfg.float
    html << %Q( mobile="fill"}\n)
    html << "{td align=center"
    html << " height=#{cfg.height} valign=middle" if cfg.height > 0
    html << " font=\"#{cfg.font}\""
    html << " line-height=#{cfg.line_height}" unless cfg.line_height.blank?
    html << %Q( font-size="#{cfg.font_size}") if cfg.font_size > 0
    html << %Q( font-weight="#{cfg.font_weight}") unless cfg.font_weight.blank?

    # Text on the button gets a shadow automatically unless the shadow
    # color matches the background color of the button.
    shadow = cfg.text_shadow
    html << %Q( shadow="#{shadow}" shadow-offset=-1) if shadow != bgcolor

    html << '}'

    # Second, internal link for Outlook users that makes the inside of the button
    # clickable.
    html << %Q({a id="#{id}" href="#{href}" color="#{cfg.color}")
    html << %Q( letter-spacing="#{cfg.letter_spacing}") unless cfg.letter_spacing.blank?
    html << %q(})


  else

    html << "{/a}{/td}\n{/table}{/a}"

  end

  html
end