Class: Occams::Cms::Layout
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Occams::Cms::Layout
- Defined in:
- app/models/occams/cms/layout.rb
Class Method Summary collapse
-
.app_layouts_for_select(view_paths) ⇒ Object
List of available application layouts.
-
.options_for_select(site, current_layout = nil) ⇒ 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
54 55 56 57 58 59 60 61 |
# File 'app/models/occams/cms/layout.rb', line 54 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, current_layout = nil) ⇒ Object
– Class Methods ———————————————————– Tree-like structure for layouts
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/occams/cms/layout.rb', line 33 def self.(site, current_layout = nil) = [] = ->(layout, depth = 0) do return if layout == current_layout << ["#{'. . ' * depth}#{layout.label}", layout.id] layout.children.order(:position).each do |child_layout| .call(child_layout, depth + 1) end end site.layouts.roots.order(:position).each do |layout| .call(layout) end end |
Instance Method Details
#cache_buster ⇒ Object
92 93 94 |
# File 'app/models/occams/cms/layout.rb', line 92 def cache_buster updated_at.to_i end |
#clear_page_content_cache ⇒ Object
Forcing page content reload
97 98 99 100 |
# File 'app/models/occams/cms/layout.rb', line 97 def clear_page_content_cache Occams::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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/occams/cms/layout.rb', line 67 def content_tokens renderer = Occams::Content::Renderer.new(nil) tokens = renderer.tokenize(content) if parent = Occams::Content::Tags::Fragment.subclasses.map do |c| Occams::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 |