Class: PivotalDoc::Generators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal_doc/generators/base.rb

Direct Known Subclasses

HTML, Text

Instance Method Summary collapse

Constructor Details

#initialize(release, options = {}) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/pivotal_doc/generators/base.rb', line 4

def initialize(release, options={})
  @release= release
  @options= options
end

Instance Method Details

#absolute_pathObject



24
25
26
# File 'lib/pivotal_doc/generators/base.rb', line 24

def absolute_path
  File.dirname(__FILE__)
end

#output_extObject



22
# File 'lib/pivotal_doc/generators/base.rb', line 22

def output_ext; '.default' end

#output_fileObject



13
14
15
16
17
18
19
20
# File 'lib/pivotal_doc/generators/base.rb', line 13

def output_file
  name= @options['output_file']
  unless name
    name=@release.name || self.object_id.to_s
    name.gsub!(/\//, '') and name.gsub!(/\s/,'')
  end
  File.join(output_path, (name + output_ext))  
end

#output_pathObject



9
10
11
# File 'lib/pivotal_doc/generators/base.rb', line 9

def output_path
  @options['output_path'] || absolute_path
end

#render_doc(output = '') ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pivotal_doc/generators/base.rb', line 28

def render_doc(output='')
  begin
    # No permissions throw exception about output_path
    FileUtils.mkdir_p(output_path)
    f= File.open(self.output_file, 'w+')
    f.write(output)
  rescue Exception=>e
    $stdout.print(e.message)
    $stdout.flush
  ensure
    f.close if f
  end
end

#templateObject



42
43
44
45
46
# File 'lib/pivotal_doc/generators/base.rb', line 42

def template
  path= File.join(PROJECT_ROOT, 'templates', template_name)
  raise TemplateNonExistent.new(template_name) unless File.exists?(path)
  @template ||= File.read(path)
end

#template_nameObject



48
49
50
# File 'lib/pivotal_doc/generators/base.rb', line 48

def template_name
  raise 'Not Implemented!'
end