Class: PrawnHtml::Tags::Ul

Inherits:
PrawnHtml::Tag show all
Defined in:
lib/prawn_html/tags/ul.rb

Constant Summary collapse

ELEMENTS =
[:ul].freeze
MARGIN_TOP =
15
MARGIN_LEFT =
40
MARGIN_BOTTOM =
15

Constants inherited from PrawnHtml::Tag

PrawnHtml::Tag::CALLBACKS, PrawnHtml::Tag::TAG_CLASSES

Instance Attribute Summary

Attributes inherited from PrawnHtml::Tag

#attrs, #parent, #tag

Instance Method Summary collapse

Methods inherited from PrawnHtml::Tag

#block_styles, class_for, #process_styles, #tag_close_styles, #tag_open_styles

Constructor Details

#initialize(tag, attributes: {}, options: {}) ⇒ Ul

Returns a new instance of Ul.



12
13
14
15
# File 'lib/prawn_html/tags/ul.rb', line 12

def initialize(tag, attributes: {}, options: {})
  super
  @first_level = false
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/prawn_html/tags/ul.rb', line 17

def block?
  true
end

#on_context_add(context) ⇒ Object



21
22
23
24
25
# File 'lib/prawn_html/tags/ul.rb', line 21

def on_context_add(context)
  return if context.map(&:tag).count { |el| el == :ul } > 1

  @first_level = true
end

#tag_stylesObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prawn_html/tags/ul.rb', line 27

def tag_styles
  if @first_level
    <<~STYLES
      margin-top: #{MARGIN_TOP}px;
      margin-left: #{MARGIN_LEFT}px;
      margin-bottom: #{MARGIN_BOTTOM}px;
    STYLES
  else
    "margin-left: #{MARGIN_LEFT}px"
  end
end