Class: Inkcite::Renderer::Property

Inherits:
Base
  • Object
show all
Defined in:
lib/inkcite/renderer/property.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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/inkcite/renderer/property.rb', line 5

def render tag, opt, ctx

  html = ctx[tag]
  if html.nil?
    ctx.error 'Unknown tag or property', { :tag => tag, :opt => "[#{opt.to_query}]" }
    return nil
  end

  # True if this is a opening tag - e.g. {feature ...}, not {/feature}
  is_open_tag = !tag.starts_with?(SLASH)

  # When a custom opening tag is encountered, if there is a corresponding
  # closing tag, we'll save the options provided at open so that they
  # can be pop'd by the closing tag and used in the closing HTML.
  if is_open_tag

    # Verify that a closing tag has been defined and push the opts
    # onto the stack.  No need to push opts and pollute the stack if
    # there is no closing tag to take advantage of them.
    close_tag = "#{SLASH}#{tag}"
    ctx.tag_stack(tag) << opt unless ctx[close_tag].nil?

  else

    # Chop off the forward slash to reveal the original open tag.  Then
    # grab the tag stack for said open tag.  Pop the most recently provided
    # opts off the stack so those values are available again.
    open_tag = tag[1..-1]
    tag_stack = ctx.tag_stack(open_tag)

    # The provided opts take precedence over the ones passed to the open tag.
    if tag_stack

      # Need to verify that there are open opts to pop - if a tag is closed that
      # hasn't been opened (e.g. {h3}...{/h2}) the open_opt can be nil.
      open_opt = tag_stack.pop
      opt = open_opt.merge(opt) if open_opt

    end

  end

  # Need to clone the property - otherwise, we modify the original property.
  # Which is bad.
  html = html.clone

  Parser.each html, VARIABLE_REGEX do |pair|

    # Split the declaration on the equals sign.
    variable, default = pair.split(EQUALS, 2)

    # Check to see if the variable has been defined in the parameters.  If so, use that
    # value - otherwise, inherit the default.
    (opt[variable.to_sym] || default).to_s

  end

end