Module: ApplicationHelper
- Defined in:
- app/helpers/application_helper.rb
Instance Method Summary collapse
- #active_path(key) ⇒ Object
- #anchor_page_path(child, args = {}) ⇒ Object
- #current_structure?(item) ⇒ Boolean
- #embed_google_map_tag(query, params = {}) ⇒ Object
- #entry_url(entry) ⇒ Object
- #feature_enabled?(key) ⇒ Boolean
- #feature_price(price, tag = :div, args = {}) ⇒ Object
- #feed_item_url(item) ⇒ Object
- #file_provider_available?(provider) ⇒ Boolean
- #flag_css_by_code(country_code) ⇒ Object
- #humanized_attribute(record, key, &block) ⇒ Object
- #intent_tweet_link(name = nil, text = nil, url = nil, html_options = {}, &block) ⇒ Object
- #is_current_anchor_page?(child) ⇒ Boolean
- #nofollow_page? ⇒ Boolean
- #noindex_follow_page? ⇒ Boolean
- #payment_callback_url(options = {}) ⇒ Object
- #pretty_number(number, precision = 2, strip_zeros = true) ⇒ Object
- #profile_nav_current_link(name = nil, html_options = {}, &block) ⇒ Object
- #rating_field(stars_count = 5, rating = 5, html_options = {}, &block) ⇒ Object
- #render_submenu_block(options = {}) ⇒ Object
- #satellite_price(price) ⇒ Object
- #skype_to(skype, name = nil, html_options = {}, &block) ⇒ Object
- #structure_path(record) ⇒ Object
- #subscriber_partial_form ⇒ Object
- #subservice_path(structure) ⇒ Object
- #tel_to(tel, name = nil, html_options = {}, &block) ⇒ Object
- #upload_evaluation_attachment_path(params = {}) ⇒ Object
- #upload_free_quote_attachment_path(params = {}) ⇒ Object
- #upload_order_attachment_path(params = {}) ⇒ Object
- #widget_header(widget, alt_url = nil) ⇒ Object
Instance Method Details
#active_path(key) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/application_helper.rb', line 26 def active_path(key) Rails.cache.fetch "active_path_#{key}_#{I18n.locale}", expires_in: 4.hours do id = Settings["#{key}_id".gsub(/(?:_id)+$/, '_id')] if id structure_path(Structure.find_by(id: id)) else root_path end end end |
#anchor_page_path(child, args = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/application_helper.rb', line 91 def anchor_page_path(child, args = {}) if child.parent.position_type == PositionType.composite prefix = args.delete :anchor_prefix args[:anchor] = "#{prefix.presence || ''}#{child.slug}" if child.parent.structure_type == StructureType.main root_path(args) else page_path(child.parent.slug, args) end else page_path(child.slug) end end |
#current_structure?(item) ⇒ Boolean
72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/application_helper.rb', line 72 def current_structure?(item) return if item.nil? controller_factor = case item.structure_type when StructureType.posts then params[:controller] == 'posts' && params[:action] == 'index' else false end current_page?(structure_path(item)) || controller_factor end |
#embed_google_map_tag(query, params = {}) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'app/helpers/application_helper.rb', line 249 def (query, params = {}) kind = params[:kind] || 'place' kind = 'view' if query =~ /^\d{1,3}(.\d{1,10})?,\d{1,3}(.\d{1,10})?$/ case kind.to_s when 'view' params[:endpoint] ||= 'https://www.google.com/maps/embed/v1/view' query_key = 'center' else params[:endpoint] ||= 'https://www.google.com/maps/embed/v1/place' query_key = 'q' end params[:title] ||= @structure ? @structure.(:title) || @structure.title : Settings.slogan params[:url] ||= request.url params[:src] = [ params.delete(:endpoint), [ ['key', ENV['GMAPS_API_KEY']], ['zoom', 18], [query_key, query] ].map { |p| p.join('=') }.join('&') ].join('?') params[:frameborder] ||= 0 params[:style] ||= 'border:0' params[:allowfullscreen] ||= '' content_tag :iframe, nil, params end |
#entry_url(entry) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/helpers/application_helper.rb', line 17 def entry_url(entry) return root_url if entry.nil? case entry.class.name when 'Post' then post_url(entry) when 'Structure' then page_url(slug: entry.slug) end end |
#feature_enabled?(key) ⇒ Boolean
331 332 333 334 335 336 |
# File 'app/helpers/application_helper.rb', line 331 def feature_enabled?(key) Rails.cache.fetch "feature_#{key.hash}", expires_in: 4.hours do Settings[key].to_s.casecmp('true') == 0 || Settings["enable_#{key}"].to_s.casecmp('true') == 0 end end |
#feature_price(price, tag = :div, args = {}) ⇒ Object
115 116 117 118 119 120 121 |
# File 'app/helpers/application_helper.rb', line 115 def feature_price(price, tag = :div, args = {}) currency = args[:currency_symbol] || '$' fprice = format('%g', price) fprice = content_tag(args[:money_tag], fprice) if args[:money_tag] content_tag tag, [currency, fprice].join.html_safe, class: 'global-currency-price', "data-price": price end |
#feed_item_url(item) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/application_helper.rb', line 62 def feed_item_url(item) return if item.nil? case item.class.name when 'Post' then post_url(item.slug) when 'Structure' then page_url(slug: item.slug) else root_url end end |
#file_provider_available?(provider) ⇒ Boolean
326 327 328 329 |
# File 'app/helpers/application_helper.rb', line 326 def file_provider_available?(provider) TranslationCms.available_file_providers.present? && TranslationCms.available_file_providers.include?(provider.to_s) end |
#flag_css_by_code(country_code) ⇒ Object
317 318 319 320 321 322 323 324 |
# File 'app/helpers/application_helper.rb', line 317 def flag_css_by_code(country_code) return if country_code.nil? Rails.cache.fetch "flag_css_by_code_#{country_code}", expires_in: 1.day do country = ISO3166::Country.find_country_by_alpha3(country_code) country&.alpha2&.downcase end end |
#humanized_attribute(record, key, &block) ⇒ Object
310 311 312 313 314 315 |
# File 'app/helpers/application_helper.rb', line 310 def humanized_attribute(record, key, &block) return unless defined?(record.human_value) value = record.human_value(key) (defined?(::Rails) ? capture(value, &block) : yield(value)) if value.present? end |
#intent_tweet_link(name = nil, text = nil, url = nil, html_options = {}, &block) ⇒ Object
204 205 206 207 208 209 |
# File 'app/helpers/application_helper.rb', line 204 def intent_tweet_link(name = nil, text = nil, url = nil, = {}, &block) = ( || {}).stringify_keys text = "\u201c#{text.truncate(140 - 3 - 23)}\u201d" ['href'] = "https://twitter.com/intent/tweet?text=#{text}&url=#{url}" content_tag(:a, name || text, , &block) end |
#is_current_anchor_page?(child) ⇒ Boolean
83 84 85 86 87 88 89 |
# File 'app/helpers/application_helper.rb', line 83 def is_current_anchor_page?(child) if child.parent.position_type == PositionType.composite current_structure? child.parent else current_structure? child end end |
#nofollow_page? ⇒ Boolean
211 212 213 214 215 216 217 |
# File 'app/helpers/application_helper.rb', line 211 def nofollow_page? current_page?(new_order_path) || controller_name == 'subscribers' || TranslationCms::NOFOLLOW_SLUGS.include?(@structure.try(:slug)) || (@structure.try(:position_type) == PositionType.bottom) || writer_preview_page? end |
#noindex_follow_page? ⇒ Boolean
219 220 221 |
# File 'app/helpers/application_helper.rb', line 219 def noindex_follow_page? paginated_page? end |
#payment_callback_url(options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/application_helper.rb', line 105 def payment_callback_url( = {}) payment = [:payment] params = { provider: [:provider], tr: payment.payment_token } case [:mode] when :fail then payment.promo_uid.blank? ? payments_integrations_fail_url(params) : promo_fail_url(params) when :success then payment.promo_uid.blank? ? payments_integrations_success_url(params) : promo_success_url(params) end end |
#pretty_number(number, precision = 2, strip_zeros = true) ⇒ Object
245 246 247 |
# File 'app/helpers/application_helper.rb', line 245 def pretty_number(number, precision = 2, strip_zeros = true) number_with_precision(number, precision: precision, strip_insignificant_zeros: strip_zeros) end |
#profile_nav_current_link(name = nil, html_options = {}, &block) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/helpers/application_helper.rb', line 179 def profile_nav_current_link(name = nil, = {}, &block) # sample # <div class="profile_nav_current"> # <a href="javascript:void(0);">My Discounts <span class="bell active"></span></a> # <b></b> # </div> if block_given? = name name = nil end = ( || {}).stringify_keys [:class] = 'cabinet_nav_current' if .blank? link = content_tag(:a, name, { href: 'javascript:void(0);' }, &block) drop = content_tag(:b) content_tag(:div, link + drop, ) end |
#rating_field(stars_count = 5, rating = 5, html_options = {}, &block) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'app/helpers/application_helper.rb', line 223 def (stars_count = 5, = 5, = {}, &block) unique_id = [:id].presence || Time.current.hash.abs ans = '' # prevent non-rated field when rate > stars = stars_count if > stars_count stars_count.times do |index| [:id] = "rate_#{unique_id}_#{index}" if block_given? value = { uid: unique_id, value: index + 1, filled: index + 1 <= .floor, checked: index + 1 == .floor } ans << (defined?(::Rails) ? capture(value, &block) : yield(value)) else ans << ("rate_#{unique_id}", index + 1, index + 1 == .floor, ) end end ans.html_safe end |
#render_submenu_block(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/application_helper.rb', line 37 def ( = {}) action ||= controller.action_name class_name = controller.class.name.downcase namespace = (class_name.include?('::') ? class_name.split('::').first : nil) partials = [:partials] || [] partials << "#{controller.controller_path}/submenu_#{action}" partials << "#{controller.controller_path}/submenu" partials << "#{namespace}/submenu" if namespace partials << 'shared/submenu' partials.each do |pname| return render(partial: pname) if lookup_context.exists?(pname, nil, true) end '' end |
#satellite_price(price) ⇒ Object
55 56 57 58 59 60 |
# File 'app/helpers/application_helper.rb', line 55 def satellite_price(price) @_rate ||= TranslationCms.settings.base_rate number_to_currency(price.to_f * @_rate.value, unit: @_rate.symbol) .gsub(@_rate.symbol, content_tag(:sup, @_rate.symbol)) .html_safe end |
#skype_to(skype, name = nil, html_options = {}, &block) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/helpers/application_helper.rb', line 150 def skype_to(skype, name = nil, = {}, &block) if block_given? = name name = nil end = ( || {}).stringify_keys extras = %w[type topic].map! do |item| option = .delete(item) || next if item =~ /type/i case option when /chat/i 'chat' when /call/i 'call' when /video/i 'call&video=true' end else "#{item}=#{Rack::Utils.escape_path(option)}" end end.compact extras = extras.empty? ? '' : '?' + extras.join('&') ['href'] = "skype:#{skype}#{extras}" content_tag(:a, name || skype, , &block) end |
#structure_path(record) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/application_helper.rb', line 4 def structure_path(record) return '#' if record.nil? case record.structure_type.kind when :page then page_path(slug: record.slug) when :redirect then (record.redirect_url.presence || '#') when :main then root_path when :group then '#' else page_path(slug: record.slug) if record.structure_type.pageable? end end |
#subscriber_partial_form ⇒ Object
198 199 200 201 202 |
# File 'app/helpers/application_helper.rb', line 198 def subscriber_partial_form prefix = "#{params[:from]}_" if %w[prices posts discounts].include?(params[:from]) "subscribers/#{prefix}form" end |
#subservice_path(structure) ⇒ Object
132 133 134 135 136 |
# File 'app/helpers/application_helper.rb', line 132 def subservice_path(structure) return if structure.blank? || !structure.service_page? service_page_path(structure.sub_service_params) end |
#tel_to(tel, name = nil, html_options = {}, &block) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/helpers/application_helper.rb', line 138 def tel_to(tel, name = nil, = {}, &block) if block_given? = name name = nil end = ( || {}).stringify_keys ['href'] = "tel:#{tel}" content_tag(:a, name || tel, , &block) end |
#upload_evaluation_attachment_path(params = {}) ⇒ Object
277 278 279 280 281 282 283 284 285 286 |
# File 'app/helpers/application_helper.rb', line 277 def (params = {}) params.reverse_merge!( assetable_type: 'OrderForm', assetable_id: 0, klass: 'PickedFile' ) path = (params) # path.gsub!(%r{^/account/}, '/uploader/') unless account_signed_in? path end |
#upload_free_quote_attachment_path(params = {}) ⇒ Object
299 300 301 302 303 304 305 306 307 308 |
# File 'app/helpers/application_helper.rb', line 299 def (params = {}) params.reverse_merge!( assetable_type: 'FreeQuote', assetable_id: 0, klass: 'FreeQuoteFile', guid: '______guid______' ) path = (params) path end |
#upload_order_attachment_path(params = {}) ⇒ Object
288 289 290 291 292 293 294 295 296 297 |
# File 'app/helpers/application_helper.rb', line 288 def (params = {}) params.reverse_merge!( assetable_type: 'OrderForm', assetable_id: 0, klass: 'PickedFile' ) path = (params) path.gsub!(%r{^/account/}, '/uploader/') unless account_signed_in? path end |
#widget_header(widget, alt_url = nil) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'app/helpers/application_helper.rb', line 123 def (, alt_url = nil) title = .render_title if .link_url.blank? alt_url ? link_to(title, alt_url) : title else link_to(title, .link_url) end end |