Sha256: 3d435c1d21473b668d90633a82033431fbb630d4afc458353f29bcf02f594d7c

Contents?: true

Size: 1005 Bytes

Versions: 3

Compression:

Stored size: 1005 Bytes

Contents

module Flutterby
  module Layout
    extend self

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flutterby-0.6.2 lib/flutterby/layout.rb
flutterby-0.6.1 lib/flutterby/layout.rb
flutterby-0.6.0 lib/flutterby/layout.rb