Permalink
Browse files

adding factory

  • Loading branch information...
1 parent bf1e959 commit 7fd7d2aac47c309c7054e684e3cb35e56037d8dd @steveklabnik committed Jan 22, 2012
Showing with 28 additions and 0 deletions.
  1. +9 −0 lib/metadown.rb
  2. +19 −0 spec/metadown_spec.rb
View
@@ -3,4 +3,13 @@
module Metadown
+ Data = Struct.new(:metadata, :output)
+
+ def render(text)
+ renderer = Metadown::Renderer.new
+ markdown = Redcarpet::Markdown.new(renderer)
+ output = markdown.render(text)
+ Data.new(renderer.metadata, output)
+ end
+ module_function :render
end
View
@@ -0,0 +1,19 @@
+$:.unshift("lib")
+require 'metadown'
+
+describe Metadown do
+ it "provides a factory" do
+ text = <<-MARKDOWN
+---
+key: "value"
+---
+hello world
+MARKDOWN
+
+ Metadown.render(text).tap do |data|
+ data.should be_kind_of(Metadown::Data)
+ data.metadata.should eql({"key" => "value"})
+ data.output.should eql("<p>hello world</p>\n")
+ end
+ end
+end

0 comments on commit 7fd7d2a

Please sign in to comment.