Class: Paperwork::Tasks::Template

Inherits:
Base
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/paperwork/tasks/template.rb

Overview

Task for generating middleman template directory for building

Instance Attribute Summary collapse

Attributes inherited from Base

#dependencies, #name

Instance Method Summary collapse

Methods inherited from Base

#create_tasks, explain, #register, #registered?, #registered_tasks

Constructor Details

#initialize(name, *dependencies) ⇒ Template

Returns a new instance of Template.



17
18
19
20
21
22
23
24
25
# File 'lib/paperwork/tasks/template.rb', line 17

def initialize(name, *dependencies)
    @dir = File.join(Paperwork::Config[:build_root], name.to_s)
    @bundle = File.join(Paperwork::Config[:build_root], ".bundle")
    super(self.dir, File.dirname(self.dir), @bundle, *dependencies)

    BuildDir.new(@bundle)
    BuildDir.new(File.dirname(self.dir))
    @template = File.expand_path("middleman_template", __dir__)
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



13
14
15
# File 'lib/paperwork/tasks/template.rb', line 13

def dir
  @dir
end

#templateObject (readonly)

Returns the value of attribute template.



13
14
15
# File 'lib/paperwork/tasks/template.rb', line 13

def template
  @template
end

Instance Method Details

#tasksObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/paperwork/tasks/template.rb', line 27

def tasks
    directory self.name => self.dependencies do
        cp_r template, self.dir
        Dir.chdir(self.dir) do
            cmd = "bundle install --path=../.bundle/gems --jobs 8 --without test development"
            if defined? Bundler
                Bundler.with_unbundled_env do
                    Process.spawn(cmd, out: :out, in: :in, err: :err)
                end
            else
                Process.spawn(cmd, out: :out, in: :in, err: :err)
            end
            Process.spawn("yarn install", out: :out, in: :in, err: :err)
            Process.waitall
        end
    end
end