From 8b61314cc41eb2ff4e6e103b802a8e3e15440340 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Mon, 7 May 2012 15:11:43 +0800 Subject: [PATCH] Add i18n for site_info. Add always display site title. Changes for menu in front-end --- app/helpers/application_helper.rb | 12 +++++- app/models/site.rb | 1 + app/views/admin/sites/site_info.html.erb | 9 ++-- config/locales/en.yml | 5 +++ config/locales/zh_tw.yml | 5 +++ lib/parsers/parser_common.rb | 52 +++++++++--------------- 6 files changed, 47 insertions(+), 37 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8829dfef2..4f9128bb4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -112,7 +112,16 @@ module ApplicationHelper end def page_title(page) - "#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}\n" + res = "" + page_title = page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale] + if page.is_home? && @site.title + res << @site.title[I18n.locale] + elsif @site.title && @site.title_always_on + res << @site.title[I18n.locale] + ' - ' + page_title + else + res << page_title + end + res << "\n" end def page_stylesheets(page, edit=nil) @@ -123,6 +132,7 @@ module ApplicationHelper stylesheets << "\n" end stylesheets << "\n" if page.design.reset_css + # stylesheets << "\n" stylesheets << "\n" if page.design.default_css theme = page.design.themes.detect{ |d| d.id == page.theme_id } stylesheets << "\n" if theme diff --git a/app/models/site.rb b/app/models/site.rb index ce689200e..a3e0513d3 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -11,6 +11,7 @@ class Site field :roaming_id field :private_key, :type => Binary field :public_key, :type => Binary + field :title_always_on, :type => Boolean, :default => false field :school field :department diff --git a/app/views/admin/sites/site_info.html.erb b/app/views/admin/sites/site_info.html.erb index 93e1a3583..a3ca39353 100644 --- a/app/views/admin/sites/site_info.html.erb +++ b/app/views/admin/sites/site_info.html.erb @@ -12,28 +12,29 @@
+ <%= f.check_box :title_always_on %> <%= t 'admin.always_display_title' %> <% @site_valid_locales.each do |locale|%> <%= content_tag :div, :class => "tab-pane #{active_when_current_locale_eq locale}", :id => "#{locale}" do %>
- <%= t :title %> + <%= t 'admin.site_title' %> <%= f.fields_for :title, @site.title do |f| %> <%= f.text_field locale %> <% end %>
- <%= t :keywords %> + <%= t 'admin.keywords' %> <%= f.fields_for :keywords, @site.keywords do |f| %> <%= f.text_field locale %> <% end %>
- <%= t :description %> + <%= t 'admin.site_description' %> <%= f.fields_for :description, @site.description do |f| %> <%= f.text_field locale %> <% end %>
- <%= t :footer %> + <%= t 'admin.site_footer' %> <%= f.fields_for :footer, @site.footer do |f| %> <%= f.text_area locale, :class => "tinymce_textarea" %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index eeb5e63ad..862ccf136 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -98,6 +98,7 @@ en: admin: Admin action: Action all_articles: List + always_display_title: Always displayed in the title bar announcement: Announcement asset: Asset assets: @@ -147,6 +148,7 @@ en: is_published: Is published item: Item key: Key + keywords: Keywords language: Language layout: Layout layout_name: Layout name @@ -199,7 +201,10 @@ en: setup_translations: Translations setup setup_designs: Designs setup site: Site + site_description: Site description + site_footer: Site footer site_settings: Site Setting + site_title: Site title super_pages: Super pages structure: Structure title: Title diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 661253c4d..27f4a2f63 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -91,6 +91,7 @@ zh_tw: add_drop_down_item: +增加Orbit選單 admin: 網站管理者 all_articles: 列表 + always_display_title: 永遠顯示於標題列 announcement: 公告管理 asset: 資產 assets: @@ -144,6 +145,7 @@ zh_tw: is_published: 被出版 item: 網站架構 key: 關鍵 + keywords: 關鍵字 language: 語言 layout: 佈局 layout_name: 佈局名字 @@ -189,7 +191,10 @@ zh_tw: purchase: 購買 role: 身份 roles: 身份 + site_description: 網站描述 + site_footer: 網站頁尾 site_settings: 基本設定 + site_title: 網站標題 setup_member: 成員設置 setup_translations: 語系設定 setup_designs: 版型設定 diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 04fe2e6c6..6ee096561 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -3,46 +3,34 @@ module ParserCommon def menu_level(page, current, menu, edit = false) res = '' - if menu.levels > 0 && current <= menu.levels - if current != 0 - res << "
" - item = rand(100000) - res << "#{page.i18n_variable[I18n.locale]}" - if page.children.size > 0 - res << "
" - res << "
    " - i = nil - i = 1 if menu.values["li_incremental_#{current}"] - page.ordered_and_visible_children.each do |child| - res << menu_li(child, current, menu, i, edit) - i += 1 if i - end - res << "
" - res << "
" - end - res << "
" - else - res << '
    ' - res << "
  • " + "#{page.i18n_variable[I18n.locale]}" + "
  • " - page.ordered_and_visible_children.each do |child| - res << "
  • " + menu_level(child, current + 1, menu, edit) + "
  • " - end - res << '
' + if page.children.size > 0 + res << "" end res end def menu_li(page, current, menu, i, edit) res = "" end @@ -104,7 +92,7 @@ module ParserCommon page_menu = body.css('.page_menu').first home = get_homepage menu = page.design.layout.menu - fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 0, menu, edit)) + fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 1, menu, edit)) page_menu.swap(fragment) end @@ -135,7 +123,7 @@ module ParserCommon res << @site.footer[I18n.locale] res << "
" fragment = Nokogiri::HTML::DocumentFragment.new(body ,res) - page_footer.swap(fragment) + page_footer.swap(fragment) rescue nil end end