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.
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/microstation/template_runner.rb', line 3 def file @file end |
#template_hash ⇒ Object (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.}" end |
#locals ⇒ Object
24 25 26 |
# File 'lib/microstation/template_runner.rb', line 24 def locals template_hash[:locals] end |
#name ⇒ Object
20 21 22 |
# File 'lib/microstation/template_runner.rb', line 20 def name template_hash[:name] || Pathname(template).basename.ext(".dgn") end |
#output_dir ⇒ Object
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( = {}) the_template = Template.new(template) = {output_dir: output_dir, locals: locals, name: name, tagsets: } = .merge() the_template.render() 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, = {}) = {app: app}.merge() run() end |
#tagsets ⇒ Object
28 29 30 |
# File 'lib/microstation/template_runner.rb', line 28 def template_hash[:tagsets] end |
#template ⇒ Object
36 37 38 |
# File 'lib/microstation/template_runner.rb', line 36 def template template_hash[:template] end |