Class: Httpdoc::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/httpdoc/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/httpdoc/generator.rb', line 5

def base_url
  @base_url
end

#input_pathsObject

Returns the value of attribute input_paths.



7
8
9
# File 'lib/httpdoc/generator.rb', line 7

def input_paths
  @input_paths
end

#output_directoryObject

Returns the value of attribute output_directory.



6
7
8
# File 'lib/httpdoc/generator.rb', line 6

def output_directory
  @output_directory
end

#template_nameObject

Returns the value of attribute template_name.



8
9
10
# File 'lib/httpdoc/generator.rb', line 8

def template_name
  @template_name
end

Instance Method Details

#generate!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/httpdoc/generator.rb', line 10

def generate!
  file_names = @input_paths.map { |path|
    path = path.gsub(/\/$/, '')
    if File.directory?(path)
      Dir.glob("#{path}/**/*.rb")
    else
      Dir.glob(path)
    end
  }.flatten
  file_names.each do |file_name|
    parser = RubyCommentParser.new(file_name)
    parser.parse
    if parser.controller
      renderer = Rendering::SingleFileRenderer.new(:base_url => @base_url)
      renderer.template_name = @template_name
      output_filename = File.join(@output_directory, File.basename(file_name).gsub(/\.rb/, ''))
      output_filename << ".html"
      File.open(output_filename, "w") do |file|
        file << renderer.render_controller(parser.controller)
      end
    end
  end      
end