Module: Blazer::BaseHelper

Defined in:
app/helpers/blazer/base_helper.rb

Constant Summary collapse

JSON_ESCAPE =
{ '&' => '\u0026', '>' => '\u003e', '<' => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
JSON_ESCAPE_REGEXP =
/[\u2028\u2029&><]/u

Instance Method Summary collapse

Instance Method Details

#blazer_column_types(columns, rows, boom) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/blazer/base_helper.rb', line 19

def blazer_column_types(columns, rows, boom)
  columns.map do |k, _|
    v = (rows.find { |r| r[k] } || {})[k]
    if boom[k]
      "string"
    elsif v.is_a?(Numeric)
      "numeric"
    elsif v.is_a?(Time) || v.is_a?(Date)
      "time"
    elsif v.nil?
      nil
    else
      "string"
    end
  end
end

#blazer_format_value(key, value) ⇒ Object



11
12
13
14
15
16
17
# File 'app/helpers/blazer/base_helper.rb', line 11

def blazer_format_value(key, value)
  if value.is_a?(Integer) && !key.to_s.end_with?("id")
    number_with_delimiter(value)
  else
    value
  end
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



45
46
47
48
49
50
51
52
# File 'app/helpers/blazer/base_helper.rb', line 45

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

Returns:

  • (Boolean)


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

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