Class: Cms::Layout

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/cms/layout.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_layouts_for_selectObject

List of available application layouts



43
44
45
46
47
48
49
# File 'app/models/cms/layout.rb', line 43

def self.app_layouts_for_select
  Dir.glob(File.expand_path('app/views/layouts/*.html.*', Rails.root)).collect do |filename|
    match = filename.match(/\w*.html.\w*$/)
    app_layout = match && match[0]
    app_layout.to_s[0...1] == '_' ? nil : app_layout
  end.compact
end

.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = '. . ') ⇒ Object

– Class Methods ——————————————————– Tree-like structure for layouts



30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/cms/layout.rb', line 30

def self.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = '. . ')
  out = []
  [current_layout || site.layouts.roots].flatten.each do |l|
    next if layout == l
    out << [ "#{spacer*depth}#{l.label}", l.id ]
    l.children.each do |child|
      out += options_for_select(site, layout, child, depth + 1, spacer)
    end
  end
  return out.compact
end

Instance Method Details

#merged_contentObject

– Instance Methods —————————————————– magical merging tag is cms:page:content If parent layout has this tag defined its content will be merged. If no such tag found, parent content is ignored.



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/cms/layout.rb', line 55

def merged_content
  if parent
    regex = /\{\{\s*cms:page:content:?(?:(?::text)|(?::rich_text))?\s*\}\}/
    if parent.merged_content.match(regex)
      parent.merged_content.gsub(regex, content.to_s)
    else
      content
    end
  else
    content
  end
end