Ruby dsl based web framework
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
test
README.rdoc
TODO.txt

README.rdoc

Snap

A DSL-ish framework for building web applications in Ruby.

Example

require '../lib/snap'

module AdminWeb

  include Snap::App

  start do

    get{render 'admin'}

    namespace 'posts' do

      get do
        @posts = Post.all
        render 'admin/posts'
      end

      post do
        @post = Post.new(params[:post])
        # ...
        redirect namespace.full_route
      end

      namespace ':id' do

        # /admin/post/:id
        get do
          @post = Post.find(params[:id])
          render 'admin/post'
        end

        # /admin/post/:id/edit
        get 'edit' do
          @post = Post.find(params[:id])
          render 'admin/post_edit'
        end

      end

    end

  end

end

module Example

  class Web

    include Snap::App

    start do

      before :all=>true do
        @title = 'Blah!'
        @response.body << 'the root namespace BEFORE ALL filter<br/>'
      end

      after :all=>true do
        @response.body << 'the root namespace AFTER ALL filter<br/>'
      end

      get do
        @title = 'HOME'
        render 'home'
      end

      namespace 'admin' do

        use Admin::Web

      end

    end

  end

end