Module: Flutterby::Layout

Extended by:
Layout
Included in:
Layout
Defined in:
lib/flutterby/layout.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collect_layouts(node, list: nil, include_tree: true) ⇒ 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
# File 'lib/flutterby/layout.rb', line 5

def collect_layouts(node, list: nil, include_tree: true)
  layouts = []
  list ||= node.layout

  # Collect layouts explicitly configured for node
  if defined? list
    Array(list).each do |sel|
      # If a false is explicity specified, that's all the layouts
      # we're expected to render
      return layouts if sel == false

      if layout = node.find(sel)
        layouts << layout
      else
        raise "No layout found for path expression '#{sel}'"
      end
    end
  end

  if include_tree
    # Decide on a starting node for walking the tree upwards
    start = layouts.any? ? layouts.last.parent : node

    # Walk the tree up, collecting any layout files found on our way
    TreeWalker.walk_up(start) do |n|
      if layout = n.sibling("_layout")
        layouts << layout
      end
    end
  end

  layouts
end

Instance Method Details

#collect_layouts(node, list: nil, include_tree: true) ⇒ 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
# File 'lib/flutterby/layout.rb', line 5

def collect_layouts(node, list: nil, include_tree: true)
  layouts = []
  list ||= node.layout

  # Collect layouts explicitly configured for node
  if defined? list
    Array(list).each do |sel|
      # If a false is explicity specified, that's all the layouts
      # we're expected to render
      return layouts if sel == false

      if layout = node.find(sel)
        layouts << layout
      else
        raise "No layout found for path expression '#{sel}'"
      end
    end
  end

  if include_tree
    # Decide on a starting node for walking the tree upwards
    start = layouts.any? ? layouts.last.parent : node

    # Walk the tree up, collecting any layout files found on our way
    TreeWalker.walk_up(start) do |n|
      if layout = n.sibling("_layout")
        layouts << layout
      end
    end
  end

  layouts
end