https://github.com/habu-kagumba/rapid_runty
A minimal web framework to get web project up and running in seconds.
https://github.com/habu-kagumba/rapid_runty
rack ruby
Last synced: 12 months ago
JSON representation
A minimal web framework to get web project up and running in seconds.
- Host: GitHub
- URL: https://github.com/habu-kagumba/rapid_runty
- Owner: Habu-Kagumba
- License: mit
- Created: 2016-08-05T12:09:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-13T22:16:53.000Z (over 6 years ago)
- Last Synced: 2025-07-01T22:02:37.875Z (12 months ago)
- Topics: rack, ruby
- Language: Ruby
- Size: 68.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Rapid Runty
[](https://badge.fury.io/rb/rapid_runty) [](https://gemnasium.com/github.com/Habu-Kagumba/rapid_runty) [ ](https://codeship.com/projects/167383) [](https://coveralls.io/github/Habu-Kagumba/rapid_runty?branch=master) [](https://codebeat.co/projects/github-com-habu-kagumba-rapid_runty) [](http://inch-ci.org/github/Habu-Kagumba/rapid_runty)
**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:
```ruby
gem 'rapid_runty'
```
And then execute:
```bash
$ bundle
```
Or install it yourself as:
```bash
$ gem install rapid_runty
```
## Usage
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
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Habu-Kagumba/rapid_runty. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).