Class: LaTeXProjectTemplate::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) {|_self| ... } ⇒ Task

Returns a new instance of Task.

Yields:

  • (_self)

Yield Parameters:



82
83
84
85
86
87
88
89
# File 'lib/latex_project_template/task.rb', line 82

def initialize(target, &block)
  @target = target
  @latexmk = Latexmk.new
  @clean = Cleaning.new
  @default = :pdf
  yield(self) if block_given?
  define_task
end

Instance Attribute Details

#cleanObject

Returns the value of attribute clean.



80
81
82
# File 'lib/latex_project_template/task.rb', line 80

def clean
  @clean
end

#defaultObject

Returns the value of attribute default.



80
81
82
# File 'lib/latex_project_template/task.rb', line 80

def default
  @default
end

#latexmkObject

Returns the value of attribute latexmk.



80
81
82
# File 'lib/latex_project_template/task.rb', line 80

def latexmk
  @latexmk
end

Instance Method Details

#define_taskObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/latex_project_template/task.rb', line 163

def define_task
  desc "Default task"
  task :default => @default

  desc "Clean up temporary files."
  task :clean do |t|
    @latexmk.clean(@target)
    @clean.clean
  end

  desc "Clean up all files."
  task :distclean do |t|
    @latexmk.distclean(@target)
    @clean.clean
  end

  Latexmk::COMMAND_TO_PRODUCE_FILE.each do |type|
    desc "Create #{type.to_s}."
    task type => [@target] do |t|
      @latexmk.__send__(type, @target)
    end
  end

  desc "Create snapshot file."
  task :snapshot, [:type,:commit] do |t, args|
    type = args.type && args.type.size > 0 ? args.type.intern : :pdf
    unless Latexmk::COMMAND_TO_PRODUCE_FILE.include?(type)
      raise "Invalid option to produce file: #{type}."
    end
    if commit = args.commit
      path = snapshot_of_commit(type, commit)
    else
      path = snapshot_of_current(type)
    end
    if path
      $stdout.puts "Save to #{path}"
    else
      $stdout.puts "We can not create a file."
    end
  end

  desc "Create source of particular commit."
  task :source, [:commit] do |t, args|
    if commit = args.commit
      if date = commit_date(commit)
        if source_directory = extract_source(commit)
          $stdout.puts "Save to #{source_directory}"
        else
          $stdout.puts "We can not create directory of source files."
        end
      else
        $stderr.puts "The commit '#{commit}' does not exist."
      end
    else
      $stderr.puts "Please set commit."
    end
  end
end