Class: Detroit::VClog

Inherits:
Tool
  • Object
show all
Defined in:
lib/detroit-vclog.rb

Overview

VClog service generates changelogs from SCM commit messages.

TODO: Support multiple formats in one pass.

Constant Summary collapse

VALID_FORMATS =
/^(html|yaml|json|xml|rdoc|md|markdown|gnu|txt|atom|rss|ansi)$/
VALID_TYPES =
/^(log|rel|history|changelog)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Show revision/reference numbers (true/false)?



49
50
51
# File 'lib/detroit-vclog.rb', line 49

def id
  @id
end

#levelObject

Minimum change level to include.



58
59
60
# File 'lib/detroit-vclog.rb', line 58

def level
  @level
end

#outputObject

Output is either a file name with a clear extension to infer type or a list of such file names, or a hash mapping file name to type.

output: NOTES.rdoc

output:
  - NOTES.rdoc
  - site/notes.html

output:
  NOTES: markdown
  site/notes.html: html

Recognized formats include ‘html`, `xml`, `atom`, `rss`, `json`, `yaml`, `rdoc`, `markdown` and `md`, `ansi`, `gnu` and `txt`.



46
47
48
# File 'lib/detroit-vclog.rb', line 46

def output
  @output
end

#pointObject

Divide messages into change points (true/false)?



61
62
63
# File 'lib/detroit-vclog.rb', line 61

def point
  @point
end

#styleObject

Some formats can reference an optional stylesheet (namely xml and html).



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

def style
  @style
end

#summaryObject

Reduced detail?



64
65
66
# File 'lib/detroit-vclog.rb', line 64

def summary
  @summary
end

#titleObject

Some formats, such as rdoc, use a title field. Defaults to project title.



52
53
54
# File 'lib/detroit-vclog.rb', line 52

def title
  @title
end

#typeObject

Changelog layout type (changelog or history). Default is changelog.



29
30
31
# File 'lib/detroit-vclog.rb', line 29

def type
  @type
end

#versionObject

Current version of project.



26
27
28
# File 'lib/detroit-vclog.rb', line 26

def version
  @version
end

Class Method Details

.man_pageObject



344
345
346
# File 'lib/detroit-vclog.rb', line 344

def self.man_page
  File.dirname(__FILE__)+'/../man/detroit-vclog.5'
end

Instance Method Details

#assemble(station, options = {}) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/detroit-vclog.rb', line 88

def assemble(station, options={})
  case station
  when :document then document
  when :reset    then reset
  when :purge    then purge
  end
end

#assemble?(station, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/detroit-vclog.rb', line 79

def assemble?(station, options={})
  case station
  when :document then true
  when :reset    then true
  when :purge    then true
  end
end

#cleanObject

TODO: anything to remove ?



156
157
# File 'lib/detroit-vclog.rb', line 156

def clean
end

#current?Boolean

TODO: Check the output files and see if they are older than the current change log.

Returns:

  • (Boolean)

    whether output is up-to-date



103
104
105
106
107
108
109
110
# File 'lib/detroit-vclog.rb', line 103

def current?
  false
  #output_mapping.each do |file, format|
  #  return false if outofdate?(file, *dnote_session.files)
  #else
  #  "VCLogs are current."
  #end
end

#documentObject

Generate the log.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/detroit-vclog.rb', line 113

def document
  output_mapping.each do |file, format, type|
    next unless verify_format(format, file)
    #file = File.join(output, fname)
    trace "vclog --#{type} -f #{format} >> #{file}"
    if dryrun?
      false # file hasn't changed
    else
      changed = save(file, format, type)
      if changed
        report "Updated " + relative_from_root(file)
      else
        report "Current " + relative_from_root(file)
      end
      changed
    end
  end
end

#purgeObject

Remove output directory output directory.



160
161
162
163
164
165
166
167
# File 'lib/detroit-vclog.rb', line 160

def purge
  output_mapping.each do |file, format, type|
    if File.exist?(file)
      rm(file)
      report "Removed #{file}"
    end
  end
end

#render(format, doctype) ⇒ Object

Convert log to desired format.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/detroit-vclog.rb', line 175

def render(format, doctype)
  doctype = type if doctype.nil?
  doctype = 'history'   if doctype == 'rel'
  doctype = 'changelog' if doctype == 'log'

  options = {
    :type       => doctype,
    :format     => format,
    :stylesheet => style,
    :level      => level,
    :point      => point,
    :is         => id,
    :version    => version,
    :title      => title,
    :summary    => summary
  }

  repo.report(options)
end

#repoObject

Access to version control system.



170
171
172
# File 'lib/detroit-vclog.rb', line 170

def repo
  @repo ||= VCLog::Repo.new(project.root.to_s)
end

#resetObject

Mark the output directory as out of date.



146
147
148
149
150
151
152
153
# File 'lib/detroit-vclog.rb', line 146

def reset
  output_mapping.each do |file, format, type|
    if File.exist?(file)
      utime(0,0,file)
      report "Reset #{file}."
    end
  end
end

#save(file, format, type) ⇒ Object

Save changelog/history to output file.



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/detroit-vclog.rb', line 133

def save(file, format, type)
  text = render(format, type)
  if File.exist?(file)
    return false if File.read(file) == text
  else
    dir = File.dirname(file)
    mkdir_p(dir) unless File.exist?(dir)
  end
  File.open(file, 'w'){ |f| f << text }
  return true
end