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.



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

def initialize(repo, options)
  @repo    = repo
  @options = case options 
             when Hash
               OpenStruct.new(options)
             else
               options
             end

  @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.



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

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.



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

def email
  options.email || repo.email
end

#h(input) ⇒ Object (private)

HTML escape.



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

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



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

def homepage
  options.homepage
end

Print report.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/vclog/report.rb', line 116

def print
  options.type   ||= 'changelog'
  options.format ||= 'ansi'

  require_formatter(options.format)

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

  tmp = File.read(tmp_file)

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

#r(input) ⇒ Object (private)

Convert from RDoc to HTML.



168
169
170
# File 'lib/vclog/report.rb', line 168

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

#rdocRDoc::Markup::ToHtml (private)

RDoc converter.



177
178
179
180
181
182
183
# File 'lib/vclog/report.rb', line 177

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.



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

def releases
  repo.releases(changelog.changes)
end

#repositoryObject

Repo repository URL.



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

def repository
  repo.repository
end

#require_formatter(format) ⇒ Object (private)

Depending on the format special libraries may by required.



142
143
144
145
146
147
148
149
# File 'lib/vclog/report.rb', line 142

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

#titleObject

Report title.



100
101
102
103
104
105
106
107
108
# File 'lib/vclog/report.rb', line 100

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

#urlObject

TODO:

Ensure this is being provided.

Repository URL.



86
87
88
# File 'lib/vclog/report.rb', line 86

def url
  options.url || repo.repository
end

#userObject

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



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

def user
  options.user || repo.user
end