Module: R18n::Utils

Defined in:
lib/r18n-core/utils.rb

Class Method Summary collapse

Class Method Details

.deep_merge!(one, another) ⇒ Object

Recursively hash merge.



33
34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object

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



24
25
26
27
28
29
30
# 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) ⇒ Object



46
47
48
49
50
51
52
53
# 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