Module: Blazer::BaseHelper
- Defined in:
- app/helpers/blazer/base_helper.rb
Constant Summary collapse
- BLAZER_URL_REGEX =
/\Ahttps?:\/\/[\S]+\z/
- BLAZER_IMAGE_EXT =
%w[png jpg jpeg gif]
- JSON_ESCAPE =
{ '&' => '\u0026', '>' => '\u003e', '<' => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
- JSON_ESCAPE_REGEXP =
/[\u2028\u2029&><]/u
Instance Method Summary collapse
- #blazer_format_value(key, value) ⇒ Object
- #blazer_js_var(name, value) ⇒ Object
-
#blazer_json_escape(s) ⇒ Object
Prior to version 4.1 of rails double quotes were inadventently removed in json_escape.
- #blazer_maps? ⇒ Boolean
- #blazer_title(title = nil) ⇒ Object
Instance Method Details
#blazer_format_value(key, value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/blazer/base_helper.rb', line 14 def blazer_format_value(key, value) if value.is_a?(Integer) && !key.to_s.end_with?("id") && !key.to_s.start_with?("id") number_with_delimiter(value) elsif value =~ BLAZER_URL_REGEX # see if image or link if Blazer.images && (key.include?("image") || BLAZER_IMAGE_EXT.include?(value.split(".").last.split("?").first.try(:downcase))) link_to value, target: "_blank" do image_tag value, referrerpolicy: "no-referrer" end else link_to value, value, target: "_blank" end else value end end |
#blazer_js_var(name, value) ⇒ Object
35 36 37 |
# File 'app/helpers/blazer/base_helper.rb', line 35 def blazer_js_var(name, value) "var #{name} = #{blazer_json_escape(value.to_json)}".html_safe end |
#blazer_json_escape(s) ⇒ Object
Prior to version 4.1 of rails double quotes were inadventently removed in json_escape. This adds the correct json_escape functionality to rails versions < 4.1
44 45 46 47 48 49 50 51 |
# File 'app/helpers/blazer/base_helper.rb', line 44 def blazer_json_escape(s) if Rails::VERSION::STRING < "4.1" result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE) s.html_safe? ? result.html_safe : result else json_escape(s) end end |
#blazer_maps? ⇒ Boolean
31 32 33 |
# File 'app/helpers/blazer/base_helper.rb', line 31 def blazer_maps? ENV["MAPBOX_ACCESS_TOKEN"].present? end |
#blazer_title(title = nil) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/blazer/base_helper.rb', line 3 def blazer_title(title = nil) if title content_for(:title) { title } else content_for?(:title) ? content_for(:title) : nil end end |