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]

Instance Method Summary collapse

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?(Numeric) && !key.to_s.end_with?("id") && !key.to_s.start_with?("id")
    number_with_delimiter(value)
  elsif value.is_a?(String) && 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



31
32
33
# File 'app/helpers/blazer/base_helper.rb', line 31

def blazer_js_var(name, value)
  "var #{name} = #{json_escape(value.to_json(root: false))};".html_safe
end

#blazer_series_name(k) ⇒ Object



35
36
37
# File 'app/helpers/blazer/base_helper.rb', line 35

def blazer_series_name(k)
  k.nil? ? "null" : k.to_s
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