Only one parser for front end

Separate site map for i18n
This commit is contained in:
chris committed 2012-12-19 17:15:31 +08:00
1 parent f1c628f2d6
commit fcbba6660b
20 files changed
+445 -168

No files matched your search

+1
View File
@@ -15,4 +15,5 @@
*= require scroll_style
*= require isotope
*= require icons
*= require site-map
*/
+4 -9
View File
@@ -1,8 +1,8 @@
class Admin::SitesController < ApplicationController
layout "new_admin"
before_filter :authenticate_user!, :except => [:sitemap_frontend]
before_filter :is_admin?, :except => [:sitemap_frontend]
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :get_site
# def index
@@ -31,18 +31,13 @@ class Admin::SitesController < ApplicationController
@items = get_homepage.children rescue []
end
def sitemap_frontend
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
render :layout => false
end
def sitemap_toggle
@item = Item.find(params[:id])
@item.sitemap_enabled = !@item.sitemap_enabled
@item.sitemap_enabled[params[:temp_locale]] = (!@item.show_in_sitemap_for(params[:temp_locale])).to_s
@item.save
if params[:parent]
@item.children.each do |child|
child.sitemap_enabled = @item.sitemap_enabled
child.sitemap_enabled[params[:temp_locale]] = @item.sitemap_enabled[params[:temp_locale]].to_s
child.save
end
end
+1 -1
View File
@@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base
def render_page
if @item
respond_to do |format|
format.html { render :text => parse_page_noko(@item), :layout => 'page_layout' }
format.html { render :text => parse_page_content(@item), :layout => 'page_layout' }
format.rss { render_main_rss }
end
else
+70
View File
@@ -0,0 +1,70 @@
class FrontController < ApplicationController
layout false
def show_banner
@ad_banner = AdBanner.find(params[:id]) rescue nil
end
def show_footer
render :text => @site.footer
end
def show_menu
page = Page.find(params[:id]) rescue nil
render :text => menu_level(Page.root, page, 1, page.design.layout.menu) if page
end
def show_site_sub_menu
render :text => @site.sub_menu
end
def show_sitemap
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
end
def show_page_sub_menu
@menu_page = Page.find(params[:menu_page_id]) rescue nil
@page_id = params[:page_id]
end
private
def menu_level(page, current_page, current, menu)
res = ''
if page.visible_children.size > 0
res << "<ul class='"
res << menu.values["class_#{current}"] rescue nil
res << "'>"
i = nil
i = 1 if menu.values["li_incremental_#{current}"]
children = current == 1 ? page.visible_children.reverse : page.visible_children
children.each do |child|
res << menu_li(child, current_page, current, menu, i)
i += 1 if i
end
if menu.values['home'] && current == 1
res << menu_li(page, current_page, current, menu, i)
end
res << "</ul>"
end
res
end
def menu_li(page, current_page, current, menu, i)
res = "<li class='"
res << menu.values["li_class_#{current}"] rescue nil
res << "_#{i}" if i
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
res << "'>"
root = "/"
res << "<a href='#{(page.class.to_s.eql?('Page') ? root + page.path : page.url)}'><span>#{page.title}</span></a>"
if page.visible_children.size > 0 && current < menu.levels
res << "<span class='dot'></span>"
res << menu_level(page, current_page, current + 1, menu)
end unless (page.root? rescue nil)
res << "</li>"
end
end
+51 -52
View File
@@ -29,63 +29,62 @@ class PagesController < ApplicationController
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found
end
#rescue
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
#end
end
#rescue
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
#end
end
def index_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page
end
def index_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page
end
def show_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank?
redirect_to(url + options) unless save_from_no_lang_for_page
end
def show_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank?
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank?
redirect_to(url + options) unless save_from_no_lang_for_page
end
def load_orbit_bar
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
end
def load_orbit_bar
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
end
protected
def get_item
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
if !params[:category_id].blank? && !params[:tag_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
elsif !params[:category_id].blank?
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
elsif !params[:tag_id].blank?
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
end
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
end
protected
def get_item
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
if !params[:category_id].blank? && !params[:tag_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
elsif !params[:category_id].blank?
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
elsif !params[:tag_id].blank?
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
end
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
end
def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:error] = t('sys.module_page_lang_not_support')
redirect_to '/'
return true
else
return false
end
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:error] = t('sys.module_page_lang_not_support')
redirect_to '/'
return true
else
return false
end
end
end
+19 -2
View File
@@ -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
View File
@@ -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
+5
View File
@@ -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
+1 -1
View File
@@ -138,7 +138,7 @@
<% end %>
</ul>
<div class="tab-content">
<%= select_tag 'ad_banner[id]',options_from_collection_for_select(AdBanner.all, "id", "title",params[:ad_banner_id]) , :class=>"input-medium", %>
<%= select_tag 'ad_banner[id]',options_from_collection_for_select(AdBanner.all, "id", "title",params[:ad_banner_id]) , :class=>"input-medium" %>
<% @site_valid_locales.each do |locale|%>
<%= content_tag :div,:class => "tab-pane #{active_when_current_locale_eq locale}",:id=>"#{locale}" do%>
<div class="title">
@@ -1,15 +1,15 @@
<div class="map-block <%= 'disabled' if !sitemap_block.sitemap_enabled %>">
<div class="map-block <%= 'disabled' if !sitemap_block.show_in_sitemap_for(temp_locale) %>">
<h4>
<button id="<%= sitemap_block.id %>" class="onoff pull-right"><%= sitemap_block.sitemap_enabled ? t('on_upcase') : t('off_upcase') %></button>
<span><%= sitemap_block_counter + 1 %> <%= sitemap_block.title %></span>
<button id="<%= sitemap_block.id %>" class="onoff pull-right" temp_locale="<%= temp_locale %>"><%= sitemap_block.show_in_sitemap_for(temp_locale) ? t('on_upcase') : t('off_upcase') %></button>
<span><%= sitemap_block_counter + 1 %> <%= sitemap_block.title_translations[temp_locale] %></span>
</h4>
<ul>
<% sitemap_block.children.each_with_index do |child, i| %>
<li class="clear <%= 'disabled' if !child.sitemap_enabled %>">
<%= content_tag :button, :id => child.id, :class => "onoff pull-right", :disabled => !sitemap_block.sitemap_enabled do %>
<%= child.sitemap_enabled ? t('on_upcase') : t('off_upcase') %>
<li class="clear <%= 'disabled' if !child.show_in_sitemap_for(temp_locale) %>">
<%= content_tag :button, :id => child.id, :class => "onoff pull-right", :temp_locale => temp_locale, :disabled => !child.show_in_sitemap_for(temp_locale) do %>
<%= child.show_in_sitemap_for(temp_locale) ? t('on_upcase') : t('off_upcase') %>
<% end %>
<span><%= "#{sitemap_block_counter + 1}-#{i + 1}" %> <%= child.title %></span>
<span><%= "#{sitemap_block_counter + 1}-#{i + 1}" %> <%= child.title_translations[temp_locale] %></span>
</li>
<% end if sitemap_block.children %>
</ul>
+21 -7
View File
@@ -2,9 +2,18 @@
<%= render :partial => 'layouts/side_bar', :locals => {:link_name => t('site.settings'), :link_url => admin_site_site_info_path(@site), :icon => 'icons-cog', :side_bar_content => 'admin/sites/side_bar'} %>
<% end %>
<div class="site-map">
<%= render :partial => 'sitemap_block', :collection => @items %>
<ul class="nav nav-tabs">
<% @site_valid_locales.each_with_index do |locale, i| %>
<li <%= ( i == 0 ) ? " class=active" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% end %>
</ul>
<div class="tab-content">
<% @site_valid_locales.each_with_index do |temp_locale, i| %>
<div class="tab-pane site-map <%= temp_locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<%= render :partial => 'sitemap_block', :collection => @items, :locals => {:temp_locale => temp_locale} %>
</div>
<% end %>
</div>
<% content_for :page_specific_javascript do %>
@@ -13,9 +22,14 @@
$(document).ready(function(){
$('.site-map').masonry({
itemSelector: '.map-block',
columnWidth: 260,
isAnimated: true
columnWidth: 260
});
$('a[data-toggle="tab"]').on('shown', function (e) {
$('.site-map').masonry({
itemSelector: '.map-block',
columnWidth: 260
});
})
});
$(document).on('click', 'li .onoff', function () {
$(this).parents("li").toggleClass("disabled");
@@ -24,7 +38,7 @@
} else {
$(this).text("<%= t('on_upcase') %>")
}
$.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle');
$.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle?temp_locale=' + $(this).attr('temp_locale'));
});
$(document).on('click', 'h4 .onoff', function () {
$(this).parents(".map-block").toggleClass("disabled");
@@ -39,7 +53,7 @@
$(this).parents(".map-block").find('button').text("<%= t('on_upcase') %>")
$(this).parents(".map-block").find('li button').removeAttr("disabled")
}
$.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle?parent=true');
$.getScript('<%= admin_sites_path %>' + '/' + $(this).attr('id') + '/sitemap_toggle?parent=true&temp_locale=' + $(this).attr('temp_locale'));
});
</script>
<% end %>
+26
View File
@@ -0,0 +1,26 @@
<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>
<script type='text/javascript'>
jQuery(function( $ ){
$('#slideshow-<%= @ad_banner.title.dehumanize %>').cycle({
delay: -1000,
fx: "<%= @ad_banner.ad_fx.nil? ? 'fade': @ad_banner.ad_fx %>",
timeoutFn: getTimeout,
pager: '.banner_nav-<%= @ad_banner.title.dehumanize %>',
pagerAnchorBuilder: function(idx, slide) {
return "<li><a href='#'></a></li>";
}
});
});
</script>
<div style='position:relative'>
<ul id='banner_nav' class='clear banner_nav-<%= @ad_banner.title.dehumanize %>'></ul>
<div id='slideshow-<%= @ad_banner.title.dehumanize %>' class='slideshow'>
<% (images = @ad_banner.ad_images).shuffle.each do |ad_image| %>
<% if ad_image.display? %>
<img src='<%= ad_image.file %>' alt='<%= ad_image.title || ' ' %>' time_to_next='<%= @ad_banner.transition_msec %>' link_open='<%= ad_image.link_open %>' link_url='<%= (ad_image.direct_to_after_click? ? ad_image.out_link : ad_image.context) || ' ' %>' link_url='<%= (ad_image.out_link) %>' style=' <%= 'cursor:pointer;' if !ad_image.out_link.blank? %>'/>
<% end %>
<% end %>
</div>
</div>
@@ -0,0 +1,12 @@
<% if @menu_page && @menu_page.visible_children.size > 0 %>
<div class='category_list'>
<h3 class='h3'><%= @menu_page.title} %></h3>
<ul class='list'>"
<% menu_page.visible_children.each do |child| %>
<li class="<%= @page_id.eql?(child.id) ? 'active' : nil %>">
<a href="<%= (child.class.to_s.eql?('Page') ? '/' + child.path : child.url) %>"><%= child.title %></a>
</li>
<% end %>
</ul>
</div>
<% end %>
+27
View File
@@ -0,0 +1,27 @@
<div class="site-map">
<% @items.each_with_index do |item, i| %>
<% if item.show_in_sitemap_for(I18n.locale.to_s) %>
<div class="map-block">
<h4><%= i+1 %> <a href='<%= item.path %>'><%= item.title %></a></h4>
<ul>
<% item.children.each_with_index do |child, ii| %>
<% if child.show_in_sitemap_for(I18n.locale.to_s) %>
<li class="clear"><%= "#{i+1}-#{ii+1}" %> <a href='<%= child.path %>'><%= child.title %></a></span></li>
<% end %>
<% end if item.children %>
</ul>
</div>
<% end %>
<% end %>
</div>
<%= javascript_include_tag "lib/jquery.masonry.min.js" %>
<script>
$(document).ready(function(){
$('.site-map').masonry({
itemSelector: '.map-block',
columnWidth: 220,
isAnimated: true
});
});
</script>