Skip to content

Commit

Permalink
Cuba Sugar is now a Cuba Contrib plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
elcuervo committed Dec 19, 2011
1 parent dbaaef5 commit 0ac797e
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions cuba-sugar.gemspec
Expand Up @@ -10,6 +10,7 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files test`.split("\n")

s.add_dependency("cuba")
s.add_dependency("cuba-contrib")
s.add_dependency("json")
s.add_dependency("rack_csrf")

Expand Down
5 changes: 3 additions & 2 deletions lib/cuba/sugar.rb
@@ -1,7 +1,7 @@
require 'json'
require "cuba/contrib"
require "rack/csrf"

class Cuba
module Cuba::Sugar

# Sugar to access root of a page
#
Expand Down Expand Up @@ -56,6 +56,7 @@ def as(http_code = 200, extra_headers = {})
# end
# end
def as_json(http_code = 200, extra_headers = {})
require 'json'
extra_headers["Content-Type"] ||= "application/json"
as(http_code, extra_headers) do
(yield).to_json if block_given?
Expand Down
1 change: 1 addition & 0 deletions test/as.rb
@@ -1,6 +1,7 @@
require File.expand_path("helper", File.dirname(__FILE__))

test "set status and headers through helper" do
Cuba.plugin Cuba::Sugar
Cuba.define do
on "users" do
as 201, {"Content-Location" => "http://somewhere.com/users/705"} do
Expand Down
2 changes: 2 additions & 0 deletions test/as_json.rb
Expand Up @@ -3,6 +3,8 @@

test "set a block to return json" do
rum_and_coke = { "rum" => "hot", "coke" => "sweet" }

Cuba.plugin Cuba::Sugar
Cuba.define do
on "drinks" do
as_json 201, {"Content-Location" => "http://somewhere.com/drinks/42"} do
Expand Down
1 change: 1 addition & 0 deletions test/csrf.rb
@@ -1,6 +1,7 @@
require File.expand_path("helper", File.dirname(__FILE__))

test "set status and headers through helper" do
Cuba.plugin Cuba::Sugar
Cuba.define do
on "users" do
as do
Expand Down
1 change: 1 addition & 0 deletions test/helpers.rb
@@ -1,6 +1,7 @@
require File.expand_path("helper", File.dirname(__FILE__))

test "set status and headers through helpers" do
Cuba.plugin Cuba::Sugar
Cuba.define do
helpers do
def upperize(string)
Expand Down
1 change: 1 addition & 0 deletions test/redirect.rb
@@ -1,6 +1,7 @@
require File.expand_path("helper", File.dirname(__FILE__))

test "redirect helper" do
Cuba.plugin Cuba::Sugar
Cuba.define do
on "old" do
redirect "/new"
Expand Down
1 change: 1 addition & 0 deletions test/subdomain.rb
@@ -1,6 +1,7 @@
require File.expand_path("helper", File.dirname(__FILE__))

test "eval only in a given subdomain" do
Cuba.plugin Cuba::Sugar
Cuba.define do
on subdomain("api"), root do
as do
Expand Down

0 comments on commit 0ac797e

Please sign in to comment.