class Handlebars::Helpers::Configuration

Configuration class

Attributes

helper_config_file[RW]
padl_char[RW]
padl_count[RW]
padr_char[RW]
padr_count[RW]
string_formatter_config[W]
string_formatter_config_file[R]
tokenizer[RW]

Public Class Methods

new() click to toggle source
# File lib/handlebars/helpers/configuration.rb, line 36
def initialize
  @tokenizer = Handlebars::Helpers::StringTokenizer.new
  @helper_config_file = '.handlebars_helpers.json'
  @string_formatter_config_file = '.handlebars_string_formatters.json'
  @padr_count = 30
  @padr_char = ' '
  @padl_count = 30
  @padl_char = ' '
end

Public Instance Methods

build_string_formatter_config() click to toggle source
# File lib/handlebars/helpers/configuration.rb, line 57
def build_string_formatter_config
  config_content = File.read(string_formatter_config_file)
  config = JSON.parse(config_content)
  configured_formatters = config['formatters']
  configured_formatters.each_with_object({}) do |formatter, result|
    require formatter['require_path']
    helper_instance = Object.const_get(formatter['class_namespace']).new

    formatter['aliases'].each do |name|
      result[name.to_sym] = helper_instance
    end
  end
end
string_formatter_config() click to toggle source
# File lib/handlebars/helpers/configuration.rb, line 53
def string_formatter_config
  @string_formatter_config ||= build_string_formatter_config
end
string_formatter_config_file=(value) click to toggle source
# File lib/handlebars/helpers/configuration.rb, line 46
def string_formatter_config_file=(value)
  @string_formatter_config_file = value
  # updating the file will clear the config object,
  # which will be reloaded on next call to string_formatter_config
  self.string_formatter_config = nil
end