Giter VIP home page Giter VIP logo

sinator's Introduction

Gem Version Maintainability Test Coverage

Background

Sinator is Sinatra application generator. It will generate Sinatra application with minimum configuration. The reasons behind this project because I want to create many small web application based on sinatra with other third party ruby gems as foundation.

Features

  • Generate Sinatra based web application without database
  • Generate Sinatra based web application with PostgreSQL database configuration and Sequel as ORM
  • Rake task for assets precompile and assets clean

Installation

gem install sinator

with Bundler, put this code in your Gemfile:

gem 'sinator'

How to Use

Generate app in current directory without database.

sinator -n my_app

Generate app in target directory without database.

sinator -n my_app -t target/dir

Generate app in current directory with database. -d option will generate app with Sequel ORM and PostgreSQL adapter.

sinator -n my_app -d

Run web server on localhost.

bundle exec puma

Run application console / interactive mode / IRB.

bundle exec tux

Example Usage

This example assume that PostgreSQL is already running. See github.com/kuntoaji/todo_sinator for Todo Application generated with Sinator.

  1. run sinator -n my_app -d
  2. cd my_app
  3. run bundle install
  4. configure your database setting in config/database.yml
  5. create database with createdb my_app_development.
  6. create file db/migrations/001_create_artists.rb and put the following code:
Sequel.migration do
  up do
    create_table(:artists) do
      primary_key :id
      String :name, :null=>false
    end
  end

  down do
    drop_table(:artists)
  end
end
  1. run rake db:migrate
  2. create file app/models/Artist.rb and put the following code:
class Artist < Sequel::Model
end
  1. create file app/routes/artists.rb and put the following code:
class MyApp
  get '/artists' do
    @artists = Artist.all
    erb :"artists/index"
  end

  post '/artists' do
    @artist = Artist.new
    @artist.name = params[:name]
    @artist.save

    redirect '/artists'
  end
end
  1. create file app/views/artists/index.erb and put the following code:
<h1>List of Artist</h1>
<ul>
  <% @artists.each do |artist| %>
    <li><%= artist.name %></li>
  <% end %>
</ul>

<form action="/artists" method="post">
  <%= Rack::Csrf.tag(env) %>
  <input type="text" name="name" />
  <button>Submit</button>
</form>
  1. run the server bundle exec puma
  2. open url localhost:9292/artists
  3. Enjoy! :)

sinator's People

Contributors

dependabot[bot] avatar kuntoaji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

maziano

sinator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.