Class: Handlebars::Helpers::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/handlebars/helpers/configuration.rb

Overview

Configuration class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



36
37
38
39
40
41
42
43
44
# 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

Instance Attribute Details

#helper_config_fileObject

Returns the value of attribute helper_config_file.



27
28
29
# File 'lib/handlebars/helpers/configuration.rb', line 27

def helper_config_file
  @helper_config_file
end

#padl_charObject

Returns the value of attribute padl_char.



27
28
29
# File 'lib/handlebars/helpers/configuration.rb', line 27

def padl_char
  @padl_char
end

#padl_countObject

Returns the value of attribute padl_count.



27
28
29
# File 'lib/handlebars/helpers/configuration.rb', line 27

def padl_count
  @padl_count
end

#padr_charObject

Returns the value of attribute padr_char.



27
28
29
# File 'lib/handlebars/helpers/configuration.rb', line 27

def padr_char
  @padr_char
end

#padr_countObject

Returns the value of attribute padr_count.



27
28
29
# File 'lib/handlebars/helpers/configuration.rb', line 27

def padr_count
  @padr_count
end

#string_formatter_configObject



53
54
55
# File 'lib/handlebars/helpers/configuration.rb', line 53

def string_formatter_config
  @string_formatter_config ||= build_string_formatter_config
end

#string_formatter_config_fileObject

Returns the value of attribute string_formatter_config_file.



33
34
35
# File 'lib/handlebars/helpers/configuration.rb', line 33

def string_formatter_config_file
  @string_formatter_config_file
end

#tokenizerObject

Returns the value of attribute tokenizer.



27
28
29
# File 'lib/handlebars/helpers/configuration.rb', line 27

def tokenizer
  @tokenizer
end

Instance Method Details

#build_string_formatter_configObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# 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