Module: Locomotive::Concerns::Page::Layout

Extended by:
ActiveSupport::Concern
Included in:
Page
Defined in:
app/models/locomotive/concerns/page/layout.rb

Constant Summary collapse

IS_LAYOUT_REGEX =
/^layouts($|\/)/o.freeze
EXTENDS_REGEX =
/\{%\s+extends\s/o.freeze
EXTENDS_PARENT_REGEX =
/\{%\s+extends\s"?parent"?\s%}/o.freeze
EXTENDS_FULLPATH_REGEX =
/\{%\s+extends\s"?(\S+)"?\s%}/o.freeze
BLOCK_REGEX =
/\{%\s+block\s/o.freeze

Instance Method Summary collapse

Instance Method Details

#find_layoutObject

The layout is also defined in the raw_template. The UI needs it in order to select the layout in the layouts dropdown menu



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/locomotive/concerns/page/layout.rb', line 47

def find_layout
  return if !self.allow_layout? || self.layout_id

  if self.raw_template =~ EXTENDS_FULLPATH_REGEX
    # first in the current locale
    if (page = self.site.pages.fullpath($1).first).nil? && !self.site.is_default_locale?(::Mongoid::Fields::I18n.locale)
      # give it a try in the default locale too
      page = self.site.with_default_locale { self.site.pages.fullpath($1).first }
    end

    self.layout_id = page.try(:_id)
  end
end

#is_layout_or_related?Boolean

Returns:



37
38
39
# File 'app/models/locomotive/concerns/page/layout.rb', line 37

def is_layout_or_related?
  !(self.fullpath =~ IS_LAYOUT_REGEX).nil?
end

#use_layout?Boolean

Returns:



41
42
43
# File 'app/models/locomotive/concerns/page/layout.rb', line 41

def use_layout?
  !(self.raw_template =~ EXTENDS_REGEX).nil?
end