Class: Inkcite::Renderer::Footnotes

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

Constant Summary

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

Instance Method Details

#render(tag, opt, ctx) ⇒ Object



115
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
# File 'lib/inkcite/renderer/footnote.rb', line 115

def render tag, opt, ctx

  # Nothing to do if footnotes are blank.
  return if ctx.footnotes.blank?

  # Grab the active footnotes.
  active_footnotes = ctx.footnotes.select(&:active)
  return if active_footnotes.blank?

  # Check to see if a template has been provided.  Otherwise use a default one based
  # on the format of the email.
  tmpl = opt[:tmpl] || opt[:template]
  if tmpl.blank?
    tmpl = ctx.text? ? "($symbol$) $text$\n\n" : "<sup>$symbol$</sup> $text$<br><br>"

  elsif ctx.text?

    # If there are new-lines encoded in the custom template, make sure
    # they get converted to real new lines.
    tmpl.gsub!('\\n', "\n")

  end

  # For the emailed version, append a line break between each footnote so that we don't
  # end up with lines that exceed the allowed limit in certain versions of Outlook.
  tmpl << "\n" if ctx.email?

  # First, collect all symbols in the natural order they are defined
  # in the email.
  footnotes = active_footnotes.select(&:symbol?)

  # Now add to the list all numeric footnotes ordered naturally
  # regardless of how they were ordered in the email.
  footnotes += active_footnotes.select(&:numeric?).sort { |f1, f2| f1.number <=> f2.number }

  html = ''

  # Iterate through each of the footnotes and render them based on the
  # template that was provided.
  footnotes.each do |f|
    html << tmpl.gsub('$symbol$', f.symbol).gsub('$text$', f.text)
  end

  html
end