0.0
No commit activity in last 3 years
No release in over 3 years
JSend helper for Sinatra
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
~> 2.3

Runtime

~> 1.3.0
 Project Readme

Sinatra::JSend

JSend output helper for Sinatra. Extends Sinatra to support the JSend proprosal.

Depends on the Sinatra::JSON helper from Sinatra-Contrib.

Installation

System install

gem install sinatra-jsend

Gemfile

gem 'sinatra-jsend', :require => 'sinatra/jsend'

Usage

Classic:

require "sinatra"
require "sinatra/jsend"

get '/' do
  jsend_fail({ :title => "A title is required" }) if params[:title] == nil
  jsend_success({ :post => { :id => 1, :title => "First entry" } })
end

Modular:

require "sinatra/base"
require "sinatra/jsend"

class MyApp < Sinatra::Base
  helpers Sinatra::JSend

  get '/' do
    jsend_fail({ :title => "A title is required" }) if params[:title] == nil
    jsend_success({ :post => { :id => 1, :title => "First entry" } })
  end
end

Links

License

See LICENSE for details.