Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Give cuba some sugar!
tree: 989caaebec

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/cuba
test
.gitignore
Gemfile
LICENSE
README.md
Rakefile
cuba-sugar.gemspec

README.md

Cuba/Sugar

Build Status

n. bundled sugar for cuba

"See this fucking sugar road? I just fucking made it"

Description

It's like contrib stuff but with a cooler name. Provides helpers and utilities to use with cuba.

Usage

Like any other cuba app, but provides:

as

require "cuba"
require "cuba/sugar"

Cuba.use Rack::Session::Cookie

Cuba.plugin Cuba::Sugar
Cuba.define do
  on post do
    on "users" do
      # create user
      as 201, {"Content-Location" => "http://somewhere.com/users/705"} do
        "user #{user.id} created"
      end
    end
  end
end

as_json

require "cuba"
require "cuba/sugar"

Cuba.use Rack::Session::Cookie

Cuba.plugin Cuba::Sugar
Cuba.define do
  on get do
    on "weather" do
      as_json do
        {
          city:         'La Habana',
          temperature:  '19 °C',
          pressure:     '1014 hPa',
        }
      end
    end
  end
end

csrf_tag && csrf_token

In the forms:

<%= csrf_tag %>

In the code:

require "cuba"
require "cuba/sugar"

Cuba.use Rack::Csrf

Cuba.plugin Cuba::Sugar
Cuba.define do
  # Automatic csrf validation
  on post
  end
end

helpers

require "cuba"
require "cuba/sugar"

Cuba.plugin Cuba::Sugar
Cuba.define do
  helpers do
    def now
      Time.now
    end
  end

  on "time" do
    as { "The current time is: #{now}" }
  end
end

subdomain

require "cuba"
require "cuba/sugar"

Cuba.plugin Cuba::Sugar
Cuba.define do
  on subdomain("wsdl") do
    run WSDL
  end

  on subdomain("api") do
    on root do
      as do
        "Welcome to API"
      end
    end

    on "users" do
      as_json do
        Users.all.to_json
      end
    end
  end
end

Contributors

Installation

$ gem install cuba-sugar
Something went wrong with that request. Please try again.