Skip to content

Commit

Permalink
fix issue with default template
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Jul 30, 2015
1 parent 5fc1954 commit f548119
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
24 changes: 20 additions & 4 deletions app/models/locomotive/concerns/page/layout.rb
Expand Up @@ -16,7 +16,7 @@ module Layout
has_many :layout_children, class_name: 'Locomotive::Page', inverse_of: :layout

## callbacks ##
before_validation :set_default_raw_template_if_layout
before_validation :set_default_raw_template

## scopes ##
scope :layouts, -> { where(is_layout: true) }
Expand All @@ -29,14 +29,30 @@ def is_layout_or_related?

private

def set_default_raw_template_if_layout
return true unless self.allow_layout?
def set_default_raw_template
if self.allow_layout?
set_default_raw_template_if_layout
else
set_default_raw_template_if_no_layout
end
end

def set_default_raw_template_if_layout
if self.layout
self.raw_template = %({% extends "#{self.layout.fullpath}" %})
elsif self.layout_id_was
# use case: layout -> no layout
self.raw_template = nil
self.raw_template = nil # FIXME: not sure about that
end
end

def set_default_raw_template_if_no_layout
return true if self.raw_template.present?

self.raw_template = if self.index? || !self.site.is_default_locale?(::Mongoid::Fields::I18n.locale.to_s)
''
else
"{% extends 'parent' %}"
end
end

Expand Down
15 changes: 0 additions & 15 deletions app/models/locomotive/page.rb
Expand Up @@ -39,7 +39,6 @@ class Page
slugify_from :title

## callbacks ##
after_initialize :set_default_raw_template
before_create :localize_slug
before_create :build_fullpath
before_update :build_fullpath, unless: :skip_callbacks_on_update
Expand Down Expand Up @@ -120,20 +119,6 @@ def do_not_remove_index_and_404_pages
self.errors.empty?
end

def set_default_raw_template
begin
return true if self.raw_template.present?

self.raw_template = if self.index? || !self.site.is_default_locale?(::Mongoid::Fields::I18n.locale.to_s)
''
else
"{% extends 'parent' %}"
end
rescue ActiveModel::MissingAttributeError
# page not loaded from MongoDB without the raw_template attribute
end
end

# The slug of a new page should be the same in all
# the locales of a site.
def localize_slug
Expand Down

0 comments on commit f548119

Please sign in to comment.