Permalink
Browse files

Starting to add page functionality

  • Loading branch information...
1 parent d9da9a0 commit 608e1f778a7c7754dcfc6c02da2935f7822daaf2 @practicingruby practicingruby committed May 8, 2012
Showing with 59 additions and 37 deletions.
  1. +6 −0 lib/jackal/page.rb
  2. +2 −2 lib/jackal/post.rb
  3. +2 −0 test/suite.rb
  4. +7 −35 test/units/page_test.rb
  5. +42 −0 test/units/post_test.rb
View
@@ -4,6 +4,12 @@ def initialize(source_file)
@source_file = source_file
end
+ def filename
+ File.basename(source_file)
+ end
+
+ private
+
attr_reader :source_file
end
end
View
@@ -6,8 +6,8 @@
module Jackal
class Post
- FILE_PATTERN = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})-
- (?<basename>.*).markdown/x
+ FILE_PATTERN = /\A(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})-
+ (?<basename>.*).markdown\z/x
MARKDOWN_CONVERTER = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
View
@@ -0,0 +1,2 @@
+require_relative "units/page_test"
+require_relative "units/post_test"
View
@@ -1,42 +1,14 @@
require_relative "../helper"
-require_relative "../../lib/jackal/post"
+require_relative "../../lib/jackal/page"
-require "ostruct"
-require "tempfile"
-describe Jackal::Post do
- let(:post) do
- page = OpenStruct.new
- page.filename = "2012-05-07-first-post.markdown"
- page.metadata = { :category => "essays" }
- page.contents = "Hello *world*"
-
- Jackal::Post.new(page)
- end
-
- it "must generate dirname" do
- post.dirname.must_equal("essays/2012/05/07")
- end
-
- it "must generate filename" do
- post.filename.must_equal("first-post.html")
+describe Jackal::Page do
+ let(:page) do
+ posts_dir = "#{File.dirname(__FILE__)}/../fixtures/sample_app/_posts"
+ Jackal::Page.new("#{posts_dir}/2012-05-07-first-post.markdown")
end
- it "must generate path" do
- post.path.must_equal("essays/2012/05/07/first-post.html")
- end
-
- it "must render contents to HTML" do
- post.contents.must_equal("<p>Hello <em>world</em></p>\n")
- end
-
- it "must be able to save contents to file" do
- Dir.mktmpdir do |dir|
- post.save(dir)
-
- Dir.chdir("#{dir}/#{post.dirname}") do
- File.read(post.filename).must_equal(post.contents)
- end
- end
+ it "must extract the base filename" do
+ page.filename.must_equal("2012-05-07-first-post.markdown")
end
end
View
@@ -0,0 +1,42 @@
+require_relative "../helper"
+require_relative "../../lib/jackal/post"
+
+require "ostruct"
+require "tempfile"
+
+describe Jackal::Post do
+ let(:post) do
+ page = OpenStruct.new
+ page.filename = "2012-05-07-first-post.markdown"
+ page.metadata = { :category => "essays" }
+ page.contents = "Hello *world*"
+
+ Jackal::Post.new(page)
+ end
+
+ it "must generate dirname" do
+ 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("essays/2012/05/07/first-post.html")
+ end
+
+ it "must render contents to HTML" do
+ post.contents.must_equal("<p>Hello <em>world</em></p>\n")
+ end
+
+ it "must be able to save contents to file" do
+ Dir.mktmpdir do |base_dir|
+ post.save(base_dir)
+
+ Dir.chdir("#{base_dir}/#{post.dirname}") do
+ File.read(post.filename).must_equal(post.contents)
+ end
+ end
+ end
+end

0 comments on commit 608e1f7

Please sign in to comment.