Class: LaTeXProjectTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/latex_project_template.rb,
lib/latex_project_template/task.rb

Defined Under Namespace

Classes: Cleaning, Component, Configuration, Directory, ErbObject, LPTConfig, Latexmk, Task

Constant Summary collapse

DEFAULT_CONFIG =
".latex_project_template"

Instance Method Summary collapse

Constructor Details

#initialize(dir, template, home_directory = nil) ⇒ LaTeXProjectTemplate

Returns a new instance of LaTeXProjectTemplate.



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/latex_project_template.rb', line 216

def initialize(dir, template, home_directory = nil)
  @config = LaTeXProjectTemplate::Configuration.new(home_directory)
  @target_dir = File.expand_path(dir)
  unless @template = @config.template_exist?(template)
    raise ArgumentError, "Can not find template: #{template}"
  end
  if File.exist?(@target_dir)
    raise ArgumentError, "File #{@target_dir} exists."
  end
  @project_name = File.basename(dir).sub(/\/$/, '')
end

Instance Method Details

#create(opts = {}) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/latex_project_template.rb', line 240

def create(opts = {})
  FileUtils.mkdir_p(@target_dir)
  git = Git.init(@target_dir)
  files = create_files
  git.add
  git.commit("Copy template: #{@template.name}.")
  if io = opts[:io]
    files.map! do |path|
      path.sub!(@target_dir, '')
      path.sub!(/^\//, '')
    end
    io.puts "Create the following files from template '#{@template.name}' and commit to git."
    io.puts files.join("\n")
  end
end