Permalink
Browse files

Use openstruct as a stub for a future Page object

  • Loading branch information...
1 parent 9228c87 commit ea75ab797cc120b4a7ec511ecd0322d689ba604c @practicingruby practicingruby committed May 7, 2012
Showing with 14 additions and 7 deletions.
  1. +6 −4 lib/jackal/post.rb
  2. +8 −3 test/units/page_test.rb
View
@@ -6,15 +6,17 @@ class Post
(?<basename>.*).markdown/x
def initialize(page)
- @data = page.source_file.match(FILE_PATTERN)
+ @file_info = page.source_file.match(FILE_PATTERN)
+ @metadata = page.metadata
end
def dirname
- "#{data[:year]}/#{data[:month]}/#{data[:day]}"
+ [ metadata[:category],
+ file_info[:year], file_info[:month], file_info[:day] ].join("/")
end
def filename
- "#{data[:basename]}.html"
+ "#{file_info[:basename]}.html"
end
def path
@@ -23,6 +25,6 @@ def path
private
- attr_reader :data
+ attr_reader :file_info, :metadata
end
end
@@ -1,21 +1,26 @@
require_relative "../helper"
require_relative "../../lib/jackal/post"
+require "ostruct"
+
describe Jackal::Post do
let(:post) do
- page = Jackal::Page.new("2012-05-07-first-post.markdown")
+ page = OpenStruct.new
+ page.source_file = "2012-05-07-first-post.markdown"
+ page.metadata = { :category => "essays" }
+
Jackal::Post.new(page)
end
it "must generate dirname" do
- post.dirname.must_equal("2012/05/07")
+ post.dirname.must_equal("essays/2012/05/07")
end
it "must generate filename" do
post.filename.must_equal("first-post.html")
end
it "must generate path" do
- post.path.must_equal("2012/05/07/first-post.html")
+ post.path.must_equal("essays/2012/05/07/first-post.html")
end
end

0 comments on commit ea75ab7

Please sign in to comment.