base_helper.rb 1023 B

12345678910111213141516171819202122232425262728293031323334353637
  1. module Blazer
  2. module BaseHelper
  3. def title(title = nil)
  4. if title
  5. content_for(:title) { title }
  6. else
  7. content_for?(:title) ? content_for(:title) : nil
  8. end
  9. end
  10. def format_value(key, value)
  11. if value.is_a?(Integer) && !key.to_s.end_with?("id")
  12. number_with_delimiter(value)
  13. else
  14. value
  15. end
  16. end
  17. def blazer_maps?
  18. ENV["MAPBOX_ACCESS_TOKEN"].present?
  19. end
  20. JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003e', '<' => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
  21. JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
  22. # Prior to version 4.1 of rails double quotes were inadventently removed in json_escape.
  23. # This adds the correct json_escape functionality to rails versions < 4.1
  24. def blazer_json_escape(s)
  25. if Rails::VERSION::STRING < "4.1"
  26. result = s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
  27. s.html_safe? ? result.html_safe : result
  28. else
  29. json_escape(s)
  30. end
  31. end
  32. end
  33. end