anxgang 5 лет назад
Родитель
Сommit
4eb0fc8caf

+ 6 - 0
app/assets/stylesheets/application.scss

@@ -20,3 +20,9 @@
 body > .alert {
   margin-bottom: 0;
 }
+
+// Breadcrumb alert no margin & background
+body nav .breadcrumb {
+  background: white;
+  margin-bottom: 0;
+}

+ 3 - 0
app/controllers/application_controller.rb

@@ -3,6 +3,9 @@ class ApplicationController < ActionController::Base
 
   before_action :configure_permitted_parameters, if: :devise_controller?
   before_action :masquerade_user!
+  # before_action :authenticate_user!
+  
+  add_breadcrumb I18n.t("breadcrumbs.homepage"), :root_path
 
   protected
 

+ 1 - 0
app/views/layouts/application.html.erb

@@ -7,6 +7,7 @@
   <body>
     <%= render 'shared/navbar' %>
     <%= render 'shared/notices' %>
+    <%= render 'shared/breadcrumb' %>
 
     <div class="container">
       <%= yield %>

+ 5 - 0
app/views/shared/_breadcrumb.html.erb

@@ -0,0 +1,5 @@
+<nav>
+  <div class="container">
+    <%= render_breadcrumbs builder: ::BootstrapBreadcrumbsBuilder %>     
+  </div>
+</nav>

+ 34 - 0
config/initializers/bootstrap_breadcrumbs_builder.rb

@@ -0,0 +1,34 @@
+class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
+  def render
+    if @elements.size > 0
+      set_context
+    else
+      set_element
+    end
+  end
+
+  def set_context
+    @context.content_tag(:ol, class: 'breadcrumb') do
+      @elements.collect do |element|
+        render_element(element)
+      end.join.html_safe
+    end
+  end
+
+  def set_element
+    @elements.collect do |element|
+      render_element(element)
+    end.join(@options[:separator] || ' &raquo;')
+  end
+
+  def render_element(element)
+    current = @context.current_page?(compute_path(element))
+
+    @context.content_tag(:li, class: "breadcrumb-item #{'active' if current}") do
+      link_or_text = @context.link_to_unless_current(compute_name(element),
+                                                     compute_path(element),
+                                                     element.options)
+      link_or_text
+    end
+  end
+end

+ 59 - 0
config/locales/devise.zh-TW.yml

@@ -0,0 +1,59 @@
+# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
+
+zh-TW:
+  devise:
+    confirmations:
+      confirmed: "您的帳號已通過驗證,現在您已成功登入。"
+      send_instructions: "您將在幾分鐘後收到一封電子郵件,內有驗證帳號的步驟說明。"
+      send_paranoid_instructions: "如果我們有您的信箱,您將會收到一封驗證您的帳號的電子郵件。"
+    failure:
+      already_authenticated: "您已經登入。"
+      inactive: "您的帳號尚未被啟用。"
+      invalid: "信箱或密碼是無效的。"
+      locked: "您的帳號已被鎖定。"
+      last_attempt: "您還有最後一次嘗試機會,再次失敗您的帳號將會被鎖定。"
+      not_found_in_database: "信箱或密碼是無效的。"
+      timeout: "您的登入時效過期,請重新登入。"
+      unauthenticated: "您需要先登入或註冊後才能繼續。"
+      unconfirmed: "您的帳號需需要經過驗證後,才能繼續。"
+    mailer:
+      confirmation_instructions:
+        subject: "帳號驗證步驟"
+      reset_password_instructions:
+        subject: "密碼重設步驟"
+      unlock_instructions:
+        subject: "帳號解鎖步驟"
+    omniauth_callbacks:
+      failure: "無法從 %{kind} 驗證,因為 \"%{reason}\"。"
+      success: "成功從 %{kind} 驗證。"
+    passwords:
+      no_token: "這是密碼重設頁面,僅能透過密碼重設信件進入。如果您是透過重設信件進入的,請確認您的網址是完整的。"
+      send_instructions: "您將在幾分鐘後收到一封電子郵件,內有重新設定密碼的步驟說明。"
+      send_paranoid_instructions: "如果我們有您的信箱,您將會收到一封內含可重新設定密碼連結的電子郵件。"
+      updated: "您的密碼已被修改,您現在已經登入。"
+      updated_not_active: "您的密碼已被修改。"
+    registrations:
+      destroyed: "再會!您的帳號已被取消。有緣再會。"
+      signed_up: "註冊成功,歡迎!"
+      signed_up_but_inactive: "您已註冊成功。然而因為您的帳號尚未啓動,暫時無法登入,抱歉!"
+      signed_up_but_locked: "您已註冊成功。 然而因為您的帳號已被鎖定,暫時無法登入,抱歉!"
+      signed_up_but_unconfirmed: "確認信件已送至您的 Email 信箱,請點擊信件內連結以啓動您的帳號。"
+      update_needs_confirmation: "您已經成功的更新帳號資訊,但我們仍需確認您的電子信箱,請至新信箱收信並點擊連結以確認您的新電子郵件帳號。"
+      updated: "您已經成功的更新帳號資訊。"
+    sessions:
+      signed_in: "成功登入了。"
+      signed_out: "成功登出了。"
+    unlocks:
+      send_instructions: "您將在幾分鐘後收到一封電子郵件,內有將帳號解除鎖定的步驟說明。"
+      send_paranoid_instructions: "如果您的帳號已存在,您的電子信箱將會收到如何解鎖帳號的指示。"
+      unlocked: "您的帳號已被解鎖,現在已經登入。"
+  errors:
+    messages:
+      already_confirmed: "已經驗證,請直接登入。"
+      confirmation_period_expired: "必須在 %{period} 內驗證,請重新申請。"
+      expired: "已經過期,請重新申請。"
+      not_found: "找不到。"
+      not_locked: "並未被鎖定。"
+      not_saved:
+        one: "有一個錯誤導致 %{resource} 不能被儲存:"
+        other: "有 %{count} 個錯誤導致 %{resource} 不能被儲存:"

+ 6 - 0
config/locales/en.yml

@@ -0,0 +1,6 @@
+en:
+  breadcrumbs:
+    homepage: Homepage
+    first: First
+    second: Second
+    third: Third

+ 6 - 0
config/locales/zh-TW.yml

@@ -0,0 +1,6 @@
+zh-TW:
+  breadcrumbs:
+    homepage: 首頁
+    first: 第一頁
+    second: 第二頁
+    third: 第三頁

+ 11 - 1
template.rb

@@ -53,7 +53,8 @@ def add_gems
   gem 'sitemap_generator', '~> 6.0', '>= 6.0.1'
   gem 'whenever', require: false
   gem 'simple_form', '~> 4.1.0'
-
+  gem "breadcrumbs_on_rails", '~> 3.0.1'
+  
   gem_group :development do
     gem 'pry', '~> 0.12.2'
     gem 'bullet', '~> 6.0.0'
@@ -246,6 +247,14 @@ def add_simple_form
   generate "simple_form:install --bootstrap"
 end
 
+def add_breadcrumbs
+  content = <<-RUBY
+    config.i18n.default_locale = 'zh-TW'
+    config.time_zone = 'Taipei'
+  RUBY
+  insert_into_file "config/application.rb", "#{content}\n\n", after: "class Application < Rails::Application\n"
+end
+
 def stop_spring
   run "spring stop"
 end
@@ -299,6 +308,7 @@ after_bundle do
   add_sidekiq
   add_friendly_id
   add_simple_form
+  add_breadcrumbs
 
   copy_templates
   add_whenever