Sha256: 1359dd6a8e88c4145ff89dc2540a3ced6186b9af01d3251e68328fafd7e75ada
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
# Grape::Rabl Use rabl templates in grape! [](http://travis-ci.org/LTe/grape-rabl) [](https://gemnasium.com/LTe/grape-rabl) ## Installation Add this line to your application's Gemfile: ```ruby gem 'grape-rabl' gem 'grape', :git => "git://github.com/intridea/grape.git", :branch => "frontier" ``` And then execute: $ bundle ## Usage ### Require grape-rabl ```ruby # config.ru require 'grape-rabl' ``` ### Setup view root directory ```ruby # config.ru require 'grape-rabl' use Rack::Config do |env| env['api.tilt.root'] = '/path/to/view/root/directory' end ``` ### Create grape application To *get post put delete options* add **:rabl** options with template name. ```ruby get "/path", :rabl => "template_name.rabl" do # stuff @var = "hello" end post "/path", :rabl => "template_name_diff.rabl" do # stuff @user = User.find_user("email@example.com") end ``` **You can use instance variables in templates!** ### Example ```ruby # config.ru require 'grape-rabl' use Rack::Config do |env| env['api.tilt.root'] = '/path/to/view/root/directory' end class UserAPI < Grape::API # use rabl with 'hello.rabl' template get '/user', :rabl => 'hello.rabl' do @user = User.first end # do not use rabl, normal usage get '/user2' do { :some => :hash } end end ``` ```ruby # hello.rabl object @user => :user attributes :name ``` Enjoy :) ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grape-rabl-0.0.2 | README.md |