Class: BlueberryCMS::Page

Inherits:
Object
  • Object
show all
Includes:
Sortable, Mongoid::Document, Mongoid::Slug, Mongoid::Tree, Mongoid::Tree::Ordering, Mongoid::Tree::Traversal
Defined in:
app/models/blueberry_cms/page.rb

Instance Method Summary collapse

Instance Method Details

#name_translations=(attributes) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/blueberry_cms/page.rb', line 64

def name_translations=(attributes)
  attributes.stringify_keys!
  primary_locale_name = attributes[I18n.default_locale.to_s]
  empty_locale_keys   = attributes.select { |_, v| v.blank? || v.empty? }.keys

  empty_locale_keys.each do |locale|
    attributes[locale] = primary_locale_name
  end

  super
end

#rebuild_children_pathsObject



54
55
56
57
58
# File 'app/models/blueberry_cms/page.rb', line 54

def rebuild_children_paths
  if %i[custom_slug name].any? { |f| attribute_changed? f.to_s }
    children.each(&:save)
  end
end

#slug_sourceObject



49
50
51
52
# File 'app/models/blueberry_cms/page.rb', line 49

def slug_source
  renderer = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
  renderer.render(custom_slug.presence || name.presence || '').squish
end

#to_pathObject



60
61
62
# File 'app/models/blueberry_cms/page.rb', line 60

def to_path
  BlueberryCMS.force_locale ? "/#{I18n.locale}#{path}" : path
end