Home

Awesome

SAT

Sinatra Application Template.

Features

Installation

$ git clone git@github.com:patriciomacadden/sat.git
$ git remote rm origin
$ git remote add origin <YOUR_GIT_REPOSITORY>
$ APP_NAME=AwesomeApp; for i in `find . -type f | grep -v .git`; do if [ `grep SAT $i | wc -l` != 0 ]; then sed -i '' "s/SAT/$APP_NAME/g" $i; fi; done; git commit -am "SAT => $APP_NAME"

Note: Note the APP_NAME variable. You should change the application name there.

Creating a new controller

Let's create a controller for handling products.

module SAT::Application
  class ProductsController < ApplicationController
    set prefix: '/products'
    # views will be found in app/views/products directory.
    # If you want to change the views directory, use this
    # configuration option.
    # set views_prefix: '/some_other_directory'

    get '/' do
      # will render app/views/products/index.erb
      # erb :index
      'Hello World'
    end
  end
end
module SAT::Application
  module ProductsHelpers
    # helper methods
  end
end
$ mkdir app/views/products
require 'minitest_helper'

describe SAT::Application::ProductsController do
  include Rack::Test::Methods

  def app
    SAT::Application
  end

  describe 'GET /products' do
    it 'must be ok' do
      get '/products'
      last_response.must_be :ok?
    end
  end
end
require 'minitest_helper'

describe SAT::Application::ProductsHelpers do
  include Rack::Test::Methods

  def app
    SAT::Application
  end
end

Custom settings

Two settings are introduced:

Caveats

Since the application itself its a Rack::Builder that maps the different controllers to a particular path, you need to use that builder to use any rack middleware.

See an example:

# in environment.rb:

config.builder.use Rack::Auth::Basic do |username, password|
  username == 'admin' && password == 'secret'
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

See the LICENSE.