Skip to content
Browse files

Merge branch 'master' of github.com:shoes/shoesrb.com

  • Loading branch information...
2 parents 74a83b1 + f7b2941 commit ccbdf0a185003330f36e1daf053557f6763a603b @mpapis mpapis committed Mar 16, 2012
Showing with 69 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +18 −0 Rakefile
  4. +2 −0 config.ru
  5. +9 −0 posts/hello-world.md
  6. +30 −0 resources/blog_resource.rb
  7. +5 −0 views/post.html.haml
View
1 Gemfile
@@ -7,3 +7,4 @@ gem 'webmachine', :git => "https://github.com/seancribbs/webmachine-ruby.git"
gem 'rack'
gem 'haml'
+gem 'metadown'
View
4 Gemfile.lock
@@ -10,12 +10,16 @@ GEM
specs:
haml (3.1.4)
i18n (0.6.0)
+ metadown (1.0.1)
+ redcarpet
rack (1.4.1)
+ redcarpet (2.1.0)
PLATFORMS
ruby
DEPENDENCIES
haml
+ metadown
rack
webmachine!
View
18 Rakefile
@@ -0,0 +1,18 @@
+desc "Make a new post"
+task :"new_post", :title do |t, args|
+ args.with_defaults(:title => 'new-post')
+ title = args.title
+ filename = "posts/#{title.downcase.gsub(/\W/, "-")}.md"
+
+ puts "Creating new posts: #{filename}"
+ open(filename, 'w') do |post|
+ post.puts "---"
+ post.puts "title: \"#{title.gsub(/&/,'&')}\""
+ post.puts "slug: \"#{title.gsub(/\W/, '-').downcase}\""
+ post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
+ post.puts "---"
+ post.puts ""
+ post.puts "CONTENT HERE **IN MARKDOWN**"
+ end
+end
+
View
2 config.ru
@@ -8,6 +8,8 @@ Dir["resources/*"].each {|f| require "./#{f}" }
Shoes = Webmachine::Application.new do |app|
app.routes do
add [], ShoesHomepage
+ add ["blog"], BlogResource
+ add ["blog", :slug], BlogResource
add ['*'], StaticResource, :root => "public"
end
app.configure do |config|
View
9 posts/hello-world.md
@@ -0,0 +1,9 @@
+---
+title: "Hello World"
+slug: "hello-world"
+date: 2012-03-15 21:47
+---
+
+Hello, world!
+
+**MARKDOWN**!!!!
View
30 resources/blog_resource.rb
@@ -0,0 +1,30 @@
+require 'metadown'
+
+$posts = Dir["posts/*"].inject({}) do |hsh, file|
+ data = Metadown.render(File.read(file))
+
+ hsh[data.metadata["slug"]] = data
+
+ hsh
+end
+
+class BlogResource < Webmachine::Resource
+ def resource_exists?
+ return true unless request.path_info[:slug] #index
+
+ @post = $posts[request.path_info[:slug]] if request.path_info[:slug]
+ !@post.nil?
+ end
+
+ def to_html
+ return "INDEX" unless @post
+
+ Haml::Engine.new(File.read("views/layout.html.haml")).render do
+ Haml::Engine.new(File.read("views/post.html.haml")).render(Object.new,
+ :contents => @post.output,
+ :title => @post.metadata["title"],
+ :date => @post.metadata["date"]
+ )
+ end
+ end
+end
View
5 views/post.html.haml
@@ -0,0 +1,5 @@
+%h1= title
+%h3 Posted on #{date}
+%hr/
+
+= contents

0 comments on commit ccbdf0a

Please sign in to comment.
Something went wrong with that request. Please try again.