Sha256: 361742df3f85299e3ef4bcddf63e6a0ed8415c72f85eb472716640f7f77c0d1a

Contents?: true

Size: 966 Bytes

Versions: 10

Compression:

Stored size: 966 Bytes

Contents

$: << File.expand_path("../../lib", File.dirname(__FILE__))
$: << File.dirname(__FILE__)
require 'renee'
require 'blog'
require 'json'

blog = Blog.new

run Renee {
  @blog = blog

  # find blog post and do things to it.
  var :integer do |id|
    @post = @blog.find_post(id)
    halt 404 unless @post
    path('edit') { render! 'edit' }

    get { render! 'show' }
    delete { @post.delete!; halt :ok }
    put {
      @post.title = request['title'] if request['title']
      @post.contents = request['contents'] if request['contents']
      halt :ok
    }
  end

  post {
    if request['title'] && request['contents']
      @blog.new_post(request['title'], request['contents'])
      halt :created
    else
      halt :bad_request
    end
  }

  extension('json') { get { halt @blog.posts.map{ |p| {:contents => p.contents} }.to_json } }
  no_extension      { get { render! 'index' } }
}.setup {
  views_path File.expand_path(File.dirname(__FILE__) + "/views")
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
renee-0.3.11 examples/blog/config.ru
renee-0.3.10 examples/blog/config.ru
renee-0.3.7 examples/blog/config.ru
renee-0.3.6 examples/blog/config.ru
renee-0.3.2 examples/blog/config.ru
renee-0.3.1 examples/blog/config.ru
renee-0.3.0 examples/blog/config.ru
renee-0.2.0 examples/blog/config.ru
renee-0.1.1 examples/blog/config.ru
renee-0.1.0 examples/blog/config.ru