Skip to content

Commit

Permalink
Finalize documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Herbert Kagumba committed Aug 31, 2016
1 parent f07b7db commit 9e7faa8
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 2 deletions.
182 changes: 181 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

**Rapid Runty** is a minimal web framework to get your web project up and running in seconds.

## Dependencies

1. [Ruby](https://github.com/rbenv/rbenv)
2. [SQlite3](https://github.com/sparklemotion/sqlite3-ruby)
3. [Bundler](https://github.com/bundler/bundler)
4. [Rack](https://github.com/rack/rack)
6. [Rspec](https://github.com/rspec/rspec)

## Installation

Add this line to your application's Gemfile:
Expand All @@ -31,7 +39,179 @@ $ gem install rapid_runty

## Usage

TODO: Write usage instructions here
You application structure should be as follows:

```bash
.
├── Gemfile
├── app
│   ├── controllers
│   ├── models
│   └── views
│   └── layouts
│      └── application.html.haml
├── config
│   ├── application.rb
│   └── routes.rb
├── config.ru
└── db
```

### Hacking

Start by defining an `Application` class that inherits from `RapidRunty::Application`.

```ruby
require 'rapid_runty'

$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'controllers')
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'app', 'models')

module TodoList
class TodoApplication < RapidRunty::Application
end
end
```

#### Configuration

You need to define the `ROOT_DIR` in the `config.ru` file. e.g.

```ruby
require_relative './config/application'
ROOT_DIR = __dir__

use Rack::MethodOverride # masks put and delete methods requests as post requests

run TodoListApplication
```

#### Routes

Define your application routes.

```ruby
TodoApplication.routes.draw do
root "todo#index"
get "/todo", to: "todo#index"
get "/todo/new", to: "todo#new"
get "/todo/:id", to: "todo#show"
get "/todo/:id/edit", to: "todo#edit"
post "/todo", to: "todo#create"
put "/todo/:id", to: "todo#update"
delete "/todo/:id", to: "todo#destroy"
end
```

Add the route file to the config file

```ruby
[...]
require_relative './config/routes'
[...]
```

#### Models

Define your models in the `app/models` directory.

```ruby
class Todo < RapidRunty::Model::Base
to_table :todos
property :id, type: :integer, primary_key: true
property :title, type: :text, nullable: false
property :body, type: :text, nullable: false
property :created_at, type: :text, nullable: false
create_table
end
```

#### Controllers

Defines your controllers in the `app/controllers` directory.

```ruby
class TodosController < RapidRunty::BaseController
def index
@todos = Todo.all
end

def show
@todo = Todo.find(params['id'])
end

def new
end

def create
todo = Todo.new
todo.title = params['title']
todo.body = params['body']
todo.created_at = Time.now.to_s
todo.save

redirect_to '/todos'
end

def edit
@todo = Todo.find(params['id'])
end

def update
todo = Todo.find(params['id'])
todo.title = params['title']
todo.body = params['body']
todo.save

redirect_to "/todos/#{todo.id}"
end

def destroy
todo = Todo.find(params['id'])
todo.destroy

redirect_to '/todos'
end
end
```

#### Views

This are the last piece to make the framework work.

You need to define the layout file located at `app/views/layouts/application.html.haml`.

```haml
!!!
%html{:lang => 'en'}
%head
%meta{:content => 'text/html; charset=UTF-8', 'http-equiv' => 'Content-Type'}/
%meta{:charset => 'UTF-8'}/
%title Todo Application
%body
= yield
```

#### Running the application

To run the application, run from you the root of your application,

```bash
$ rackup
```

## Tests

To run the tests, run this command from the root of your application,

```bash
$ rspec -fd
```

## Limitations

- **TODO** - Generate application files with rake command.
- **TODO** - Support model relationships.

## Development

Expand Down
2 changes: 1 addition & 1 deletion spec/support/todoList
Submodule todoList updated 1 files
+0 −0 db/.gitkeep

0 comments on commit 9e7faa8

Please sign in to comment.