Class: Comfy::Cms::Layout
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comfy::Cms::Layout
- Defined in:
- app/models/comfy/cms/layout.rb
Class Method Summary collapse
-
.app_layouts_for_select(view_paths) ⇒ 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
- #cache_buster ⇒ Object
-
#clear_page_content_cache ⇒ Object
Forcing page content reload.
-
#content_tokens ⇒ Object
– Instance Methods ——————————————————– Tokenized layout content that also pulls in parent layout (if there’s one) and merges on the content} tag (if parent layout has that).
Class Method Details
.app_layouts_for_select(view_paths) ⇒ Object
List of available application layouts
45 46 47 48 49 50 51 52 |
# File 'app/models/comfy/cms/layout.rb', line 45 def self.app_layouts_for_select(view_paths) view_paths.map(&:to_s).select { |path| path.start_with?(Rails.root.to_s) }.flat_map do |full_path| Dir.glob("#{full_path}/layouts/**/*.html.*").collect do |filename| filename.gsub!("#{full_path}/layouts/", "") filename.split("/").last[0...1] == "_" ? nil : filename.split(".").first end.compact.sort end.compact.uniq.sort end |
.options_for_select(site, layout = nil, current_layout = nil, depth = 0, spacer = ". . ") ⇒ Object
– Class Methods ———————————————————– Tree-like structure for layouts
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/comfy/cms/layout.rb', line 32 def self.(site, layout = nil, current_layout = nil, depth = 0, spacer = ". . ") out = [] [current_layout || site.layouts.roots.order(:position)].flatten.each do |l| next if layout == l out << ["#{spacer * depth}#{l.label}", l.id] l.children.order(:position).each do |child| out += (site, layout, child, depth + 1, spacer) end end out.compact end |
Instance Method Details
#cache_buster ⇒ Object
83 84 85 |
# File 'app/models/comfy/cms/layout.rb', line 83 def cache_buster updated_at.to_i end |
#clear_page_content_cache ⇒ Object
Forcing page content reload
88 89 90 91 |
# File 'app/models/comfy/cms/layout.rb', line 88 def clear_page_content_cache Comfy::Cms::Page.where(id: pages.pluck(:id)).update_all(content_cache: nil) children.each(&:clear_page_content_cache) end |
#content_tokens ⇒ Object
– Instance Methods ——————————————————– Tokenized layout content that also pulls in parent layout (if there’s one) and merges on the content} tag (if parent layout has that). Returns a list of tokens that can be fed into the renderer.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/comfy/cms/layout.rb', line 58 def content_tokens renderer = ComfortableMexicanSofa::Content::Renderer.new(nil) tokens = renderer.tokenize(content) if parent = ComfortableMexicanSofa::Content::Tag::Fragment.subclasses.map do |c| ComfortableMexicanSofa::Content::Renderer..key(c) end parent_tokens = parent.content_tokens replacement_position = parent_tokens.index do |n| n.is_a?(Hash) && .member?(n[:tag_class]) && n[:tag_params].split(%r{\s}).first == "content" end if replacement_position parent_tokens[replacement_position] = tokens tokens = parent_tokens.flatten end end tokens end |