Class: NetLinx::Rake::ERB::GenerateERB

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/netlinx/rake/erb/generate_erb.rb

Overview

Generate Netlinx source code files from the erb template files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :generate_erb) {|_self| ... } ⇒ GenerateERB

Returns a new instance of GenerateERB.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/netlinx/rake/erb/generate_erb.rb', line 14

def initialize name = :generate_erb
  @name = name
  yield self if block_given?
  
  desc "Generate Netlinx source code files from the erb template files."
  
  task(name) do
    require 'netlinx-erb'
    
    puts "Generating NetLinx files from ERB..."
    puts "------------------------------------"
    
    templates = Dir['include/**/*.erb']
    
    templates.each do |template|
      file_name = template.gsub /\.erb$/, ''
      puts "   #{file_name}"
      
      $AUTOGEN_HEADER = <<-HEADER
(***********************************************************)
(*                         WARNING                         *)
(***********************************************************}
    This file was generated from the following template
    and should NOT be edited directly: 
    
      #{template}
    
    See the documentation at `doc/index.html` for
    information about maintaining this project.
    
    Generated with netlinx-erb:
      https://github.com/amclain/netlinx-erb
{***********************************************************)

  HEADER
      
      File.open file_name, 'w+' do |file|
          file.write NetLinx::ERB.execute(template)
      end
    end
    
    puts "\nDone."
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/netlinx/rake/erb/generate_erb.rb', line 12

def name
  @name
end