Class: Microstation::TemplateRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/microstation/template_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ TemplateRunner

Returns a new instance of TemplateRunner.



5
6
7
8
9
# File 'lib/microstation/template_runner.rb', line 5

def initialize(file)
  puts "running #{file}"
  @file = file
  @template_hash = load(file)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/microstation/template_runner.rb', line 3

def file
  @file
end

#template_hashObject (readonly)

Returns the value of attribute template_hash.



3
4
5
# File 'lib/microstation/template_runner.rb', line 3

def template_hash
  @template_hash
end

Instance Method Details

#load(file) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/microstation/template_runner.rb', line 11

def load(file)
  File.open(file) do |f|
    YAML.load(f)
  end
rescue => e
  binding.pry
  puts "Could not parse YAML: #{e.message}"
end

#localsObject



24
25
26
# File 'lib/microstation/template_runner.rb', line 24

def locals
  template_hash[:locals]
end

#nameObject



20
21
22
# File 'lib/microstation/template_runner.rb', line 20

def name
  template_hash[:name] || Pathname(template).basename.ext(".dgn")
end

#output_dirObject



32
33
34
# File 'lib/microstation/template_runner.rb', line 32

def output_dir
  template_hash[:output_dir]
end

#run(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/microstation/template_runner.rb', line 45

def run(options = {})
  the_template = Template.new(template)
  template_options = {output_dir: output_dir,
                      locals: locals,
                      name: name,
                      tagsets: tagsets}
  run_options = template_options.merge(options)
  the_template.render(run_options)
rescue
  binding.pry
end

#run_with_app(app, options = {}) ⇒ Object



40
41
42
43
# File 'lib/microstation/template_runner.rb', line 40

def run_with_app(app, options = {})
  run_options = {app: app}.merge(options)
  run(run_options)
end

#tagsetsObject



28
29
30
# File 'lib/microstation/template_runner.rb', line 28

def tagsets
  template_hash[:tagsets]
end

#templateObject



36
37
38
# File 'lib/microstation/template_runner.rb', line 36

def template
  template_hash[:template]
end