Snipsnap::Extensions

Sinatra Extensions from the SnipSnap / Goodfor codebases

Installation

Since this is a private repository, you'll either need to setup your deployment box to have proper GitHub credentials, or more easily you need to vendor the gem.

$ mkdir -p vendor/private_gems
$ git clone [email protected]:snipsnap/snipsnap-extensions.git vendor/private_gems/snipsnap-extensions

Add this line to your application's Gemfile:

gem 'snipsnap-extensions', '0.0.1', path: 'vendor/private_gems/snipsnap-extensions'

And then execute:

$ bundle

Usage

In your Sinatra::Base file, require the extension and then register it

For example, to include the SnipSnap::CORSExtension,

# app.rb
require 'snipsnap/extensions/cors'

# ...
class App < Sinatra::Base
  # ...
  register SnipSnap::CORSExtension
end

Require All

# app.rb
require 'snipsnap/extensions/all'

# ...
class App < Sinatra::Base
  # ...
  register SnipSnap::AuthExtension
  register SnipSnap::CORSExtension
  # ...
end

Extensions

SnipSnap::ActionMailerExtension

Require Path: 'snipsnap/extensions/action_mailer'

Optional:

  • ENV['EMAIL_ADDRESS'] defaults to "smtp.sendgrid.net"
  • ENV['URL_ROOT'] for prepending email URLs with url_for(path)

Requires:

  • gem 'actionmailer'
  • gem 'letter_opener' in development
  • ENV['EMAIL_DOMAIN'] for outgoing mail domain
  • ENV['EMAIL_USER_NAME'] for sendgrid username
  • ENV['EMAIL_PASSWORD'] for sendgrid password

SnipSnap::ActiveRecord

Require path: snipsnap/extensions/active_record

Requires:

  • gem 'activerecord'
  • gem 'sinatra-activerecord'

SnipSnap::Auth

Require Path: snipsnap/extensions/auth

Requires:

  • Guest model to act as an unfound user

    • include the SnipSnap::Guest mixin into your Guest class
  • include the SnipSnap::User mixin into your

  • User model that

    • responds to authenticate to check for password match (matching the has_secure_password interface)
    • responds to authorized?

SnipSnap::CORSExtension

Require Path: snipsnap/extensions/cors

SnipSnap::DeliveryExtension

Require Path: snipsnap/extensions/delivery

SnipSnap::JSONBodyExtension

Require Path: snipsnap/extensions/json_body

SnipSnap::LoggingExtension

Require Path: snipsnap/extensions/logging

SnipSnap::PaperclipExtension

Setup paperclip file management

Require Path: snipsnap/extensions/paperclip

Requires:

  • gem 'paperclip'
  • imagemagick installed on system

SnipSnap::PlatformDetectExtension

Require Path: snipsnap/extensions/platform_detect

SnipSnap::SprocketsExtension

Require Path: snipsnap/extensions/sprockets

Optional:

  • ENV['ASSET_HOST'] prepended to asset URLs
  • ENV['API_ROOT'] prepended to API AJAX calls

Required:

  • gem 'sprockets'
  • gem 'sass'
  • gem 'coffee-script'

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