Class: Texas::Build::Base

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(_options) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/texas/build/base.rb', line 13

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 { "Starting #{self.class}" }
  verbose { "[i] work_dir: #{options.work_dir}".dark }
  verbose { "[i] contents_dir: #{@contents_dir}".dark }
  verbose { "[i] contents_template: #{@contents_template}".dark }
  verbose { "[i] build_path: #{@build_path}".dark }
end

Instance Attribute Details

#contents_dirObject (readonly)

Returns the value of attribute contents_dir.



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

def contents_dir
  @contents_dir
end

#contents_templateObject (readonly)

Returns the value of attribute contents_template.



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

def contents_template
  @contents_template
end

#current_templateObject

Returns the value of attribute current_template.



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

def current_template
  @current_template
end

#master_fileObject (readonly)

Returns the value of attribute master_file.



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

def master_file
  @master_file
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/texas/build/base.rb', line 9

def options
  @options
end

#ran_templatesObject (readonly)

Returns the value of attribute ran_templates.



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

def ran_templates
  @ran_templates
end

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/texas/build/base.rb', line 9

def root
  @root
end

Class Method Details

.initialize_tasksObject



97
98
99
100
101
102
# File 'lib/texas/build/base.rb', line 97

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

.run(options) ⇒ Object



84
85
86
87
88
# File 'lib/texas/build/base.rb', line 84

def run(options)
  instance = self.new(options)
  instance.run
  instance
end

.tasks(key) ⇒ Object



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

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



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

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

#configObject



51
52
53
54
55
56
# File 'lib/texas/build/base.rb', line 51

def config
  @config ||= begin
    filename = File.join(root, CONFIG_FILE)
    File.exist?(filename) ? YAML.load_file(filename) : {}
  end
end

#dest_fileObject



58
59
60
# File 'lib/texas/build/base.rb', line 58

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

#document_structObject



41
42
43
44
45
46
47
48
49
# File 'lib/texas/build/base.rb', line 41

def document_struct
  @document_struct ||= begin
    hash = config["document"] || {}
    if options.merge_config
      hash.merge! config[options.merge_config]
    end
    OpenStruct.new(hash)
  end
end

#runObject



71
72
73
# File 'lib/texas/build/base.rb', line 71

def run
  run_build_tasks before_tasks, basic_tasks, after_tasks
end

#run_build_task(klass) ⇒ Object



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

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

#run_build_tasks(*tasks) ⇒ Object



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

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

#storeObject



31
32
33
# File 'lib/texas/build/base.rb', line 31

def store
  @store ||= OpenStruct.new
end