Skip to content

Commit

Permalink
Merge branch 'master' of github.com:shoes/shoesrb.com
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Mar 16, 2012
2 parents 74a83b1 + f7b2941 commit ccbdf0a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -7,3 +7,4 @@ gem 'webmachine', :git => "https://github.com/seancribbs/webmachine-ruby.git"
gem 'rack' gem 'rack'


gem 'haml' gem 'haml'
gem 'metadown'
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -10,12 +10,16 @@ GEM
specs: specs:
haml (3.1.4) haml (3.1.4)
i18n (0.6.0) i18n (0.6.0)
metadown (1.0.1)
redcarpet
rack (1.4.1) rack (1.4.1)
redcarpet (2.1.0)


PLATFORMS PLATFORMS
ruby ruby


DEPENDENCIES DEPENDENCIES
haml haml
metadown
rack rack
webmachine! webmachine!
18 changes: 18 additions & 0 deletions 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

2 changes: 2 additions & 0 deletions config.ru
Expand Up @@ -8,6 +8,8 @@ Dir["resources/*"].each {|f| require "./#{f}" }
Shoes = Webmachine::Application.new do |app| Shoes = Webmachine::Application.new do |app|
app.routes do app.routes do
add [], ShoesHomepage add [], ShoesHomepage
add ["blog"], BlogResource
add ["blog", :slug], BlogResource
add ['*'], StaticResource, :root => "public" add ['*'], StaticResource, :root => "public"
end end
app.configure do |config| app.configure do |config|
Expand Down
9 changes: 9 additions & 0 deletions posts/hello-world.md
@@ -0,0 +1,9 @@
---
title: "Hello World"
slug: "hello-world"
date: 2012-03-15 21:47
---

Hello, world!

**MARKDOWN**!!!!
30 changes: 30 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions 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.