• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby gem that is a Sinatra app generator with Rails-like simplicity. I built this to help fellow Flatiron School students with their Sinatra assessments.

Corneal

Why this exists

When I was creating my first major Sinatra project, Cook This Way, while doing Learn Verified, I was looking for a way to build a Sinatra skeleton similar to running

rails new APP-NAME

Hazel was the closest thing I could find and this gem is based largely off of it. While it did provide a pretty good initial setup, I still had to tweak some things. The views were sitting in the root directory while I wanted them to reside in an app folder along with my models and controllers. There was also no environment.rb in the config folder as I had become accustom to having.

I also wanted to create a gem for future Learn students so they could easily get started building their projects. Although built with them in mind, this can get you off and running with any Sinatra app.

Install the gem, run corneal new APP-NAME, run bundle install, and you're all set! You can start up your server with shotgun and verify everything is working. It is as simple as that.

It uses a file structure similar to what you would see with Rails.

Directory structure:

โ”œโ”€โ”€ config.ru
โ”œโ”€โ”€ Gemfile
โ”œโ”€โ”€ Gemfile.lock
โ”œโ”€โ”€ Rakefile
โ”œโ”€โ”€ README
โ”œโ”€โ”€ app
โ”‚   โ”œโ”€โ”€ controllers
โ”‚   โ”‚   โ””โ”€โ”€ application_controller.rb
โ”‚   โ”œโ”€โ”€ models
โ”‚   โ””โ”€โ”€ views
โ”‚       โ”œโ”€โ”€ layout.erb
โ”‚       โ””โ”€โ”€ welcome.erb
โ”œโ”€โ”€ config
โ”‚   โ”œโ”€โ”€ initializers
โ”‚   โ””โ”€โ”€ environment.rb
โ”œโ”€โ”€ db
โ”‚   โ””โ”€โ”€ migrate
โ”œโ”€โ”€ lib
โ”‚   โ””โ”€โ”€ .gitkeep
โ””โ”€โ”€ public
|   โ”œโ”€โ”€ images
|   โ”œโ”€โ”€ javascripts
|   โ””โ”€โ”€ stylesheets
|       โ””โ”€โ”€ main.css
โ””โ”€โ”€ spec
    โ”œโ”€โ”€ application_controller_spec.rb
    โ””โ”€โ”€ spec_helper.rb

Installation

gem install corneal

Commands

corneal -v              # Show Corneal version number
corneal help [COMMAND]  # Describe available commands or one specific command
corneal new APP-NAME    # Creates a new Sinatra application
corneal model NAME      # Generate a model
corneal controller NAME # Generate a controller
corneal scaffold NAME   # Generate a model with its associated views and controllers

The controller generator also have an optional views flag --no-views to create controllers without views.

Using Corneal

To generate your app:

corneal new APP-NAME

After Corneal is done generating your app, run bundle install from your app's directory:

cd APP-NAME
bundle install

You can then start your server with shotgun:

shotgun

You can generate a model and migration file:

corneal model NAME

You can also generate an entire MVC structure complete with a migration file:

corneal scaffold NAME

The resulting structure will look like this:

โ””โ”€app
  โ”œโ”€โ”€ controllers
  โ”‚   โ”œโ”€โ”€application_controller.rb
  โ”‚   โ””โ”€โ”€new_model_controller.rb
  โ”œโ”€โ”€ models
  โ”‚   โ””โ”€โ”€new_model.rb
  โ””โ”€โ”€ views
      โ”œโ”€โ”€new_models
      โ”‚  โ”œโ”€โ”€index.html.rb.erb
      โ”‚  โ”œโ”€โ”€show.html.rb.erb
      โ”‚  โ”œโ”€โ”€new.html.rb.erb
      โ”‚  โ””โ”€โ”€edit.html.rb.erb
      โ”œโ”€โ”€ layout.erb
      โ””โ”€โ”€ welcome.erb

You can also add your model attributes when you generate the scaffold structure and have them added to your migration file:

corneal [model/scaffold] NAME name:string age:integer
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :name
      t.age :integer

      t.timestamps null: false
    end
  end
end

Visit http://localhost:9393/ to verify your app is running.

You can also verify it is working by running rspec to see the passing test:

1 example, 0 failures

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/thebrianemory/corneal This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

Copyright (c) 2016 Brian Emory

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.