Only one parser for front end

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

View File

@ -15,4 +15,5 @@
*= require scroll_style *= require scroll_style
*= require isotope *= require isotope
*= require icons *= require icons
*= require site-map
*/ */

View File

@ -1,8 +1,8 @@
class Admin::SitesController < ApplicationController class Admin::SitesController < ApplicationController
layout "new_admin" layout "new_admin"
before_filter :authenticate_user!, :except => [:sitemap_frontend] before_filter :authenticate_user!
before_filter :is_admin?, :except => [:sitemap_frontend] before_filter :is_admin?
before_filter :get_site before_filter :get_site
# def index # def index
@ -31,18 +31,13 @@ class Admin::SitesController < ApplicationController
@items = get_homepage.children rescue [] @items = get_homepage.children rescue []
end end
def sitemap_frontend
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
render :layout => false
end
def sitemap_toggle def sitemap_toggle
@item = Item.find(params[:id]) @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 @item.save
if params[:parent] if params[:parent]
@item.children.each do |child| @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 child.save
end end
end end

View File

@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base
def render_page def render_page
if @item if @item
respond_to do |format| 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 } format.rss { render_main_rss }
end end
else else

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

View File

@ -29,63 +29,62 @@ class PagesController < ApplicationController
else else
render :file => "#{Rails.root}/public/404.html", :status => :not_found render :file => "#{Rails.root}/public/404.html", :status => :not_found
end end
#rescue #rescue
# render :file => "#{Rails.root}/public/404.html", :status => :not_found # render :file => "#{Rails.root}/public/404.html", :status => :not_found
#end #end
end end
def index_from_link def index_from_link
url = "/#{@item.path}" url = "/#{@item.path}"
options = '' options = ''
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank? 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? ? '?' : '&'}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? ? '?' : '&'}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? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank? options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options) uri = URI::escape(url + options)
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&')) #uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page redirect_to(uri)unless save_from_no_lang_for_page
end end
def show_from_link def show_from_link
url = "/#{@item.path}" url = "/#{@item.path}"
options = '' options = ''
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank? 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? ? '?' : '&'}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? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank? options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].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 redirect_to(url + options) unless save_from_no_lang_for_page
end end
def load_orbit_bar def load_orbit_bar
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer} render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
end 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 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 def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s) if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:error] = t('sys.module_page_lang_not_support') flash[:error] = t('sys.module_page_lang_not_support')
redirect_to '/' redirect_to '/'
return true return true
else else
return false return false
end end
end end
end end

View File

@ -11,7 +11,7 @@ class Item
field :enabled_for, :type => Array, :default => nil field :enabled_for, :type => Array, :default => nil
field :menu_enabled_for, :type => Array, :default => nil field :menu_enabled_for, :type => Array, :default => nil
field :title, localize: true 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\-_]+$/ validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
@ -53,12 +53,29 @@ class Item
save! save!
end end
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 protected
def rebuild_path def rebuild_path
self.path = (self.ancestors_and_self - [Item.root]).collect{|x| x.name unless x.root?}.join('/') 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 end
def find_by_parent_and_position(parent, position) def find_by_parent_and_position(parent, position)

View File

@ -1,9 +1,11 @@
class Page < Item class Page < Item
include Rails.application.routes.url_helpers
include Impressionist::Impressionable include Impressionist::Impressionable
include ParserFrontEnd
is_impressionable :counter_cache => { :column_name => :view_count } is_impressionable :counter_cache => { :column_name => :view_count }
field :content field :content, localize: true
field :app_frontend_url field :app_frontend_url
field :theme_id, :type => BSON::ObjectId, :default => nil field :theme_id, :type => BSON::ObjectId, :default => nil
field :category, :default => '' field :category, :default => ''
@ -17,40 +19,34 @@ class Page < Item
belongs_to :design belongs_to :design
belongs_to :module_app 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_contexts, :autosave => true, :dependent => :destroy
has_many :page_metas, :autosave => true, :dependent => :destroy has_many :page_metas, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :page_parts, :allow_destroy => true accepts_nested_attributes_for :page_parts, :allow_destroy => true
before_save :create_parts, :delete_empty_frontend_field before_save :delete_empty_frontend_field
before_save :create_parts, if: Proc.new { |page| page.new_record? || page.design_id_changed? }
# embeds_many :custom_images, :class_name => 'Image', as: :design_image after_save :generate_html
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
protected protected
def create_parts def create_parts
if self.new_record? || self.design_id_changed? page_design = self.design
page_design = self.design parent = self.parent
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
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|
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.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 = self.page_parts.build(:name => layout_part.name) unless current_part if menu_part && current_part.name.eql?(menu_part.name)
if menu_part && current_part.name.eql?(menu_part.name) if current_part.new_record?
if current_part.new_record? current_part.kind = menu_part.kind
current_part.kind = menu_part.kind current_part.public_r_tag = menu_part.public_r_tag
current_part.public_r_tag = menu_part.public_r_tag current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id PagePart.without_callback(:save, :after, :update_parent) do
else 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) 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
end end
@ -70,4 +66,11 @@ class Page < Item
end 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 end

