Class: Texas::Build::Base

Inherits:
Object
  • Object
show all
Includes:
OutputHelper
Defined in:
lib/texas/build/base.rb

Direct Known Subclasses

Dry

Constant Summary collapse

CONFIG_FILE =
".texasrc"
MASTER_TEMPLATE =
"master.tex"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OutputHelper

#trace, #verbose, #warning

Constructor Details

#initialize(_options) ⇒ Base

Returns a new instance of Base.



30
31
32
33
34
35
36
37
# File 'lib/texas/build/base.rb', line 30

def initialize(_options)
  @options = _options
  @root = options.work_dir
  @contents_dir = options.contents_dir
  @contents_template = options.contents_template
  @master_file = File.join(__path__, MASTER_TEMPLATE)
  verbose { verbose_info }
end

Instance Attribute Details

#contents_dirObject (readonly)

Returns the value of attribute contents_dir.



19
20
21
# File 'lib/texas/build/base.rb', line 19

def contents_dir
  @contents_dir
end

#contents_templateObject (readonly)

Returns the name of the template whose contents should be rendered.



22
23
24
# File 'lib/texas/build/base.rb', line 22

def contents_template
  @contents_template
end

#current_templateObject

Returns the name of the template currently rendered.



25
26
27
# File 'lib/texas/build/base.rb', line 25

def current_template
  @current_template
end

#master_fileObject (readonly)

Returns the location of the template that is run.



17
18
19
# File 'lib/texas/build/base.rb', line 17

def master_file
  @master_file
end

#optionsObject (readonly)

Returns the options of this build.



14
15
16
# File 'lib/texas/build/base.rb', line 14

def options
  @options
end

#ran_templatesObject (readonly)

Returns an array of all templates that have been rendered.



28
29
30
# File 'lib/texas/build/base.rb', line 28

def ran_templates
  @ran_templates
end

#rootObject (readonly)

Returns the path of the current Texas project



11
12
13
# File 'lib/texas/build/base.rb', line 11

def root
  @root
end

Class Method Details

.initialize_tasksObject



115
116
117
118
119
120
# File 'lib/texas/build/base.rb', line 115

def initialize_tasks
  @@tasks[self.to_s] = {}
  (@@tasks[self.superclass.to_s] || {}).each do |k, v|
    @@tasks[self.to_s][k] = v.dup
  end
end

.tasks(key) ⇒ Object



108
109
110
111
112
113
# File 'lib/texas/build/base.rb', line 108

def tasks(key)
  @@tasks ||= {}
  initialize_tasks if @@tasks[self.to_s].nil?
  @@tasks[self.to_s][key] ||= []
  @@tasks[self.to_s][key]
end

Instance Method Details

#__path__Object

Returns the full path of the directory where the build is happening.



41
42
43
# File 'lib/texas/build/base.rb', line 41

def __path__
  File.join(root, 'tmp', 'build')
end

#configObject

Returns the Config object.



62
63
64
# File 'lib/texas/build/base.rb', line 62

def config
  @config ||= Config.create ConfigLoader.new(root, CONFIG_FILE).to_hash, options.merge_config
end

#dest_fileObject

Returns the location where the generated PDF file should be after the build.



68
69
70
# File 'lib/texas/build/base.rb', line 68

def dest_file
  @dest_file ||= File.join(root, "bin", "#{Template.basename contents_template}.pdf")
end

#runObject

Executes the build process.



88
89
90
# File 'lib/texas/build/base.rb', line 88

def run
  run_build_tasks before_tasks, basic_tasks, after_tasks
end

#run_build_task(klass) ⇒ Object

Runs the given build task.



80
81
82
83
84
# File 'lib/texas/build/base.rb', line 80

def run_build_task(klass)
  verbose { TraceInfo.new(:build_task, klass, :green) }
  klass = eval("::Texas::Build::Task::#{klass}") if [Symbol, String].include?(klass.class)
  klass.new(self).run
end

#run_build_tasks(*tasks) ⇒ Object

Runs the given build tasks.



74
75
76
# File 'lib/texas/build/base.rb', line 74

def run_build_tasks(*tasks)
  tasks.flatten.each { |t| run_build_task t }
end

#storeObject

Returns an object that can store persistent information throughout the build process.



48
49
50
# File 'lib/texas/build/base.rb', line 48

def store
  @store ||= OpenStruct.new
end

#verbose_infoObject



92
93
94
95
96
97
# File 'lib/texas/build/base.rb', line 92

def verbose_info
  [
    TraceInfo.new("work_dir", options.work_dir, :dark),
    TraceInfo.new("build_path", __path__, :dark),
  ].join("\n")
end