Class: LaTeXProjectTemplate::Configuration
- Inherits:
-
Object
- Object
- LaTeXProjectTemplate::Configuration
- Defined in:
- lib/latex_project_template.rb
Constant Summary collapse
- TEMPLATE_DIRECTORY =
'template'
- VARIABLE_DIRECTORY =
'variable'
- COMPONENT_DIRECTORY =
'component'
- DEFAULT_PROFILE_YAML =
{ :name => "Your Name" }
Class Method Summary collapse
Instance Method Summary collapse
- #component(name) ⇒ Object
- #config_directory ⇒ Object
- #delete_template(template) ⇒ Object
-
#initialize(home_path) ⇒ Configuration
constructor
A new instance of Configuration.
- #list_template ⇒ Object
- #template_exist?(template) ⇒ Boolean
- #user_variables ⇒ Object
Constructor Details
#initialize(home_path) ⇒ Configuration
Returns a new instance of Configuration.
34 35 36 |
# File 'lib/latex_project_template.rb', line 34 def initialize(home_path) @user_config = LPTConfig.new(DEFAULT_CONFIG, :home => home_path) end |
Class Method Details
.create_new_config(home_path = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/latex_project_template.rb', line 19 def self.create_new_config(home_path = nil) begin config = LPTConfig.new(DEFAULT_CONFIG, :home => home_path, :new_directory => true) dir = config.directory Dir.glob(File.(File.join(File.dirname(__FILE__), '../initial_files/*'))).each do |path| FileUtils.cp_r(path, dir) end git = Git.init(dir) git.add git.commit("Create initial template.") rescue UserConfig::DirectoryExistenceError $stderr.puts "Can not new configuration directory." end end |
Instance Method Details
#component(name) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/latex_project_template.rb', line 77 def component(name) if path = @user_config.exist?(File.join(COMPONENT_DIRECTORY, name)) return LaTeXProjectTemplate::Component.new(path) end nil end |
#config_directory ⇒ Object
38 39 40 |
# File 'lib/latex_project_template.rb', line 38 def config_directory @user_config.directory end |
#delete_template(template) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/latex_project_template.rb', line 58 def delete_template(template) if String === template && template.size > 0 @user_config.delete(user_config_template_path(template)) else raise ArgumentError, "Invalid template name to delete: #{template.inspect}" end end |
#list_template ⇒ Object
42 43 44 |
# File 'lib/latex_project_template.rb', line 42 def list_template @user_config.list_in_directory(TEMPLATE_DIRECTORY) end |
#template_exist?(template) ⇒ Boolean
51 52 53 54 55 56 |
# File 'lib/latex_project_template.rb', line 51 def template_exist?(template) if path = @user_config.exist?(user_config_template_path(template)) return LaTeXProjectTemplate::Directory.new(path) end false end |
#user_variables ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/latex_project_template.rb', line 66 def user_variables vars = {} if dir = @user_config.exist?('variable') Dir.glob(File.join(dir, '*.yaml')).each do |yaml_path| key = File.basename(yaml_path).sub(/\.yaml$/, '').intern vars[key] = YAML.load_file(yaml_path) end end vars end |