Give cuba some sugar!
Ruby HTML
Latest commit 66b9464 Jul 5, 2016 @elcuervo committed on GitHub Merge pull request #6 from alexford/patch-1
Fix content_for syntax in README
Permalink
Failed to load latest commit information.
lib/cuba New version Jul 6, 2012
test Use require_relative for test_helper Nov 3, 2014
.gitignore ignore a built *.gem Mar 30, 2011
Gemfile it needs rake here wtf Sep 15, 2011
Gemfile.lock Bump May 21, 2015
LICENSE Readme and License Mar 30, 2011
README.md Fix content_for syntax in README Jul 5, 2016
Rakefile Refactors tests Jan 21, 2014
cuba-sugar.gemspec Bump May 21, 2015

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:

You have two choices:

  • require only the tool you want eg: require 'cuba/sugar/content_for'
  • require all the tools eg: require 'cuba/sugar'

content_for

require "cuba"
require "cuba/sugar/content_for"

Cuba.plugin Cuba::Sugar::ContentFor

In your views to define where the content block will be rendered

<% yield_for :menu %>

# And when you want to define a content
<% content_for :menu do %>
  <ul id="menu">
    <li class="active">Home</li>
    <li>Users</li>
  </ul>
<% end %>

as

require "cuba"
require "cuba/sugar/as"

Cuba.use Rack::Session::Cookie

Cuba.plugin Cuba::Sugar::As
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/as"

Cuba.use Rack::Session::Cookie

Cuba.plugin Cuba::Sugar::As
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/csrf"

Cuba.use Rack::Csrf

Cuba.plugin Cuba::Sugar::Csrf
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/routes"

Cuba.plugin Cuba::Sugar::Routes
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