Class: VCLog::Report
- Inherits:
-
Object
- Object
- VCLog::Report
- 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
-
#options ⇒ Object
readonly
OpenStruct of report options.
-
#repo ⇒ Object
readonly
Instance of VCLog::Repo.
Instance Method Summary collapse
-
#changelog ⇒ Object
Returns a Changelog object.
-
#email ⇒ Object
Email address as given on the command line or from the repo.
-
#format ⇒ Object
Report format.
-
#h(input) ⇒ Object
private
HTML escape.
-
#homepage ⇒ Object
TODO.
-
#initialize(repo, options) ⇒ Report
constructor
Setup new Reporter instance.
-
#print ⇒ Object
Print report.
-
#r(input) ⇒ Object
private
Convert from RDoc to HTML.
-
#rdoc ⇒ RDoc::Markup::ToHtml
private
RDoc converter.
-
#releases ⇒ Object
Compute and return set of releases for
changelog
changes. -
#repository ⇒ Object
Repo repository URL.
-
#require_formatter(format) ⇒ Object
private
Depending on the format special libraries may by required.
-
#title ⇒ Object
Report title.
-
#type ⇒ Object
Report type.
-
#url ⇒ Object
Repository URL.
-
#user ⇒ Object
User as given by the command line or from the repo.
Constructor Details
#initialize(repo, options) ⇒ Report
Setup new Reporter instance.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vclog/report.rb', line 33 def initialize(repo, ) @repo = repo [:type] ||= 'changelog' [:format] ||= 'ansi' @options = OpenStruct.new() @options.level ||= 0 end |
Instance Attribute Details
#options ⇒ Object (readonly)
OpenStruct of report options.
25 26 27 |
# File 'lib/vclog/report.rb', line 25 def @options end |
#repo ⇒ Object (readonly)
Instance of VCLog::Repo.
20 21 22 |
# File 'lib/vclog/report.rb', line 20 def repo @repo end |
Instance Method Details
#changelog ⇒ Object
Returns a Changelog object.
47 48 49 50 |
# File 'lib/vclog/report.rb', line 47 def changelog changes = .point ? repo.changes : repo.change_points ChangeLog.new(changes).above(.level) end |
#email ⇒ Object
Email address as given on the command line or from the repo.
83 84 85 |
# File 'lib/vclog/report.rb', line 83 def email .email || repo.email end |
#format ⇒ Object
Report format.
69 70 71 |
# File 'lib/vclog/report.rb', line 69 def format .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!("<", "<") result.gsub!(">", ">") result.gsub!("'", "'") #result.gsub!("@", "&at;") result.gsub!("\"", """) return result end |
#homepage ⇒ Object
TODO
104 105 106 |
# File 'lib/vclog/report.rb', line 104 def homepage .homepage end |
#print ⇒ Object
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 |
#rdoc ⇒ RDoc::Markup::ToHtml (private)
RDoc 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 |
#releases ⇒ Object
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 |
#repository ⇒ Object
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 |
#title ⇒ Object
Report title.
113 114 115 116 117 118 119 120 121 |
# File 'lib/vclog/report.rb', line 113 def title return .title if .title case type when :history "RELEASE HISTORY" else "CHANGELOG" end end |
#type ⇒ Object
Report type.
62 63 64 |
# File 'lib/vclog/report.rb', line 62 def type .type end |
#url ⇒ Object
Ensure this is being provided.
Repository URL.
99 100 101 |
# File 'lib/vclog/report.rb', line 99 def url .url || repo.repository end |
#user ⇒ Object
User as given by the command line or from the repo.
76 77 78 |
# File 'lib/vclog/report.rb', line 76 def user .user || repo.user end |