This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Adding some footer magic in

  • Loading branch information...
1 parent 535f57e commit 359b52a3bc80e1e33e3b0b23e1fce2f7fe19014c @qrush qrush committed Jul 10, 2009
Showing with 13 additions and 8 deletions.
  1. +6 −3 lib/report_card/index.rb
  2. +1 −1 template/index.html.erb
  3. +6 −4 test/index_test.rb
View
@@ -1,16 +1,19 @@
module ReportCard
class Index
+ attr_reader :projects, :footer
+
TEMPLATE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "template", "index.html.erb"))
def self.create(projects, site)
- new(projects.select { |p| p.public }, site)
- new(projects.select { |p| ! p.public }, File.join(site, 'private'))
+ new(projects.select { |p| p.public }, site, "<a href='/private'>TOP SECRET PROJECTS</a>")
+ new(projects.select { |p| ! p.public }, File.join(site, 'private'), "<a href='/'>NORMAL BORING PROJECTS</a>")
end
- def initialize(projects, path)
+ def initialize(projects, path, footer)
return if projects.empty?
@projects = projects
+ @footer = footer
erb = File.read(TEMPLATE_PATH)
html = ERB.new(erb).result(binding)
View
@@ -27,7 +27,7 @@
</ul>
</div>
<div id="footer">
- <a href="/private">TOP SECRET PROJECTS</a>
+ <%= @footer %>
</div>
</body>
</html>
View
@@ -12,8 +12,8 @@ class IndexTest < Test::Unit::TestCase
end
should "split up public and private projects" do
- mock(ReportCard::Index).new([@public_project1, @public_project2], @site)
- mock(ReportCard::Index).new([@private_project], File.join(@site, "private"))
+ mock(ReportCard::Index).new([@public_project1, @public_project2], @site, anything)
+ mock(ReportCard::Index).new([@private_project], File.join(@site, "private"), anything)
ReportCard::Index.create(@projects, @site)
end
@@ -28,14 +28,16 @@ class IndexTest < Test::Unit::TestCase
mock(ERB).new(erb).mock!.result(anything) { html }
mock(File).open(File.join(@site, "index.html"), "w").yields(io)
- ReportCard::Index.new([@private_project], @site)
+ index = ReportCard::Index.new([@private_project], @site, "footer")
+ assert_equal [@private_project], index.projects
+ assert_equal "footer", index.footer
end
should "not write out anything if there's no projects" do
mock(File).read(anything).never
mock(ERB).new(anything).never
mock(File).open(anything, "w").never
- ReportCard::Index.new([], @site)
+ ReportCard::Index.new([], @site, "footer")
end
end
end

0 comments on commit 359b52a

Please sign in to comment.