generating sample page

This commit is contained in:
Tomasz Gieniusz 2012-10-08 18:21:42 +02:00
parent f322835ba0
commit ba3eaeae0a
17 changed files with 8964 additions and 1 deletions

View File

@ -18,5 +18,10 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.add_dependency('tilt')
gem.add_dependency('haml')
gem.add_dependency('launchy')
gem.add_development_dependency('pry')
end

5
lib/gitstats/assets.rb Normal file
View File

@ -0,0 +1,5 @@
class GitStats::Assets
def self.prepare(out_path)
FileUtils.cp_r('templates/assets', out_path)
end
end

View File

@ -1,4 +1,5 @@
require "gitstats"
require "launchy"
class GitStats::CLI
@ -10,6 +11,7 @@ class GitStats::CLI
repo_path, out_path = args
validate(repo_path, out_path)
GitStats::Generator.new(repo_path, out_path).generate
Launchy.open("#{out_path}/index.html")
end
end

View File

@ -4,6 +4,10 @@ class GitStats::Generator
end
def generate
puts "generating..."
data = GitStats::GitData.new(@repo_path)
data.gather_all_data
GitStats::Assets.prepare(@out_path)
output = GitStats::Template.new('index').render(data)
File.open("#{@out_path}/index.html", 'w') { |f| f.write output }
end
end

14
lib/gitstats/git_data.rb Normal file
View File

@ -0,0 +1,14 @@
class GitStats::GitData
attr_reader :total_authors
attr_reader :total_commits
def initialize(repo_path)
@repo_path = repo_path
end
def gather_all_data
Dir.chdir(@repo_path) {
@total_authors = %x[git shortlog -s HEAD | wc -l]
}
end
end

13
lib/gitstats/template.rb Normal file
View File

@ -0,0 +1,13 @@
require 'tilt'
class GitStats::Template
def initialize(name)
@name = name
@@layout ||= Tilt.new("templates/layout.haml")
@template = Tilt.new("templates/#{@name}.haml")
end
def render(data)
@@layout.render { @template.render(data) }
end
end

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

2027
templates/assets/bootstrap/js/bootstrap.js vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

2
templates/assets/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

7
templates/index.haml Normal file
View File

@ -0,0 +1,7 @@
%table
%tr
%td= total_authors
%td bbb
%tr
%td cc
%td dd

28
templates/layout.haml Normal file
View File

@ -0,0 +1,28 @@
!!! XML
!!!
%html
%head
%title GitStats
%link{:rel => "stylesheet", :href => "assets/bootstrap/css/bootstrap.min.css", :type => "text/css"}
%link{:rel => "stylesheet", :href => "assets/bootstrap/css/bootstrap-responsive.min.css", :type => "text/css"}
%script{:src => "assets/jquery.min.js", :type => "text/javascript"}
%script{:src => "assets/bootstrap/js/bootstrap.min.js", :type => "text/javascript"}
%body
%div.navbar.navbar-inverse.navbar-fixed-top
%div.navbar-inner
%div.container
%a.btn.btn-navbar{'data-toggle' => "collapse", 'data-target' => ".nav-collapse"}
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand{:href => "#"} Project name
%div.nav-collapse.collapse
%ul.nav
%li.active
%a{:href => "#"} Home
%li
%a{:href => "#"} Home2
%li
%a{:href => "#"} Hom3
%div.container
= yield