Module: Locomotive::BaseHelper
- Defined in:
- app/helpers/locomotive/base_helper.rb
Instance Method Summary collapse
-
#application_domain ⇒ Object
sites.
- #backbone_view_class_name ⇒ Object
- #backbone_view_data ⇒ Object
-
#flag_tag(locale, size = '24x24') ⇒ String
Display the image of the flag representing the locale.
- #flash_message ⇒ Object
- #inputs_folded?(resource) ⇒ Boolean
-
#link_to_icon(name, *args, &block) ⇒ String
Like link_to but instead of passing a label, we pass the name of an Font Awesome icon.
- #local_action_button(text, url, options = {}) ⇒ Object
- #locale_picker_link ⇒ Object
- #manage_domains? ⇒ Boolean
- #manage_subdomain? ⇒ Boolean
- #manage_subdomain_or_domains? ⇒ Boolean
- #multi_sites? ⇒ Boolean
- #nocoffee_tag ⇒ Object
-
#not_the_default_current_locale? ⇒ Boolean
For a localized site, tell if the current content locale does not match the default locale of the site.
-
#options_for_membership_roles(options = {}) ⇒ Object
memberships.
- #public_page_url(page, options = {}) ⇒ Object
-
#required_once(label, &block) ⇒ Object
Execute the code only once during the request time.
- #submenu_entry(name, url, options = {}, &block) ⇒ Object
- #title(title = nil) ⇒ Object
Instance Method Details
#application_domain ⇒ Object
sites
126 127 128 129 130 |
# File 'app/helpers/locomotive/base_helper.rb', line 126 def application_domain domain = Locomotive.config.domain domain += ":#{request.port}" if request.port != 80 domain end |
#backbone_view_class_name ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/locomotive/base_helper.rb', line 94 def backbone_view_class_name action = case controller.action_name when 'create' then 'New' when 'update' then 'Edit' else controller.action_name end.camelize "Locomotive.Views.#{controller.controller_name.camelize}.#{action}View" end |
#backbone_view_data ⇒ Object
105 106 107 |
# File 'app/helpers/locomotive/base_helper.rb', line 105 def backbone_view_data content_for?(:backbone_view_data) ? content_for(:backbone_view_data) : '' end |
#flag_tag(locale, size = '24x24') ⇒ String
Display the image of the flag representing the locale.
116 117 118 |
# File 'app/helpers/locomotive/base_helper.rb', line 116 def flag_tag(locale, size = '24x24') image_tag("locomotive/icons/flags/#{locale}.png", :class => 'flag', :size => size) end |
#flash_message ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/locomotive/base_helper.rb', line 83 def if not flash.empty? first_key = flash.keys.first content_tag :div, flash[first_key], :id => "flash-#{first_key}", :class => 'application-message' else '' end end |
#inputs_folded?(resource) ⇒ Boolean
13 14 15 |
# File 'app/helpers/locomotive/base_helper.rb', line 13 def inputs_folded?(resource) resource.persisted? && resource.errors.empty? end |
#link_to_icon(name, *args, &block) ⇒ String
Like link_to but instead of passing a label, we pass the name of an Font Awesome icon. If the name is a Symbol, we append “icon-” to the dasherized version of the name.
27 28 29 30 31 |
# File 'app/helpers/locomotive/base_helper.rb', line 27 def link_to_icon(name, *args, &block) name = name.is_a?(Symbol) ? "icon-#{name.to_s.dasherize}" : name icon = content_tag(:i, '', :class => name) link_to(icon, *args, &block).html_safe end |
#local_action_button(text, url, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/locomotive/base_helper.rb', line 64 def (text, url, = {}) text = text.is_a?(Symbol) ? t(".#{text}") : text icon = .delete(:icon) || :exclamation_sign icon = icon.is_a?(Symbol) ? "icon-#{icon.to_s.dasherize}" : icon link_to(url, ) do content_tag(:i, '', :class => icon) + text end end |
#locale_picker_link ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/helpers/locomotive/base_helper.rb', line 75 def locale_picker_link if current_site.locales.size > 1 && localized? content_tag :div, render('locomotive/shared/locale_picker_link'), :class => 'action' else nil end end |
#manage_domains? ⇒ Boolean
140 141 142 |
# File 'app/helpers/locomotive/base_helper.rb', line 140 def manage_domains? Locomotive.config.manage_domains? end |
#manage_subdomain? ⇒ Boolean
136 137 138 |
# File 'app/helpers/locomotive/base_helper.rb', line 136 def manage_subdomain? Locomotive.config.manage_subdomain? end |
#manage_subdomain_or_domains? ⇒ Boolean
132 133 134 |
# File 'app/helpers/locomotive/base_helper.rb', line 132 def manage_subdomain_or_domains? Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains? end |
#multi_sites? ⇒ Boolean
144 145 146 |
# File 'app/helpers/locomotive/base_helper.rb', line 144 def multi_sites? Locomotive.config.multi_sites? end |
#nocoffee_tag ⇒ Object
120 121 122 |
# File 'app/helpers/locomotive/base_helper.rb', line 120 def nocoffee_tag link_to 'noCoffee', 'http://www.nocoffee.fr', :id => 'nocoffee' end |
#not_the_default_current_locale? ⇒ Boolean
For a localized site, tell if the current content locale does not match the default locale of the site. It is used by the page / snippet forms to determine if we have to display the warning message letting the designer know that the template is only editable in the default locale.
177 178 179 |
# File 'app/helpers/locomotive/base_helper.rb', line 177 def not_the_default_current_locale? current_site.localized? && current_content_locale.to_s != current_site.default_locale.to_s end |
#options_for_membership_roles(options = {}) ⇒ Object
memberships
158 159 160 161 162 163 164 165 166 |
# File 'app/helpers/locomotive/base_helper.rb', line 158 def ( = {}) list = (unless [:skip_admin] Locomotive::Ability::ROLES.map { |r| [t("locomotive.memberships.roles.#{r}"), r] } else (Locomotive::Ability::ROLES - ['admin']).map { |r| [t("locomotive.memberships.roles.#{r}"), r] } end) (list) end |
#public_page_url(page, options = {}) ⇒ Object
148 149 150 151 152 153 154 |
# File 'app/helpers/locomotive/base_helper.rb', line 148 def public_page_url(page, = {}) if content = .delete(:content) File.join(current_site_public_url, page.fullpath.gsub('content_type_template', ''), content._slug) else File.join(current_site_public_url, page.fullpath) end end |
#required_once(label, &block) ⇒ Object
Execute the code only once during the request time. It avoids duplicated dom elements in the rendered rails page.
38 39 40 41 42 43 44 45 |
# File 'app/helpers/locomotive/base_helper.rb', line 38 def required_once(label, &block) symbol = :"@block_#{label.to_s.underscore}" if instance_variable_get(symbol).blank? yield instance_variable_set(symbol, true) end end |
#submenu_entry(name, url, options = {}, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/locomotive/base_helper.rb', line 47 def (name, url, = {}, &block) = { :i18n => true, :css => name.dasherize.downcase } .merge!() css = "#{'on' if name == sections(:sub)} #{[:css]}" label_link = [:i18n] ? t("locomotive.shared.menu.#{name}") : name if block_given? popup = content_tag(:div, capture(&block), :class => 'popup', :style => 'display: none') text = content_tag(:span, preserve(label_link) + content_tag(:i, '', :class => 'icon-caret-down')) link = link_to(text + content_tag(:em), url, :class => css) content_tag(:li, link + popup, :class => 'hoverable') else content_tag(:li, link_to(content_tag(:span, label_link), url, :class => css)) end end |
#title(title = nil) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/helpers/locomotive/base_helper.rb', line 4 def title(title = nil) if title.nil? @content_for_title else @content_for_title = title '' end end |