Class: VCLog::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/vclog/report.rb

Overview

The Report class acts a controller for outputing change log / release history.

Constant Summary collapse

DIR =

Directory of this file, so as to locate templates.

File.dirname(__FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, options) ⇒ Report

Setup new Reporter instance.

Parameters:

  • repo (Repo)

    An instance of VCLog::Repo.



33
34
35
36
37
38
39
40
41
42
# File 'lib/vclog/report.rb', line 33

def initialize(repo, options)
  @repo    = repo

  options[:type]   ||= 'changelog'
  options[:format] ||= 'ansi'

  @options = OpenStruct.new(options)

  @options.level ||= 0
end

Instance Attribute Details

#optionsObject (readonly)

OpenStruct of report options.



25
26
27
# File 'lib/vclog/report.rb', line 25

def options
  @options
end

#repoObject (readonly)

Instance of VCLog::Repo.



20
21
22
# File 'lib/vclog/report.rb', line 20

def repo
  @repo
end

Instance Method Details

#changelogObject

Returns a Changelog object.



47
48
49
50
# File 'lib/vclog/report.rb', line 47

def changelog
  changes = options.point ? repo.changes : repo.change_points
  ChangeLog.new(changes).above(options.level)
end

#emailObject

Email address as given on the command line or from the repo.



83
84
85
# File 'lib/vclog/report.rb', line 83

def email
  options.email || repo.email
end

#formatObject

Report format.



69
70
71
# File 'lib/vclog/report.rb', line 69

def format
  options.format
end

#h(input) ⇒ Object (private)

HTML escape.



167
168
169
170
171
172
173
174
175
176
# File 'lib/vclog/report.rb', line 167

def h(input)
   result = input.to_s.dup
   result.gsub!("&", "&")
   result.gsub!("<", "&lt;")
   result.gsub!(">", "&gt;")
   result.gsub!("'", "&apos;")
   #result.gsub!("@", "&at;")
   result.gsub!("\"", "&quot;")
   return result
end

#homepageObject

TODO



104
105
106
# File 'lib/vclog/report.rb', line 104

def homepage
  options.homepage
end

Print report.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vclog/report.rb', line 129

def print
  require_formatter(format)

  tmpl_glob = File.join(DIR, 'templates', "#{type}.#{format}.{erb,rb}")
  tmpl_file = Dir[tmpl_glob].first

  raise "could not find template -- #{tmp_glob}" unless tmpl_file

  tmpl = File.read(tmpl_file)

  case File.extname(tmpl_file)
  when '.rb'
    eval(tmpl, binding, tmpl_file)
  when '.erb'
    erb = ERB.new(tmpl, nil, '<>')
    erb.result(binding)
  else
    raise "unrecognized template type -- #{tmpl_file}"
  end
end

#r(input) ⇒ Object (private)

Convert from RDoc to HTML.



181
182
183
# File 'lib/vclog/report.rb', line 181

def r(input)
  rdoc.convert(input)
end

#rdocRDoc::Markup::ToHtml (private)

RDoc converter.

Returns:

  • (RDoc::Markup::ToHtml)

    rdoc markup HTML converter.



190
191
192
193
194
195
196
# File 'lib/vclog/report.rb', line 190

def rdoc
  @_rdoc ||= (
    gem 'rdoc' rescue nil  # to ensure latest version
    require 'rdoc'
    RDoc::Markup::ToHtml.new
  )
end

#releasesObject

Compute and return set of releases for changelog changes.



55
56
57
# File 'lib/vclog/report.rb', line 55

def releases
  repo.releases(changelog.changes)
end

#repositoryObject

Repo repository URL.



90
91
92
# File 'lib/vclog/report.rb', line 90

def repository
  repo.repository
end

#require_formatter(format) ⇒ Object (private)

Depending on the format special libraries may by required.



155
156
157
158
159
160
161
162
# File 'lib/vclog/report.rb', line 155

def require_formatter(format)
  case format.to_s
  when 'yaml'
    require 'yaml'
  when 'json'
    require 'json'
  end
end

#titleObject

Report title.



113
114
115
116
117
118
119
120
121
# File 'lib/vclog/report.rb', line 113

def title
  return options.title if options.title
  case type
  when :history
    "RELEASE HISTORY"
  else
    "CHANGELOG"
  end
end

#typeObject

Report type.



62
63
64
# File 'lib/vclog/report.rb', line 62

def type
  options.type
end

#urlObject

TODO:

Ensure this is being provided.

Repository URL.



99
100
101
# File 'lib/vclog/report.rb', line 99

def url
  options.url || repo.repository
end

#userObject

User as given by the command line or from the repo.



76
77
78
# File 'lib/vclog/report.rb', line 76

def user
  options.user || repo.user
end