Skip to content

Commit

Permalink
give access to articles from all pages, through @articles var
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Feb 4, 2010
1 parent 2c2ca04 commit d0ad213
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/toto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,22 @@ def http code
end

def articles
Dir["#{Paths[:articles]}/*.#{self[:ext]}"]
self.class.articles self[:ext]
end

def self.articles ext
Dir["#{Paths[:articles]}/*.#{ext}"]
end

class Context
include Template

def initialize ctx = {}, config = {}, path = "/"
@config, @ctx, @path = config, ctx, path
@articles = Site.articles(@config[:ext]).reverse.map do |a|
Article.new(File.new(a), @config)
end

ctx.each do |k, v|
meta_def(k) { ctx.instance_of?(Hash) ? v : ctx.send(k) }
end
Expand Down
1 change: 1 addition & 0 deletions test/templates/about.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span id="count"><%= @articles.length %></span>
1 change: 1 addition & 0 deletions test/toto_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
setup { @toto.get('/about') }
asserts("returns a 200") { topic.status }.equals 200
asserts("body is not empty") { not topic.body.empty? }
should("have access to @articles") { topic.body }.includes_html("#count" => /5/)
end

context "GET a single article" do
Expand Down

0 comments on commit d0ad213

Please sign in to comment.