pages seperation

This commit is contained in:
Tomasz Gieniusz 2012-10-13 14:01:46 +02:00
parent 32d84e3ddd
commit 2d7a7db33c
7 changed files with 31 additions and 20 deletions

View File

@ -10,7 +10,8 @@ module GitStats
repo = GitData::Repo.new(@repo_path)
view_data = StatsView::ViewData.new(repo)
StatsView::View.render_all(view_data, @out_path)
view = StatsView::View.new(view_data, @out_path)
view.render_all
end
private

View File

@ -7,8 +7,8 @@ module GitStats
@template = Tilt.new("templates/#@name.haml")
end
def render(data)
@layout.render { @template.render(data) }
def render(data, all_templates)
@layout.render(data, :active_page => @name, :all_templates => all_templates) { @template.render(data) }
end
end
end

View File

@ -1,17 +1,29 @@
module GitStats
module StatsView
class View
def self.render_all(data, out_path)
prepare_assets(out_path)
def initialize(view_data, out_path)
@view_data, @out_path = view_data, out_path
end
def render_all
prepare_assets
layout = Tilt.new("templates/layout.haml")
output = Template.new('index', layout).render(data)
File.open("#{out_path}/index.html", 'w') { |f| f.write output }
all_templates.each do |template|
output = Template.new(template, layout).render(@view_data, all_templates)
File.open("#@out_path/#{template}.html", 'w') { |f| f.write output }
end
end
def self.prepare_assets(out_path)
FileUtils.cp_r('templates/assets', out_path)
def all_templates
@all_templates ||= (Dir["templates/*.haml"] - Dir["templates/layout.haml"]).map { |t| File.basename(t, ".haml") }
end
def prepare_assets
FileUtils.cp_r('templates/assets', @out_path)
end
end
end
end

View File

@ -24,7 +24,9 @@ describe GitStats::Generator do
view_data = double('view_data')
GitStats::StatsView::ViewData.should_receive(:new).with(repo).and_return(view_data)
GitStats::StatsView::View.should_receive(:render_all).with(view_data, out_path)
view = double('view')
GitStats::StatsView::View.should_receive(:new).with(view_data, out_path).and_return(view)
view.should_receive(:render_all)
generator.generate
end

1
templates/authors.haml Normal file
View File

@ -0,0 +1 @@
= high_chart("my_id", h)

View File

@ -1,4 +1,2 @@
%p= repo.project_name
%p= repo.project_version
= high_chart("my_id", h)

View File

@ -2,7 +2,7 @@
!!!
%html
%head
%title GitStats
%title= "GitStats - #{repo.project_name}"
%link{:rel => "stylesheet", :href => "assets/bootstrap/css/bootstrap.min.css", :type => "text/css"}
%style
:plain
@ -19,14 +19,11 @@
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.brand{:href => "#"} Project name
%a.brand{:href => "index.html"}= "GitStats - #{repo.project_name}"
%div.nav-collapse.collapse
%ul.nav
%li.active
%a{:href => "#"} Home
%li
%a{:href => "#"} Home2
%li
%a{:href => "#"} Hom3
- all_templates.each do |link|
%li{:class => active_page == link ? "active" : ""}
%a{:href => "#{link}.html"}= link.capitalize
%div.container
= yield