Only one parser for front end
Separate site map for i18n
This commit is contained in:
1 parent
f1c628f2d6
commit
fcbba6660b
20 files changed
+445
-168
No files matched your search
+19
-2
@@ -11,7 +11,7 @@ class Item
|
||||
field :enabled_for, :type => Array, :default => nil
|
||||
field :menu_enabled_for, :type => Array, :default => nil
|
||||
field :title, localize: true
|
||||
field :sitemap_enabled, :type => Boolean, :default => true
|
||||
field :sitemap_enabled, :type => Hash
|
||||
|
||||
|
||||
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
||||
@@ -53,12 +53,29 @@ class Item
|
||||
save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show_in_sitemap_for(locale)
|
||||
if !sitemap_enabled[locale].blank?
|
||||
sitemap_enabled[locale].eql?('true') ? true : false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def rebuild_path
|
||||
self.path = (self.ancestors_and_self - [Item.root]).collect{|x| x.name unless x.root?}.join('/')
|
||||
self.rebuild_children_path
|
||||
end
|
||||
|
||||
def rebuild_children_path
|
||||
self.children.each do |child|
|
||||
child.path = (child.ancestors_and_self - [Item.root]).collect{|x| x.name}.join('/')
|
||||
child.save
|
||||
child.rebuild_children_path
|
||||
end
|
||||
end
|
||||
|
||||
def find_by_parent_and_position(parent, position)
|
||||
|
||||
+30
-27
@@ -1,9 +1,11 @@
|
||||
class Page < Item
|
||||
include Rails.application.routes.url_helpers
|
||||
include Impressionist::Impressionable
|
||||
include ParserFrontEnd
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
field :content
|
||||
field :content, localize: true
|
||||
field :app_frontend_url
|
||||
field :theme_id, :type => BSON::ObjectId, :default => nil
|
||||
field :category, :default => ''
|
||||
@@ -17,40 +19,34 @@ class Page < Item
|
||||
|
||||
belongs_to :design
|
||||
belongs_to :module_app
|
||||
has_many :page_parts, :autosave => true, :dependent => :destroy
|
||||
has_many :page_parts, :dependent => :destroy
|
||||
has_many :page_contexts, :autosave => true, :dependent => :destroy
|
||||
has_many :page_metas, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
||||
|
||||
before_save :create_parts, :delete_empty_frontend_field
|
||||
|
||||
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
||||
|
||||
def generate_parts
|
||||
page_design = self.design
|
||||
page_design.layout.layout_parts.each do |layout_part|
|
||||
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
||||
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
||||
current_part.save if current_part.new_record?
|
||||
end
|
||||
end
|
||||
before_save :delete_empty_frontend_field
|
||||
before_save :create_parts, if: Proc.new { |page| page.new_record? || page.design_id_changed? }
|
||||
after_save :generate_html
|
||||
|
||||
protected
|
||||
|
||||
def create_parts
|
||||
if self.new_record? || self.design_id_changed?
|
||||
page_design = self.design
|
||||
parent = self.parent
|
||||
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
|
||||
page_design.layout.layout_parts.each do |layout_part|
|
||||
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
||||
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
||||
if menu_part && current_part.name.eql?(menu_part.name)
|
||||
if current_part.new_record?
|
||||
current_part.kind = menu_part.kind
|
||||
current_part.public_r_tag = menu_part.public_r_tag
|
||||
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
|
||||
else
|
||||
page_design = self.design
|
||||
parent = self.parent
|
||||
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
|
||||
page_design.layout.layout_parts.each do |layout_part|
|
||||
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
||||
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
||||
if menu_part && current_part.name.eql?(menu_part.name)
|
||||
if current_part.new_record?
|
||||
current_part.kind = menu_part.kind
|
||||
current_part.public_r_tag = menu_part.public_r_tag
|
||||
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
|
||||
PagePart.without_callback(:save, :after, :update_parent) do
|
||||
current_part.save
|
||||
end
|
||||
else
|
||||
PagePart.without_callback(:save, :after, :update_parent) do
|
||||
current_part.update_attributes(:kind => menu_part.kind, :public_r_tag => menu_part.public_r_tag, :public_r_tag_object_id => menu_part.public_r_tag_object_id)
|
||||
end
|
||||
end
|
||||
@@ -69,5 +65,12 @@ class Page < Item
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
def generate_html
|
||||
Page.without_callback(:save, :after, :generate_html) do
|
||||
self.content_translations = parse_page_noko(self, Site.first)
|
||||
self.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -20,6 +20,7 @@ class PagePart
|
||||
belongs_to :module_app
|
||||
|
||||
before_save :delete_empty_widget_field
|
||||
after_save :update_parent
|
||||
|
||||
protected
|
||||
|
||||
@@ -30,4 +31,8 @@ class PagePart
|
||||
# self.widget_field.delete("") if self.widget_field
|
||||
end
|
||||
|
||||
def update_parent
|
||||
self.page.save
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user