Class: Microstation::TemplateRunner
- Inherits:
-
Object
- Object
- Microstation::TemplateRunner
- Defined in:
- lib/microstation/template_runner.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#template_hash ⇒ Object
readonly
Returns the value of attribute template_hash.
Instance Method Summary collapse
-
#initialize(file) ⇒ TemplateRunner
constructor
A new instance of TemplateRunner.
- #load(file) ⇒ Object
- #locals ⇒ Object
- #name ⇒ Object
- #output_dir ⇒ Object
- #run(options = {}) ⇒ Object
- #run_with_app(app, options = {}) ⇒ Object
- #tagsets ⇒ Object
- #template ⇒ Object
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/microstation/template_runner.rb', line 5 def file @file end |
#template_hash ⇒ Object (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.}" end end |
#locals ⇒ Object
28 29 30 |
# File 'lib/microstation/template_runner.rb', line 28 def locals template_hash[:locals] end |
#name ⇒ Object
24 25 26 |
# File 'lib/microstation/template_runner.rb', line 24 def name template_hash[:name] || Pathname(template).basename.ext('.dgn') end |
#output_dir ⇒ Object
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( = {}) begin the_template = Template.new(template) = { output_dir: output_dir, locals: locals, name: name, tagsets: } = .merge() the_template.render() 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, = {}) = { app: app}.merge() run() end |
#tagsets ⇒ Object
32 33 34 |
# File 'lib/microstation/template_runner.rb', line 32 def template_hash[:tagsets] end |
#template ⇒ Object
40 41 42 |
# File 'lib/microstation/template_runner.rb', line 40 def template template_hash[:template] end |