Module: Kramdown::Utils

Defined in:
lib/kramdown/utils.rb,
lib/kramdown/utils/html.rb,
lib/kramdown/utils/entities.rb,
lib/kramdown/utils/unidecoder.rb,
lib/kramdown/utils/configurable.rb,
lib/kramdown/utils/ordered_hash.rb,
lib/kramdown/utils/string_scanner.rb

Overview

Utils Module

This module contains utility class/modules/methods that can be used by both parsers and converters.

Defined Under Namespace

Modules: Configurable, Entities, Html, Unidecoder Classes: OrderedHash, StringScanner

Class Method Summary collapse

Class Method Details

.camelize(name) ⇒ Object

Treat name as if it were snake cased (e.g. snake_case) and camelize it (e.g. SnakeCase).



26
27
28
# File 'lib/kramdown/utils.rb', line 26

def self.camelize(name)
  name.split('_').inject('') {|s,x| s << x[0..0].upcase << x[1..-1] }
end

.deep_const_get(str) ⇒ Object

Resolve the recursive constant str.



42
43
44
45
46
# File 'lib/kramdown/utils.rb', line 42

def self.deep_const_get(str)
  names = str.split(/::/)
  names.shift if names.first.empty?
  names.inject(::Object) {|mod, s| mod.const_get(s)}
end

.snake_case(name) ⇒ Object

Treat name as if it were camelized (e.g. CamelizedName) and snake-case it (e.g. camelized_name).



31
32
33
34
35
36
37
# File 'lib/kramdown/utils.rb', line 31

def self.snake_case(name)
  name = name.dup
  name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  name.gsub!(/([a-z])([A-Z])/,'\1_\2')
  name.downcase!
  name
end