Class: Marv::Project::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/marv/project/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Builder

Initialize project builder



13
14
15
16
17
18
19
20
# File 'lib/marv/project/builder.rb', line 13

def initialize(project)
  @project = project
  @task = project.task
  @config = project.config
  @assets = Marv::Project::Assets.new(self)
  @functions = Marv::Project::Functions.new(self)
  @templates = Marv::Project::Templates.new(self)
end

Instance Attribute Details

#assetsObject

Returns the value of attribute assets.



10
11
12
# File 'lib/marv/project/builder.rb', line 10

def assets
  @assets
end

#functionsObject

Returns the value of attribute functions.



10
11
12
# File 'lib/marv/project/builder.rb', line 10

def functions
  @functions
end

#projectObject

Returns the value of attribute project.



10
11
12
# File 'lib/marv/project/builder.rb', line 10

def project
  @project
end

#taskObject

Returns the value of attribute task.



10
11
12
# File 'lib/marv/project/builder.rb', line 10

def task
  @task
end

#templatesObject

Returns the value of attribute templates.



10
11
12
# File 'lib/marv/project/builder.rb', line 10

def templates
  @templates
end

Instance Method Details

#build_projectObject

Start builder



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/marv/project/builder.rb', line 23

def build_project
  clean_directory

  @functions.copy_folders
  @templates.copy_templates

  @functions.copy_functions
  @functions.copy_includes

  @assets.copy_images
  @assets.build_assets
end

#build_to(dir) ⇒ Object

Build project to a directory



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/marv/project/builder.rb', line 37

def build_to(dir)
  @task.say_warning "This will build project #{@project.project_id} in directory #{dir}."

  begin
    build_project
    # Remove build directory
    @task.shell.mute do
      @task.remove_dir ::File.expand_path(dir)
    end
    # Copy files from .watch/build directory
    @task.directory @project.build_path, ::File.expand_path(dir)
  rescue Exception => e
    @task.say_error "There was an error while building the project:", e.message, false
    abort
  end
end

#clean_directoryObject

Clean build directory



55
56
57
58
59
# File 'lib/marv/project/builder.rb', line 55

def clean_directory
  @task.shell.mute do
    @task.remove_dir @project.build_path
  end
end