Class: Sitepress::Extensions::Layouts

Inherits:
Object
  • Object
show all
Defined in:
lib/sitepress/extensions/layouts.rb

Overview

Register layouts with resources that match certain patterns.

Defined Under Namespace

Classes: Rule

Instance Method Summary collapse

Constructor Details

#initializeLayouts

Returns a new instance of Layouts.



7
8
9
# File 'lib/sitepress/extensions/layouts.rb', line 7

def initialize
  @rules = Array.new
end

Instance Method Details

#layout(layout, &block) ⇒ Object

Register a layout for a set of resources.



12
13
14
# File 'lib/sitepress/extensions/layouts.rb', line 12

def layout(layout, &block)
  @rules << Rule.new(layout, block)
end

#process_resources(node) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/sitepress/extensions/layouts.rb', line 16

def process_resources(node)
  node.resources.flatten.each do |resource|
    @rules.each do |rule|
      if rule.processor.call(resource)
        resource.data["layout"] ||= rule.layout
      end
    end
  end
end