Module: Microservice::ApplicationHelper
- Defined in:
- app/helpers/microservice/application_helper.rb
Instance Method Summary collapse
- #application_name ⇒ Object
- #css_active_menu_item(identificator) ⇒ Object
- #favicon_path ⇒ Object
- #format_date(date) ⇒ Object
- #format_time(time, include_date = true) ⇒ Object
- #home_link(namespace = nil, options = {}) ⇒ Object
- #html_title(*args) ⇒ Object
- #html_title_from_entity ⇒ Object
- #link_to_entity(klass_or_entity, action = nil, options = {}) ⇒ Object
- #link_to_function(name, function = nil, html_options = {}, &block) ⇒ Object
- #login_link(options = {}) ⇒ Object
- #logout_link(options = {}) ⇒ Object
- #markdown(text) ⇒ Object
- #render_flash_messages ⇒ Object
- #show_top_menu_new? ⇒ Boolean
- #show_top_menu_search? ⇒ Boolean
- #signup_link(options = {}) ⇒ Object
- #sso_login_link(options = {}) ⇒ Object
- #title(*args) ⇒ Object
Instance Method Details
#application_name ⇒ Object
4 5 6 |
# File 'app/helpers/microservice/application_helper.rb', line 4 def application_name Microservice::Settings.application_name end |
#css_active_menu_item(identificator) ⇒ Object
92 93 94 95 96 |
# File 'app/helpers/microservice/application_helper.rb', line 92 def (identificator) css = ['item'] css << 'active' if active_link?(identificator) css.join(' ') end |
#favicon_path ⇒ Object
54 55 56 |
# File 'app/helpers/microservice/application_helper.rb', line 54 def favicon_path image_path('microservice/favicon.ico') end |
#format_date(date) ⇒ Object
77 78 79 80 81 |
# File 'app/helpers/microservice/application_helper.rb', line 77 def format_date(date) return nil unless date ::I18n.l(date.to_date, {format: '%d.%m.%Y'}) end |
#format_time(time, include_date = true) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'app/helpers/microservice/application_helper.rb', line 83 def format_time(time, include_date = true) return nil unless time = {} [:format] = '%H:%M' time = time.to_time if time.is_a?(String) local = (time.utc? ? time.localtime : time) (include_date ? "#{format_date(local)} " : '') + ::I18n.l(local, ) end |
#home_link(namespace = nil, options = {}) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'app/helpers/microservice/application_helper.rb', line 180 def home_link(namespace = nil, = {}) = namespace if namespace.is_a?(Hash) if namespace == :admin link_to(t(:button_administration), main_app.admin_path, {title: t(:title_administration), class: (:administration), data: {turbolinks: false}}.merge()) else link_to(t(:button_home), main_app.root_path, {title: t(:title_home), class: (:home), data: {turbolinks: false}}.merge()) end end |
#html_title(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/microservice/application_helper.rb', line 29 def html_title(*args) if args.empty? title = [application_name] title.concat(@html_title || []) title.reject(&:blank?).join(' - ') else @html_title ||= [] @html_title += args end end |
#html_title_from_entity ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/microservice/application_helper.rb', line 58 def html_title_from_entity if @entity case action_name when 'show' html_title @entity.heading_show when 'new', 'create' html_title @entity.heading_new when 'edit', 'update' html_title @entity.heading_edit else html_title end elsif controller.respond_to?(:entity_class) && controller.entity_class html_title controller.entity_class.heading_index else html_title end end |
#link_to_entity(klass_or_entity, action = nil, options = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/microservice/application_helper.rb', line 98 def link_to_entity(klass_or_entity, action = nil, = {}) entity_class = klass_or_entity.is_a?(ActiveRecord::Base) ? klass_or_entity.class : klass_or_entity entity = klass_or_entity.is_a?(ActiveRecord::Base) ? klass_or_entity : nil , action = action, nil if action.is_a?(Hash) && action. action ||= (entity ? :show : :index) if [:css_item] css = (entity_class) [:class] ||= '' [:class] << (' ' + css) if css.present? [:no_icon] = true if !.key?(:no_icon) end case action when :index # if @entity && entity_class.parent_entity_class == @entity.class && @parent_entity.nil? # route_array = entity_class.class_route_array(@entity) # else # route_array = entity_class.class_route_array(@parent_entity) # end link_to(polymorphic_path(entity_class.class_route_array(@parent_entity)), class: [:class], title: entity_class.title_index, data: [:data]) do content_tag(:i, '', class: ([:no_icon] ? '' : 'icon ' + entity_class.css_class)) + entity_class. end when :show link_to(polymorphic_path(entity.model_route_array), class: [:class], title: entity.title_show, data: [:data]) do content_tag(:i, '', class: ([:no_icon] ? '' : 'info icon')) + ([:no_label] ? '' : entity.) end when :new link_to(new_polymorphic_path(entity_class.class_route_array(@parent_entity)), class: [:class], title: entity_class.title_new, data: [:data]) do content_tag(:i, '', class: ([:no_icon] ? '' : 'add icon')) + entity_class. end when :edit link_to(edit_polymorphic_path(entity.model_route_array), class: [:class], title: entity.title_edit, data: [:data]) do content_tag(:i, '', class: ([:no_icon] ? '' : 'edit icon')) + ([:no_label] ? '' : entity.) end when :delete link_to(polymorphic_path(entity.model_route_array), class: [:class], title: entity.title_delete, data: {confirm: t(:text_are_you_sure), method: :delete}) do content_tag(:i, '', class: ([:no_icon] ? '' : 'trash icon')) end end end |
#link_to_function(name, function = nil, html_options = {}, &block) ⇒ Object
143 144 145 146 147 148 149 |
# File 'app/helpers/microservice/application_helper.rb', line 143 def link_to_function(name, function = nil, = {}, &block) if block_given? content_tag(:a, {href: '#', onclick: "#{name}; return false;"}.merge(function || {}), &block) else content_tag(:a, name, {href: '#', onclick: "#{function}; return false;"}.merge()) end end |
#login_link(options = {}) ⇒ Object
190 191 192 193 194 195 |
# File 'app/helpers/microservice/application_helper.rb', line 190 def login_link( = {}) css = ['item'] css << 'active' if controller_name == 'UsersController' link_to(t(:button_log_in), main_app.new_user_session_path, {title: t(:title_log_in), class: css.join(' '), data: {turbolinks: false}}.merge()) end |
#logout_link(options = {}) ⇒ Object
209 210 211 212 213 |
# File 'app/helpers/microservice/application_helper.rb', line 209 def logout_link( = {}) css = ['item'] link_to(t(:button_log_out), main_app.destroy_user_session_path, {title: t(:title_log_out), class: css.join(' '), method: :delete, data: {turbolinks: false}}.merge()) end |
#markdown(text) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/helpers/microservice/application_helper.rb', line 151 def markdown(text) = { filter_html: true, hard_wrap: true, link_attributes: {rel: 'nofollow', target: '_blank'}, space_after_headers: true, fenced_code_blocks: true } extensions = { autolink: true, superscript: true, disable_indented_code_blocks: true } renderer = Redcarpet::Render::HTML.new() markdown = Redcarpet::Markdown.new(renderer, extensions) markdown.render(text.to_s).html_safe end |
#render_flash_messages ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/microservice/application_helper.rb', line 8 def s = '' flash.each do |k, v| case k when 'alert' = 'warning' icon_css = 'warning' else = 'success' icon_css = 'info' end s << "<div class=\"ui icon #{message_css} message\">" s << '<i class="close icon"></i>' s << "<i class=\"#{icon_css} icon\"></i>" s << '<div class=\"content\"></div>' s << "<div class=\"header\">#{v}</div>" s << '</div>' end s.html_safe end |
#show_top_menu_new? ⇒ Boolean
172 173 174 |
# File 'app/helpers/microservice/application_helper.rb', line 172 def controller.respond_to?(:entity_class) && controller.entity_class && !controller.entity_class. end |
#show_top_menu_search? ⇒ Boolean
176 177 178 |
# File 'app/helpers/microservice/application_helper.rb', line 176 def controller.respond_to?(:entity_class) && controller.entity_class && !controller.entity_class. end |
#signup_link(options = {}) ⇒ Object
203 204 205 206 207 |
# File 'app/helpers/microservice/application_helper.rb', line 203 def signup_link( = {}) css = ['item'] link_to(t(:button_sign_up), 'https://www.easysoftware.com', {title: t(:title_sign_up), class: css.join(' '), data: {turbolinks: false}}.merge()) end |
#sso_login_link(options = {}) ⇒ Object
197 198 199 200 201 |
# File 'app/helpers/microservice/application_helper.rb', line 197 def sso_login_link( = {}) css = ['item'] link_to(t(:button_log_in), main_app., {title: t(:title_log_in), class: css.join(' '), data: {turbolinks: false}}.merge()) end |
#title(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/microservice/application_helper.rb', line 40 def title(*args) strings = args.map do |arg| if arg.is_a?(Array) && arg.size >= 2 link_to(*arg) else h(arg.to_s) end end html_title(args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s}) content_tag('h1', strings.join(' » ').html_safe, class: 'ui header') end |