class AdHocTemplate::ConfigManager

Constants

LOCAL_SETTINGS_DIR
LOCAL_SETTINGS_FILE
SETTINGS_FILE_NAME
TAG_DEF_FILE_NAME

Public Class Methods

assign_format_label(format_label, &func) click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 27
def self.assign_format_label(format_label, &func)
  AdHocTemplate::DefaultTagFormatter.assign_format(format_label, &func)
end
configure(&config_block) click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 18
def self.configure(&config_block)
  module_eval(&config_block)
end
define_label_format(&block) click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 31
def self.define_label_format(&block)
  AdHocTemplate::DefaultTagFormatter.module_eval(&block)
end
expand_path(path) click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 44
def self.expand_path(path)
  path = File.join(LOCAL_SETTINGS_DIR, path) unless %r{\A[\./]} =~ path
  File.expand_path(path)
end
init_local_settings() click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 35
def self.init_local_settings
  config_dir = File.expand_path(LOCAL_SETTINGS_DIR)
  settings_rb = File.expand_path(LOCAL_SETTINGS_FILE)
  custom_tag_yaml = File.join(config_dir, TAG_DEF_FILE_NAME)
  FileUtils.mkdir(config_dir) unless File.exist? config_dir
  create_unless_exist(settings_rb, @local_settings_template)
  create_unless_exist(custom_tag_yaml, @custom_tag_template)
end
require_local_settings() click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 13
def self.require_local_settings
  settings_file = File.expand_path(LOCAL_SETTINGS_FILE)
  require settings_file if File.exist? settings_file
end
user_defined_tag(def_yaml_path) click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 22
def self.user_defined_tag(def_yaml_path)
  yaml_source = File.read(expand_path(def_yaml_path))
  AdHocTemplate::Parser.register_user_defined_tag_type(yaml_source)
end

Private Class Methods

create_unless_exist(path, content) click to toggle source
# File lib/ad_hoc_template/config_manager.rb, line 49
def self.create_unless_exist(path, content)
  return if File.exist? path
  File.open(path, 'wb') {|file| file.print content }
end