Sha256: c93f19cafa0b3adc2207bec5b31def1d7e0764a8648feafab4494dd7fda4211a

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

module Blazer
  module BaseHelper
    def blazer_title(title = nil)
      if title
        content_for(:title) { title }
      else
        content_for?(:title) ? content_for(:title) : nil
      end
    end

    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

    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

    def blazer_maps?
      ENV["MAPBOX_ACCESS_TOKEN"].present?
    end

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

    # 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
    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
blazer-1.3.5 app/helpers/blazer/base_helper.rb
blazer-1.3.4 app/helpers/blazer/base_helper.rb
blazer-1.3.3 app/helpers/blazer/base_helper.rb
blazer-1.3.2 app/helpers/blazer/base_helper.rb
blazer-1.3.1 app/helpers/blazer/base_helper.rb
blazer-1.3.0 app/helpers/blazer/base_helper.rb
blazer-1.2.1 app/helpers/blazer/base_helper.rb
blazer-1.2.0 app/helpers/blazer/base_helper.rb
blazer-1.1.1 app/helpers/blazer/base_helper.rb