Class: Inkcite::Renderer::SpecialEffect

Inherits:
ContainerBase show all
Defined in:
lib/inkcite/renderer/special_effect.rb

Direct Known Subclasses

Snow, Sparkle

Defined Under Namespace

Classes: EffectContext

Constant Summary

Constants inherited from Responsive

Responsive::BUTTON, Responsive::DROP, Responsive::FILL, Responsive::FLUID, Responsive::FLUID_DROP, Responsive::FLUID_STACK, Responsive::HIDE, Responsive::IMAGE, Responsive::MOBILE_BACKGROUND, Responsive::MOBILE_BACKGROUND_COLOR, Responsive::MOBILE_BACKGROUND_IMAGE, Responsive::MOBILE_BACKGROUND_POSITION, Responsive::MOBILE_BACKGROUND_REPEAT, Responsive::MOBILE_BACKGROUND_SIZE, Responsive::MOBILE_BGCOLOR, Responsive::MOBILE_PADDING, Responsive::MOBILE_SRC, Responsive::SHOW, Responsive::SHOW_INLINE, Responsive::SWITCH, Responsive::SWITCH_UP, Responsive::TOGGLE

Constants inherited from Base

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

Instance Method Summary collapse

Methods inherited from Responsive

presets

Instance Method Details

#render(tag, opt, ctx) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/inkcite/renderer/special_effect.rb', line 204

def render tag, opt, ctx

  # If the closing tag was received (e.g. /snow) then close the wrapper
  # div that was rendered by the opening tag.
  return '</div>' if tag.start_with?('/')

  # Retrieve the special effects default values (times, number of units, etc.)
  _defaults = defaults(opt, ctx)

  # Create a special effects context that simplifies working with the
  # opts, defaults and manages the styles/classes necessary to animate
  # the special effect.
  sfx = EffectContext.new(tag, opt, ctx, _defaults)

  # Provide the extending class with an opportunity to configure the
  # effect context prior to any rendering.
  config_effect_context sfx

  html = []
  styles = []

  # If this is the first special effect to be included in the email
  # we need to disable the CSS animation from Gmail - which only
  # accepts part of its <styles> leading to unexpected whitespace.
  # By putting this invalid CSS into the <style> block, Gmail's
  # very strict parser will exclude the entire block, preventing
  # the animation from running.
  # https://emails.hteumeuleu.com/troubleshooting-gmails-responsive-design-support-ad124178bf81#.8jh1vn9mw
  if ctx.email? && sfx.uuid == 1
    styles << Inkcite::Renderer::Style.new(".gmail-fix", sfx.ctx, { FONT_SIZE => '3*px' })
  end

  # Create the <div> that wraps the entire animation.
  create_wrap_element html, sfx

  # Create the Style that defines the look of the wrapping container
  create_wrap_style styles, sfx

  # Create the Style that is applied to all children in the animation.
  create_all_children_style styles, sfx

  # Now create each of the child elements (e.g. the snowflakes) that
  # will be animated in this effect.  Each child is created and animated
  # at the same time.
  create_child_elements html, styles, sfx

  # Push the completed list of styles into the context's stack.
  ctx.styles << styles.join("\n")

  html.join("\n")

end