Module: FastComments::Jekyll::KeyMapper

Defined in:
lib/fastcomments/jekyll/key_mapper.rb

Overview

Maps snake_case tag/_config keys to the camelCase keys FastComments expects.

Class Method Summary collapse

Class Method Details

.map_keys(hash) ⇒ Object

Camelize top-level keys only; nested values (e.g. translations) pass through verbatim.



17
18
19
# File 'lib/fastcomments/jekyll/key_mapper.rb', line 17

def map_keys(hash)
  hash.each_with_object({}) { |(key, value), out| out[to_camel(key)] = value }
end

.to_camel(key) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/fastcomments/jekyll/key_mapper.rb', line 7

def to_camel(key)
  str = key.to_s
  return str unless str.include?("_")

  parts = str.split("_")
  head = parts.shift
  head + parts.map { |part| part.empty? ? "" : part[0].upcase + part[1..] }.join
end