Class: Card::Layout::CardLayout

Inherits:
Card::Layout show all
Defined in:
mod/standard/lib/card/layout/card_layout.rb

Overview

Layout based on a card's content

Constant Summary collapse

MAIN_NESTING_LIMIT =
5

Instance Method Summary collapse

Methods inherited from Card::Layout

built_in_layouts, built_in_layouts_hash, card_layout?, clear_cache, code_layout?, deregister_layout, #initialize, layout_class, layout_key, layouts, #main_nest_opts, main_nest_opts, register_built_in_layout, register_layout, register_layout_with_nest, render

Constructor Details

This class inherits a constructor from Card::Layout

Instance Method Details

#fetch_main_nest_optsObject



13
14
15
16
17
18
# File 'mod/standard/lib/card/layout/card_layout.rb', line 13

def fetch_main_nest_opts
  main_nest = find_main_nest_chunk
  # don't .& me !! (can be false)
  (main_nest && main_nest.options) ||
    raise(Card::Error, "no main nest found in layout \"#{@layout}\"")
end

#find_main_nest_chunk(card = layout_card, depth = 0) ⇒ Object



22
23
24
25
26
27
# File 'mod/standard/lib/card/layout/card_layout.rb', line 22

def find_main_nest_chunk card=layout_card, depth=0
  content = Card::Content.new(card.content, @format, chunk_list: :nest_only)
  return false unless content.each_chunk.count.positive?

  main_chunk(content) || go_deeper(content, depth)
end

#go_deeper(content, depth) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'mod/standard/lib/card/layout/card_layout.rb', line 29

def go_deeper content, depth
  return false if depth > MAIN_NESTING_LIMIT

  content.each_chunk do |chunk|
    main_chunk = find_main_nest_chunk chunk.referee_card, depth + 1
    return main_chunk if main_chunk
  end
  false
end

#layout_cardObject



5
6
7
# File 'mod/standard/lib/card/layout/card_layout.rb', line 5

def layout_card
  @layout_card ||= Card.quick_fetch @layout
end

#main_chunk(content) ⇒ Object



39
40
41
# File 'mod/standard/lib/card/layout/card_layout.rb', line 39

def main_chunk content
  content.each_chunk.find(&:main?)
end

#renderObject



9
10
11
# File 'mod/standard/lib/card/layout/card_layout.rb', line 9

def render
  @format.process_content layout_card.content, chunk_list: :references
end