Class: GitStats::StatsView::View

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

Instance Method Summary collapse

Constructor Details

#initialize(view_data, out_path) ⇒ View

Returns a new instance of View.


5
6
7
8
# File 'lib/git_stats/stats_view/view.rb', line 5

def initialize(view_data, out_path)
  @view_data, @out_path = view_data, out_path
  @layout = Tilt.new("../../../../templates/layout.haml".absolute_path)
end

Instance Method Details

#all_templates(root = '') ⇒ Object


37
38
39
40
41
42
43
# File 'lib/git_stats/stats_view/view.rb', line 37

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

#render_allObject


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/git_stats/stats_view/view.rb', line 10

def render_all
  prepare_static_content
  prepare_assets

  all_templates.reject {|t| t =~ /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


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/git_stats/stats_view/view.rb', line 22

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