module R18n::Utils

Common methods for another R18n code.

Public Class Methods

deep_merge!(one, another) click to toggle source

Recursively hash merge.

# File lib/r18n-core/utils.rb, line 33
def self.deep_merge!(one, another)
  another.each_pair do |key, another_value|
    value = one[key]
    one[key] =
      if value.is_a?(Hash) && another_value.is_a?(Hash)
        deep_merge!(value, another_value)
      else
        another_value
      end
  end
  one
end
escape_html(content) click to toggle source

Escape HTML entries (<, >, &). Copy from HAML helper.

# File lib/r18n-core/utils.rb, line 24
def self.escape_html(content)
  if defined? ActiveSupport::SafeBuffer
    ActiveSupport::SafeBuffer.new + content
  else
    CGI.escapeHTML content
  end
end
underscore(string) click to toggle source
# File lib/r18n-core/utils.rb, line 46
def self.underscore(string)
  string
    .gsub(/::/, '/')
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .downcase
end