Class: PivotalDoc::Generators::Base

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

Direct Known Subclasses

CSV, HTML

Constant Summary collapse

TEMPLATE_PATH =
"#{PROJECT_ROOT}/templates"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



6
7
8
9
# File 'lib/pivotal_doc/generators/base.rb', line 6

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

Instance Method Details

#absolute_pathObject



26
27
28
# File 'lib/pivotal_doc/generators/base.rb', line 26

def absolute_path
  File.dirname(__FILE__)
end

#output_extObject



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

def output_ext; '.default' end

#output_fileObject



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

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

#output_pathObject



11
12
13
# File 'lib/pivotal_doc/generators/base.rb', line 11

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

#render_doc(output = '') ⇒ Object



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

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



44
45
46
47
48
# File 'lib/pivotal_doc/generators/base.rb', line 44

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

#template_nameObject



50
51
52
# File 'lib/pivotal_doc/generators/base.rb', line 50

def template_name
  raise 'Not Implemented!'
end