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.



7
8
9
10
11
# File 'lib/microstation/template_runner.rb', line 7

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#template_hashObject (readonly)

Returns the value of attribute template_hash.



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

def template_hash
  @template_hash
end

Instance Method Details

#load(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/microstation/template_runner.rb', line 13

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

#localsObject



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

def locals
  template_hash[:locals]
end

#nameObject



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

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

#output_dirObject



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

def output_dir
  template_hash[:output_dir]
end

#run(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/microstation/template_runner.rb', line 49

def run(options = {})
  begin
  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
end

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



44
45
46
47
# File 'lib/microstation/template_runner.rb', line 44

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

#tagsetsObject



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

def tagsets
  template_hash[:tagsets]
end

#templateObject



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

def template
  template_hash[:template]
end