Class: Inkcite::Renderer::Footnote
- Defined in:
- lib/inkcite/renderer/footnote.rb
Defined Under Namespace
Classes: Instance
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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/inkcite/renderer/footnote.rb', line 57 def render tag, opt, ctx # Grab the optional id for this footnote. This would only be # populated if the designer intends on referencing this footnote # in multiple spots. id = opt[:id] || opt[:name] # If an id was specified, check to see if an existing footnote has # already been associated with this. instance = ctx.footnotes.detect { |f| f.id == id } unless id.blank? unless instance # Grab the optional symbol that was specified by the designer. If # this isn't specified count the number of existing numeric footnotes # and increment it for this new footnote's symbol. symbol = opt[:symbol] # Grab the text associated with this footnote. text = opt[:text] if text.blank? ctx.error("Footnote requires text attribute", { :id => id, :symbol => symbol }) return end # Create a new Footnote instance instance = Instance.new(id, symbol, text) # Push the new footnote onto the stack. ctx.footnotes << instance end # Check to see if the footnote's symbol is blank (either because one # wasn't defined in the source.html or because the one read from the # footnotes.tsv had no symbol associated with it) and if so, generate # one based on the number of previously declared numeric footnotes. if instance.symbol.blank? # Grab the last numeric footnote that was specified and, assuming # there is one, increment the count. Otherwise, start the count # off at one. last_instance = ctx.footnotes.select { |fn| fn.numeric? && fn.active? }.collect(&:number).max.to_i instance.symbol = last_instance + 1 end # Make sure the instance is marked as having been used so it will # appear in the {footnotes} rendering. instance.active = true # Allow footnotes to be defined without showing a symbol hidden = opt[:hidden] || (opt[:hidden] == '1') "#{instance.symbol}" unless hidden end |