Class: Cms::Layout
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cms::Layout
- Defined in:
- app/models/cms/layout.rb
Class Method Summary collapse
-
.app_layouts_for_select ⇒ Object
List of available application layouts.
-
.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = '. . ') ⇒ Object
– Class Methods ——————————————————– Tree-like structure for layouts.
Instance Method Summary collapse
-
#merged_content ⇒ Object
– Instance Methods —————————————————– magical merging tag is cms:page:content If parent layout has this tag defined its content will be merged.
Class Method Details
.app_layouts_for_select ⇒ Object
List of available application layouts
57 58 59 60 61 62 |
# File 'app/models/cms/layout.rb', line 57 def self.app_layouts_for_select Dir.glob(File.('app/views/layouts/**/*.html.*', Rails.root)).collect do |filename| filename.gsub!("#{File.('app/views/layouts', Rails.root)}/", '') filename.split('/').last[0...1] == '_' ? nil : filename.split('.').first end.compact.sort end |
.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = '. . ') ⇒ Object
– Class Methods ——————————————————– Tree-like structure for layouts
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/cms/layout.rb', line 44 def self.(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 += (site, layout, child, depth + 1, spacer) end end return out.compact end |
Instance Method Details
#merged_content ⇒ Object
– 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.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/cms/layout.rb', line 68 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.to_s end else content.to_s end end |