Class: GitScribe

Inherits:
Object
  • Object
show all
Defined in:
lib/gitscribe.rb,
lib/gitscribe/options.rb

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

.add_section(target, c) ⇒ Object



45
46
47
# File 'lib/gitscribe.rb', line 45

def add_section(target, c)
  target << GitScribe::Section.new(c.message(), c.parent().diff(c)) if c.parent()
end

.run!(*arguments) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitscribe.rb', line 8

def run!(*arguments)
  options = GitScribe::Options.new(arguments)

  if options[:show_help]
    $stderr.puts options.opts
    return 1
  end

  unless arguments.size == 1
    $stderr.puts options.opts
    return 1
  end
  
  g = Git.open(arguments.first)

  tags = Array.new
  g.tags.sort_by { |x| g.object(x.objectish).date }.each { |t| tags << t.name }

  chapters = Array.new
  if tags.empty?
    chapter = Chapter.new
    g.log.each { |c| add_section(chapter.sections, c) }
    chapters << chapter
  else
    tags.each_index do |i|
      chapter = Chapter.new(tags[i])
      g.log.between(tags[i], tags[i + 1]).each { |c| add_section(chapter.sections, c) } if i + 1 < tags.size
      chapters << chapter if !chapter.sections.empty?
    end
  end

  template = File.read(File.dirname(__FILE__) + "/gitscribe/template.erb")

  f = File.new(options[:output], "w+")
  f.puts(ERB.new(template).result(binding))
end