Module: EnjuLeaf::ApplicationHelper
- Defined in:
- app/helpers/enju_leaf/application_helper.rb
Instance Method Summary collapse
-
#back_to_index(options = {}) ⇒ Object
前の画面に戻るリンクを表示します。.
-
#current_user_role_name ⇒ Object
ログイン中のユーザの権限名を表示します。.
-
#database_adapter ⇒ Object
使用中のデータベースのアダプタ名を表示します。.
- #link_to_wikipedia(string) ⇒ Object
- #locale_display_name(locale) ⇒ Object
- #locale_native_name(locale) ⇒ Object
-
#localized_boolean(bool) ⇒ Object
I18nに対応した状態名を表示します。.
-
#localized_state(state) ⇒ Object
I18nに対応した状態名を表示します。.
-
#markdown_helper(string) ⇒ Object
Markdownの文字列をパースして表示します。.
-
#messages_count(user) ⇒ Object
ユーザの未読メッセージ数を表示します。.
- #move_position(object) ⇒ Object
-
#set_focus_on_search_form ⇒ Object
検索フォームにフォーカスを移動するJavaScriptを表示します。.
-
#title(controller_name, model_name = controller_name.singularize) ⇒ Object
HTMLのtitleを表示します。.
-
#title_action_name ⇒ Object
HTMLのtitleに表示されるアクション名を設定します。.
Instance Method Details
#back_to_index(options = {}) ⇒ Object
前の画面に戻るリンクを表示します。
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 96 def back_to_index( = {}) if == nil = {} else .reject!{|_key, value| value.blank?} .delete(:page) if [:page].to_i == 1 end unless controller_name == 'test' link_to t('page.listing', model: t("activerecord.models.#{controller_name.singularize}")), url_for(filtered_params.merge(controller: controller_name, action: :index, page: nil, id: nil, only_path: true).merge()) end end |
#current_user_role_name ⇒ Object
ログイン中のユーザの権限名を表示します。
77 78 79 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 77 def current_user_role_name current_user.try(:role).try(:name) || 'Guest' end |
#database_adapter ⇒ Object
使用中のデータベースのアダプタ名を表示します。
4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 4 def database_adapter case ActiveRecord::Base.connection.adapter_name when 'PostgreSQL' link_to 'PostgreSQL', 'http://www.postgresql.org/' when 'MySQL' link_to 'MySQL', 'http://www.mysql.org/' when 'SQLite' link_to 'SQLite', 'http://www.sqlite.org/' end end |
#link_to_wikipedia(string) ⇒ Object
29 30 31 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 29 def link_to_wikipedia(string) link_to "Wikipedia", "http://#{I18n.locale}.wikipedia.org/wiki/#{URI.escape(string)}" end |
#locale_display_name(locale) ⇒ Object
33 34 35 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 33 def locale_display_name(locale) Language.where(iso_639_1: locale).first.display_name end |
#locale_native_name(locale) ⇒ Object
37 38 39 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 37 def locale_native_name(locale) Language.where(iso_639_1: locale).first.native_name end |
#localized_boolean(bool) ⇒ Object
I18nに対応した状態名を表示します。
66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 66 def localized_boolean(bool) case bool.to_s when nil when "true" t('page.boolean.true') when "false" t('page.boolean.false') end end |
#localized_state(state) ⇒ Object
I18nに対応した状態名を表示します。
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 47 def localized_state(state) case state when 'pending' t('state.pending') when 'canceled' t('state.canceled') when 'started' t('state.started') when 'failed' t('state.failed') when 'completed' t('state.completed') else state end end |
#markdown_helper(string) ⇒ Object
Markdownの文字列をパースして表示します。
115 116 117 118 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 115 def markdown_helper(string) return unless string Kramdown::Document.new(string.to_s).to_html.html_safe end |
#messages_count(user) ⇒ Object
ユーザの未読メッセージ数を表示します。
122 123 124 125 126 127 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 122 def (user) Message.search do with(:receiver_id).equal_to user.id with(:is_read).equal_to false end.hits.total_entries end |
#move_position(object) ⇒ Object
41 42 43 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 41 def move_position(object) render partial: 'page/position', locals: {object: object} end |
#set_focus_on_search_form ⇒ Object
検索フォームにフォーカスを移動するJavaScriptを表示します。
109 110 111 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 109 def set_focus_on_search_form javascript_tag("$(function(){$('#search_form').focus()})") if @query.blank? end |
#title(controller_name, model_name = controller_name.singularize) ⇒ Object
HTMLのtitleを表示します。
82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 82 def title(controller_name, model_name = controller_name.singularize) string = '' unless ['page', 'routing_error', 'my_accounts'].include?(controller_name) string << t("activerecord.models.#{model_name}") + ' - ' end if controller_name == 'routing_error' string << t("page.routing_error") + ' - ' end string << LibraryGroup.system_name + ' - Next-L Enju Leaf' string.html_safe end |
#title_action_name ⇒ Object
HTMLのtitleに表示されるアクション名を設定します。
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/enju_leaf/application_helper.rb', line 16 def title_action_name case controller.action_name when 'index' t('title.index') when 'show' t('title.show') when 'new' t('title.new') when 'edit' t('title.edit') end end |