View File

@ -20,6 +20,7 @@ class PagePart
belongs_to :module_app belongs_to :module_app
before_save :delete_empty_widget_field before_save :delete_empty_widget_field
after_save :update_parent
protected protected
@ -30,4 +31,8 @@ class PagePart
# self.widget_field.delete("") if self.widget_field # self.widget_field.delete("") if self.widget_field
end end
def update_parent
self.page.save
end
end end

View File

@ -138,7 +138,7 @@
<% end %> <% end %>
</ul> </ul>
<div class="tab-content"> <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|%> <% @site_valid_locales.each do |locale|%>
<%= content_tag :div,:class => "tab-pane #{active_when_current_locale_eq locale}",:id=>"#{locale}" do%> <%= content_tag :div,:class => "tab-pane #{active_when_current_locale_eq locale}",:id=>"#{locale}" do%>
<div class="title"> <div class="title">

View File

@ -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> <h4>
<button id="<%= sitemap_block.id %>" class="onoff pull-right"><%= sitemap_block.sitemap_enabled ? t('on_upcase') : t('off_upcase') %></button> <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 %></span> <span><%= sitemap_block_counter + 1 %> <%= sitemap_block.title_translations[temp_locale] %></span>
</h4> </h4>
<ul> <ul>
<% sitemap_block.children.each_with_index do |child, i| %> <% sitemap_block.children.each_with_index do |child, i| %>
<li class="clear <%= 'disabled' if !child.sitemap_enabled %>"> <li class="clear <%= 'disabled' if !child.show_in_sitemap_for(temp_locale) %>">
<%= content_tag :button, :id => child.id, :class => "onoff pull-right", :disabled => !sitemap_block.sitemap_enabled do %> <%= content_tag :button, :id => child.id, :class => "onoff pull-right", :temp_locale => temp_locale, :disabled => !child.show_in_sitemap_for(temp_locale) do %>
<%= child.sitemap_enabled ? t('on_upcase') : t('off_upcase') %> <%= child.show_in_sitemap_for(temp_locale) ? t('on_upcase') : t('off_upcase') %>
<% end %> <% 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> </li>
<% end if sitemap_block.children %> <% end if sitemap_block.children %>
</ul> </ul>

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'} %> <%= 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 %> <% end %>
<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="site-map"> <div class="tab-content">
<%= render :partial => 'sitemap_block', :collection => @items %> <% @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> </div>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
@ -13,9 +22,14 @@
$(document).ready(function(){ $(document).ready(function(){
$('.site-map').masonry({ $('.site-map').masonry({
itemSelector: '.map-block', itemSelector: '.map-block',
columnWidth: 260, columnWidth: 260
isAnimated: true
}); });
$('a[data-toggle="tab"]').on('shown', function (e) {
$('.site-map').masonry({
itemSelector: '.map-block',
columnWidth: 260
});
})
}); });
$(document).on('click', 'li .onoff', function () { $(document).on('click', 'li .onoff', function () {
$(this).parents("li").toggleClass("disabled"); $(this).parents("li").toggleClass("disabled");
@ -24,7 +38,7 @@
} else { } else {
$(this).text("<%= t('on_upcase') %>") $(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 () { $(document).on('click', 'h4 .onoff', function () {
$(this).parents(".map-block").toggleClass("disabled"); $(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('button').text("<%= t('on_upcase') %>")
$(this).parents(".map-block").find('li button').removeAttr("disabled") $(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> </script>
<% end %> <% end %>

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>

View File

@ -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 %>

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>

View File

@ -162,7 +162,8 @@ Orbit::Application.routes.draw do
post 'upload' post 'upload'
end end
end end
match "desktop" => "desktop#index"
match "desktop" => "desktop#index"
namespace :desktop do namespace :desktop do
match "desktop" => "desktop#desktop" match "desktop" => "desktop#desktop"
match '/journal_pages/get_journals_json' => 'journal_pages#get_journals_json' match '/journal_pages/get_journals_json' => 'journal_pages#get_journals_json'
@ -231,6 +232,14 @@ Orbit::Application.routes.draw do
# match '/desktop_orbit/eventajaxload' => 'desktop_publications#update_journal' # match '/desktop_orbit/eventajaxload' => 'desktop_publications#update_journal'
scope '/front' do
match 'show_banner/:id' => 'front#show_banner', :as => :front_show_banner
match 'show_footer' => 'front#show_footer', :as => :front_show_footer
match 'show_menu/:id' => 'front#show_menu', :as => :front_show_menu
match 'show_page_sub_menu' => 'front#show_page_sub_menu', :as => :front_show_page_sub_menu
match 'show_site_sub_menu' => 'front#show_site_sub_menu', :as => :front_show_site_sub_menu
match 'show_sitemap' => 'front#show_sitemap', :as => :front_show_sitemap
end
match '/panel/:app_name/front_end/:app_action/:id(/:controller_action)' => 'pages#show_from_link', :constraints => lambda { |request| match '/panel/:app_name/front_end/:app_action/:id(/:controller_action)' => 'pages#show_from_link', :constraints => lambda { |request|

View File

@ -25,13 +25,13 @@ module ParserBackEnd
def parse_page_edit_noko(page) def parse_page_edit_noko(page)
body = Nokogiri::HTML(page.design.layout.body) body = Nokogiri::HTML(page.design.layout.body)
parse_menu(body, page, true) parse_menu_edit(body, page, true)
public_r_tags = parse_contents(body, page, true) public_r_tags = parse_contents_edit(body, page, true)
parse_images(body, page) parse_images_edit(body, page)
parse_footer(body, page) parse_footer_edit(body, page)
parse_sub_menu(body, page) parse_sub_menu_edit(body, page)
public_r_tags.each do |tag| public_r_tags.each do |tag|
send("parse_#{tag}s", body, page, true) send("parse_#{tag}s_edit", body, page, true)
end end
body.to_html body.to_html
end end

View File

@ -38,7 +38,7 @@ module ParserCommon
end end
# ad_banners # ad_banners
def parse_ad_banners(body = nil, page = nil, edit=nil) def parse_ad_banners_edit(body = nil, page = nil, edit=nil)
body.css('ad_banner').each do |banner| body.css('ad_banner').each do |banner|
res = '' res = ''
ad_banner = AdBanner.find(banner["id"]) rescue nil ad_banner = AdBanner.find(banner["id"]) rescue nil
@ -94,7 +94,7 @@ module ParserCommon
end end
# page_images # page_images
def parse_images(body, page, edit=nil) def parse_images_edit(body, page, edit=nil)
body.css('.page_image').each do |page_image| body.css('.page_image').each do |page_image|
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } # image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
# image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image # image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
@ -112,20 +112,16 @@ module ParserCommon
end end
# page_menu # page_menu
def parse_menu(body, page, edit=nil) def parse_menu_edit(body, page, edit=nil)
page_menu = body.css('.page_menu').first page_menu = body.css('.page_menu').first
if page_menu home = get_homepage
home = get_homepage menu = page.design.layout.menu
menu = page.design.layout.menu fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit))
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page, 1, menu, edit)) page_menu.swap(fragment)
page_menu.swap(fragment)
else
''
end
end end
# sub_menus # sub_menus
def parse_sub_menus(body = nil, page = nil, edit=nil) def parse_sub_menus_edit(body = nil, page = nil, edit=nil)
body.css('sub_menu').each do |sub_menu| body.css('sub_menu').each do |sub_menu|
menu_page = Page.find(sub_menu['id']) rescue nil menu_page = Page.find(sub_menu['id']) rescue nil
res = '' res = ''
@ -149,7 +145,7 @@ module ParserCommon
end end
# page_footer # page_footer
def parse_footer(body, page) def parse_footer_edit(body, page)
page_footer = body.css('.page_footer').first page_footer = body.css('.page_footer').first
if page_footer if page_footer
res = "<div id='#{page_footer['id']}', class='#{page_footer['class']}'>" res = "<div id='#{page_footer['id']}', class='#{page_footer['class']}'>"
@ -163,7 +159,7 @@ module ParserCommon
end end
# page_sub_menu # page_sub_menu
def parse_sub_menu(body, page) def parse_sub_menu_edit(body, page)
page_sub_menu = body.css('.page_sub_menu').first page_sub_menu = body.css('.page_sub_menu').first
if page_sub_menu if page_sub_menu
res = "<div id='#{page_sub_menu['id']}', class='#{page_sub_menu['class']}'>" res = "<div id='#{page_sub_menu['id']}', class='#{page_sub_menu['class']}'>"
@ -177,20 +173,16 @@ module ParserCommon
end end
# sitemap # sitemap
def parse_sitemaps(body = nil, page = nil, edit=nil) def parse_sitemaps_edit(body = nil, page = nil, edit=nil)
sitemap = body.css('sitemap').first sitemap = body.css('sitemap').first
if sitemap url = admin_site_sitemap_frontend_path(@site)
url = admin_site_sitemap_frontend_path(@site) options = "?inner=true"
options = "?inner=true" fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load' path='#{url + options}'></div>")
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load' path='#{url + options}'></div>") sitemap.swap(fragment)
sitemap.swap(fragment)
else
''
end
end end
# page_contents # page_contents
def parse_contents(body, page, edit=nil) def parse_contents_edit(body, page, edit=nil)
public_r_tags = [] public_r_tags = []
body.css('.page_content').each do |content| body.css('.page_content').each do |content|
ret = '' ret = ''
@ -199,7 +191,6 @@ module ParserCommon
if (content["main"] == "true" && !page.module_app.nil?) if (content["main"] == "true" && !page.module_app.nil?)
ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}" ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}"
ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(page.id.to_s) ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(page.id.to_s)
ret << "/#{params[:controller_action]}" if params[:controller_action] && params[:id]
ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}" ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}"
ret << "'></div>" ret << "'></div>"
else else
@ -216,7 +207,7 @@ module ParserCommon
ret << part.content rescue '' ret << part.content rescue ''
when 'module_widget' when 'module_widget'
url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" url = "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true"
options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&part_id=#{part.id}" options = "&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}"
ret << "<div class='dymanic_load widget' path='#{url + options}'></div>" ret << "<div class='dymanic_load widget' path='#{url + options}'></div>"
when 'public_r_tag' when 'public_r_tag'
ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>" ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>"

View File

@ -1,38 +1,139 @@
module ParserFrontEnd module ParserFrontEnd
include ParserCommon
# c.define_tag 'language_bar' do
# @site.in_use_locales.map{ |locale|
# lang = I18nVariable.first(:conditions => {:key => locale})[locale]
# if I18n.locale.to_s.eql?(locale)
# lang
# else
# "<a href='?locale=#{locale}'>#{lang}</a>"
# end
# }.join(' | ')
# end
# c.define_tag 'link' do |tag|
# item = Item.first(:conditions => { :path => tag.attr['name'] })
# ret = ''
# ret << "<a href='#{tag.attr['name']}'>"
# ret << item.i18n_variable[I18n.locale]
# ret << '</a>'
# end
# end
require 'nokogiri' require 'nokogiri'
def parse_page_noko(page) def parse_page_noko(page, site)
body = Nokogiri::HTML(page.design.layout.body) i18n = {}
parse_menu(body, page) Site.first.valid_locales.each do |locale|
public_r_tags = parse_contents(body, page) body = Nokogiri::HTML(page.design.layout.body)
parse_images(body, page) parse_contents(body, page, locale)
parse_footer(body, page) parse_footer(body, page, site)
parse_sub_menu(body, page) parse_images(body, page)
public_r_tags.each do |tag| parse_menu(body, page)
send("parse_#{tag}s", body, page) parse_sub_menu(body, page, site)
i18n.merge!({locale => body.to_html})
end end
i18n
end
def parse_page_content(page)
category = params[:category_id].blank? ? page[:category] : params[:category_id]
tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id]
body = Nokogiri::HTML(page.content)
body.css('orbit_front').each do |front|
ret = ''
part = PagePart.find(front['part_id']) if front['part_id']
ret << eval("\"#{front['path']}\"") rescue ''
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load widget' path='#{ret}'></div>")
front.swap(fragment)
end
body.to_html body.to_html
end end
# page_footer
def parse_footer(body, page, site)
page_footer = body.css('.page_footer').first
if page_footer
res = "<div id='#{page_footer['id']}', class='#{page_footer['class']}'>"
res << "<div class='dymanic_load' path='#{front_show_footer_path}'></div>"
res << "</div>"
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
page_footer.swap(fragment) rescue nil
else
''
end
end
# page_images
def parse_images(body, page, edit=nil)
body.css('.page_image').each do |page_image|
image = page.design.images.detect{|image| image.name.eql?(File.basename(page_image['src'])) } unless image
if image
res = "<img src=#{image.file.url} "
page_image.attributes.each do |l|
res << "#{l[0]}='#{l[1]}' "
end
res << '>'
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
page_image.swap(fragment)
end
end
# page_menu
def parse_menu(body, page)
page_menu = body.css('.page_menu').first
if page_menu
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load' path='#{front_show_menu_path(page.id)}'></div>")
page_menu.swap(fragment)
else
''
end
end
# page_sub_menu
def parse_sub_menu(body, page, site)
page_sub_menu = body.css('.page_sub_menu').first
if page_sub_menu
res = "<div id='#{page_sub_menu['id']}', class='#{page_sub_menu['class']}'>"
res << "<div class='dymanic_load' path='#{front_show_site_sub_menu_path}'></div>"
res << "</div>"
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
page_sub_menu.swap(fragment)
else
''
end
end
# page_contents
def parse_contents(body, page, edit=nil, locale)
public_r_tags = []
body.css('.page_content').each do |content|
ret = ''
if (content["main"] == "true" && !page.module_app.nil?)
url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}\#{(\"/\" + params[:id]) if params[:id] && !params[:id].eql?(page.id.to_s)}?inner=true"
options = "&page_id=#{page.id}&category_id=\#{category}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}"
ret << "<orbit_front path='#{url + options}'></div>"
else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
case part.kind
when 'text'
ret << part.content_translations[locale.to_s] rescue ''
when 'module_widget'
url = "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
options = "&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}"
ret << "<orbit_front path='#{url + options}' part_id=#{part.id}></div>"
when 'public_r_tag'
ret << send("generate_#{part.public_r_tag}s", part.public_r_tag_object_id, page)
else
''
end if part
end
scope = "<#{content.name}"
content.attributes.each_pair do |key, value|
scope << " #{key}='#{value}'"
end
scope << ">#{ret}</#{content.name}>"
fragment = Nokogiri::HTML::DocumentFragment.new(body, scope)
content.swap(fragment)
end
end
# ad_banners
def generate_ad_banners(*args)
"<div class='dymanic_load' path='#{front_show_banner_path(args[0])}'></div>"
end
# sitemap
def generate_sitemaps(*args)
"<div class='dymanic_load' path='#{front_show_sitemap_path}'></div>"
end
# sub_menus
def generate_sub_menus(*args)
"<div class='dymanic_load' path='#{front_show_page_sub_menu_path({:menu_page_id => args[0], :page_id => args[1]})}'></div>"
end
end end

View File

@ -305,4 +305,11 @@ namespace :migrate do
end if news_bulletins end if news_bulletins
end end
task :sitemap_i18n => :environment do
Item.all.each do |item|
item.sitemap_enabled = item.sitemap_enabled ? {'en' => 'true', 'zh_tw' => 'true'} : nil
item.save
end
end
end end

View File

@ -43,7 +43,7 @@
<div class="widget-action clear"> <div class="widget-action clear">
<a href="#" class="action"><i title="Set the announcement to start and end dates" class="icon-exclamation-sign icon-white tip"></i></a> <a href="#" class="action"><i title="Set the announcement to start and end dates" class="icon-exclamation-sign icon-white tip"></i></a>
</div> </div>
<h3 class="widget-title"><i class="icons-calendar"></i><%= t(:date) %></h3> <h3 class="widget-title"><i class="icons-calendar"></i><%= t(:date_) %></h3>
<div class="widget-content clear"> <div class="widget-content clear">
<div class="control-group"> <div class="control-group">
<label class="control-label"><%= t(:start) %></label> <label class="control-label"><%= t(:start) %></label>