Class: GitStats::StatsView::View

Inherits:
Object
  • Object
show all
Includes:
Inspector
Defined in:
lib/git_stats/stats_view/view.rb

Instance Method Summary collapse

Methods included from Inspector

#inspect, #pretty_print, #to_s

Constructor Details

#initialize(view_data, out_path) ⇒ View

Returns a new instance of View.



10
11
12
13
14
# File 'lib/git_stats/stats_view/view.rb', line 10

def initialize(view_data, out_path)
  @view_data = view_data
  @out_path = File.expand_path(out_path)
  @layout = Tilt.new(GitStats.root.join('templates/layout.haml'))
end

Instance Method Details

#all_templates(root = '') ⇒ Object



44
45
46
47
48
49
# File 'lib/git_stats/stats_view/view.rb', line 44

def all_templates(root = '')
  (Dir[GitStats.root.join("templates/#{root}**/[^_]*.haml")].sort.map do |f|
    path = Pathname.new(f)
    path.relative_path_from(GitStats.root.join('templates')).sub_ext('').to_s
  end - %w(layout))
end

#render_allObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/git_stats/stats_view/view.rb', line 16

def render_all
  prepare_static_content
  prepare_assets

  all_templates.reject { |t| t.include?('author_details') }.each do |template|
    output = Template.new(template, @layout).render(@view_data, author: @view_data.repo, links: links)
    write(output, "#{@out_path}/#{template}.html")
  end

  render_authors
end

#render_authorsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/git_stats/stats_view/view.rb', line 28

def render_authors
  done = []
  @view_data.repo.authors.sort_by { |a| -a.commits.size }.each do |author|
    next if done.include? author.dirname

    done << author.dirname
    (all_templates('activity/') + all_templates('author_details')).each do |template|
      output = Template.new(template, @layout).render(@view_data,
                                                      author: author,
                                                      links: links,
                                                      active_page: "authors/#{author.dirname}/#{template}")
      write(output, "#{@out_path}/authors/#{author.dirname}/#{template}.html")
    end
  end
end