Class: Gakubuchi::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(templates) ⇒ Task



7
8
9
# File 'lib/gakubuchi/task.rb', line 7

def initialize(templates)
  @templates = Array(templates)
end

Instance Attribute Details

#templatesObject (readonly)

Returns the value of attribute templates.



5
6
7
# File 'lib/gakubuchi/task.rb', line 5

def templates
  @templates
end

Instance Method Details

#execute!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gakubuchi/task.rb', line 11

def execute!
  templates.each do |template|
    precompiled_pathnames = template.precompiled_pathnames

    src = precompiled_pathnames
      .select  { |pathname| pathname.extname == '.html' }
      .sort_by { |pathname| pathname.mtime }
      .last

    next if src.nil?
    dest = template.destination_pathname

    FileUtils.copy_p(src, dest)
    FileUtils.remove(precompiled_pathnames) if remove_precompiled_templates?
  end
end

#remove_precompiled_templates?Boolean



28
29
30
# File 'lib/gakubuchi/task.rb', line 28

def remove_precompiled_templates?
  !!Gakubuchi.configuration.remove_precompiled_templates
end