From 026fb0d7e9e85272bf9176ecbb5bc9e455fc0e89 Mon Sep 17 00:00:00 2001 From: "Daniel Doubrovkine (dB.) @dblockdotorg" Date: Tue, 30 Dec 2014 17:40:49 -0500 Subject: [PATCH 01/29] Use prettier badges. [ci skip] --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95bee8e..e9dcaeb 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github.com/intridea/grape)! -[![Build Status](https://secure.travis-ci.org/LTe/grape-rabl.png)](http://travis-ci.org/LTe/grape-rabl) -[![Dependency Status](https://gemnasium.com/LTe/grape-rabl.png)](https://gemnasium.com/LTe/grape-rabl) -[![Code Climate](https://codeclimate.com/github/LTe/grape-rabl.png)](https://codeclimate.com/github/LTe/grape-rabl) -[![Coverage Status](https://coveralls.io/repos/LTe/grape-rabl/badge.png?branch=master)](https://coveralls.io/r/LTe/grape-rabl?branch=master) -[![Gem Version](https://badge.fury.io/rb/grape-rabl.png)](http://badge.fury.io/rb/grape-rabl) +[![Gem Version](http://img.shields.io/gem/v/grape-rabl.svg)](http://badge.fury.io/rb/grape-rabl) +[![Build Status](http://img.shields.io/travis/LTe/grape-rabl.svg)](https://travis-ci.org/LTe/grape-rabl) +[![Dependency Status](https://gemnasium.com/LTe/grape-rabl.svg)](https://gemnasium.com/LTe/grape-rabl) +[![Code Climate](https://codeclimate.com/github/LTe/grape-rabl.svg)](https://codeclimate.com/github/LTe/grape-rabl) +[![Coverage Status](https://img.shields.io/coveralls/LTe/grape-rabl.svg)](https://coveralls.io/r/LTe/grape-rabl?branch=master) ## Installation From 406ab90594016cf7202ddeeaa36569034a4bd966 Mon Sep 17 00:00:00 2001 From: Meck Date: Tue, 10 Feb 2015 22:53:59 +0800 Subject: [PATCH 02/29] Do not modify endpoint when using render. #35 --- CHANGELOG.md | 1 + lib/grape-rabl/formatter.rb | 13 ++++++++----- lib/grape-rabl/render.rb | 4 ++-- spec/grape_rabl_spec.rb | 5 +++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6724353..3be6366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ #### Next +* The `render` method will not modify endpoint options at runtime now. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) * Your contribution here. #### v0.3.0 diff --git a/lib/grape-rabl/formatter.rb b/lib/grape-rabl/formatter.rb index 10bffce..6545e70 100644 --- a/lib/grape-rabl/formatter.rb +++ b/lib/grape-rabl/formatter.rb @@ -37,18 +37,21 @@ def view_path(template) end def rablable? - !!endpoint.options[:route_options][:rabl] + !!rabl_template end def rabl - template = endpoint.options[:route_options][:rabl] - fail 'missing rabl template' unless template + fail 'missing rabl template' unless rabl_template set_view_root unless env['api.tilt.root'] - yield template + yield rabl_template end def locals - endpoint.options[:route_options][:rabl_locals] || {} + env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {} + end + + def rabl_template + env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl] end def set_view_root diff --git a/lib/grape-rabl/render.rb b/lib/grape-rabl/render.rb index c36412e..8e2a623 100644 --- a/lib/grape-rabl/render.rb +++ b/lib/grape-rabl/render.rb @@ -1,8 +1,8 @@ module GrapeRabl module Render def render(options = {}) - env['api.endpoint'].options[:route_options][:rabl] = options.delete(:rabl) if options.include?(:rabl) - env['api.endpoint'].options[:route_options][:rabl_locals] = options.delete(:locals) + env['api.tilt.rabl'] = options[:rabl] + env['api.tilt.rabl_locals'] = options[:locals] end end end diff --git a/spec/grape_rabl_spec.rb b/spec/grape_rabl_spec.rb index 8484d40..86e2f26 100644 --- a/spec/grape_rabl_spec.rb +++ b/spec/grape_rabl_spec.rb @@ -103,6 +103,11 @@ def app get('/about') parsed_response.should == JSON.parse('{"user":{"name":"LTe","project":null}}') end + + it 'does not modify endpoint options' do + get '/home' + expect(last_request.env['api.endpoint'].options[:route_options][:rabl]).to eq 'user' + end end it 'should respond with proper content-type' do From 8e4bf188914f6cee3aa3b95f09fffd8567bd116f Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 11 Feb 2015 10:15:01 -0500 Subject: [PATCH 03/29] Preparing for release, 0.3.1. --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be6366..2946c1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ -#### Next +#### v0.3.1 -* The `render` method will not modify endpoint options at runtime now. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) -* Your contribution here. +* The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) #### v0.3.0 From e3f80d5ed50610148ef1364b4ac1604b16a78926 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 11 Feb 2015 10:16:15 -0500 Subject: [PATCH 04/29] Preparing for next development iteration, 0.3.2. --- CHANGELOG.md | 4 ++++ lib/grape-rabl/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2946c1a..a3be9c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Next + +* Your contribution here. + #### v0.3.1 * The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index 092622a..f6b4615 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.3.1' + VERSION = '0.3.2' end end From eb7b86b63d9519e0a87a3805f535a696f11e87f9 Mon Sep 17 00:00:00 2001 From: Kush Kella Date: Mon, 22 Jun 2015 12:56:19 +0500 Subject: [PATCH 05/29] make grape-rabl formatter thread-safe --- lib/grape-rabl/formatter.rb | 136 ++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 62 deletions(-) diff --git a/lib/grape-rabl/formatter.rb b/lib/grape-rabl/formatter.rb index 6545e70..606e5c7 100644 --- a/lib/grape-rabl/formatter.rb +++ b/lib/grape-rabl/formatter.rb @@ -4,84 +4,96 @@ module Grape module Formatter module Rabl class << self - attr_reader :env - attr_reader :endpoint - def call(object, env) - @env = env - @endpoint = env['api.endpoint'] - - if rablable? - rabl do |template| - engine = tilt_template(template) - output = engine.render endpoint, locals - if layout_template - layout_template.render(endpoint) { output } - else - output - end - end - else - Grape::Formatter::Json.call object, env - end + GrapeRabl::Formatter.new(object, env).render end + end + end + end +end + +module GrapeRabl + class Formatter + class << self + def tilt_cache + @tilt_cache ||= ::Tilt::Cache.new + end + end + + attr_reader :env, :endpoint, :object - private + def initialize(object, env) + @env = env + @endpoint = env['api.endpoint'] + @object = object + end - def view_path(template) - if template.split('.')[-1] == 'rabl' - File.join(env['api.tilt.root'], template) + def render + if rablable? + rabl do |template| + engine = tilt_template(template) + output = engine.render endpoint, locals + if layout_template + layout_template.render(endpoint) { output } else - File.join(env['api.tilt.root'], (template + '.rabl')) + output end end + else + Grape::Formatter::Json.call object, env + end + end - def rablable? - !!rabl_template - end + private - def rabl - fail 'missing rabl template' unless rabl_template - set_view_root unless env['api.tilt.root'] - yield rabl_template - end + def view_path(template) + if template.split('.')[-1] == 'rabl' + File.join(env['api.tilt.root'], template) + else + File.join(env['api.tilt.root'], (template + '.rabl')) + end + end - def locals - env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {} - end + def rablable? + !!rabl_template + end - def rabl_template - env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl] - end + def rabl + fail 'missing rabl template' unless rabl_template + set_view_root unless env['api.tilt.root'] + yield rabl_template + end - def set_view_root - fail "Use Rack::Config to set 'api.tilt.root' in config.ru" - end + def locals + env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {} + end - def tilt_template(template) - if Grape::Rabl.configuration.cache_template_loading - tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) } - else - ::Tilt.new(view_path(template), tilt_options) - end - end + def rabl_template + env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl] + end - def tilt_cache - @tilt_cache ||= ::Tilt::Cache.new - end + def set_view_root + fail "Use Rack::Config to set 'api.tilt.root' in config.ru" + end - def tilt_options - { format: env['api.format'], view_path: env['api.tilt.root'] } - end + def tilt_template(template) + if Grape::Rabl.configuration.cache_template_loading + GrapeRabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) } + else + ::Tilt.new(view_path(template), tilt_options) + end + end - def layout_template - layout_path = view_path(env['api.tilt.layout'] || 'layouts/application') - if Grape::Rabl.configuration.cache_template_loading - tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) } - else - ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) - end - end + def tilt_options + { format: env['api.format'], view_path: env['api.tilt.root'] } + end + + def layout_template + layout_path = view_path(env['api.tilt.layout'] || 'layouts/application') + if Grape::Rabl.configuration.cache_template_loading + GrapeRabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) } + else + ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) end end end From ccfb7e8ca96aeaea967ad48edda531ab664b6974 Mon Sep 17 00:00:00 2001 From: Kush Kella Date: Tue, 23 Jun 2015 10:22:38 +0500 Subject: [PATCH 06/29] refactor code --- CHANGELOG.md | 1 + lib/grape-rabl/formatter.rb | 134 +++++++++++++++++------------------- lib/grape-rabl/render.rb | 14 ++-- lib/grape/rabl.rb | 12 ++++ 4 files changed, 83 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3be9c2..43f2221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ #### Next +* Make grape-rabl thread-safe. [#37](https://github.com/LTe/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella) * Your contribution here. #### v0.3.1 diff --git a/lib/grape-rabl/formatter.rb b/lib/grape-rabl/formatter.rb index 606e5c7..eca5624 100644 --- a/lib/grape-rabl/formatter.rb +++ b/lib/grape-rabl/formatter.rb @@ -1,99 +1,89 @@ require 'json' module Grape - module Formatter - module Rabl + module Rabl + class Formatter class << self - def call(object, env) - GrapeRabl::Formatter.new(object, env).render + def tilt_cache + @tilt_cache ||= ::Tilt::Cache.new end end - end - end -end -module GrapeRabl - class Formatter - class << self - def tilt_cache - @tilt_cache ||= ::Tilt::Cache.new - end - end - - attr_reader :env, :endpoint, :object + attr_reader :env, :endpoint, :object - def initialize(object, env) - @env = env - @endpoint = env['api.endpoint'] - @object = object - end + def initialize(object, env) + @env = env + @endpoint = env['api.endpoint'] + @object = object + end - def render - if rablable? - rabl do |template| - engine = tilt_template(template) - output = engine.render endpoint, locals - if layout_template - layout_template.render(endpoint) { output } - else - output + def render + if rablable? + rabl do |template| + engine = tilt_template(template) + output = engine.render endpoint, locals + if layout_template + layout_template.render(endpoint) { output } + else + output + end end + else + Grape::Formatter::Json.call object, env end - else - Grape::Formatter::Json.call object, env end - end - private + private - def view_path(template) - if template.split('.')[-1] == 'rabl' - File.join(env['api.tilt.root'], template) - else - File.join(env['api.tilt.root'], (template + '.rabl')) + def view_path(template) + if template.split('.')[-1] == 'rabl' + File.join(env['api.tilt.root'], template) + else + File.join(env['api.tilt.root'], (template + '.rabl')) + end end - end - def rablable? - !!rabl_template - end + def rablable? + !!rabl_template + end - def rabl - fail 'missing rabl template' unless rabl_template - set_view_root unless env['api.tilt.root'] - yield rabl_template - end + def rabl + fail 'missing rabl template' unless rabl_template + set_view_root unless env['api.tilt.root'] + yield rabl_template + end - def locals - env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {} - end + def locals + env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {} + end - def rabl_template - env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl] - end + def rabl_template + env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl] + end - def set_view_root - fail "Use Rack::Config to set 'api.tilt.root' in config.ru" - end + def set_view_root + fail "Use Rack::Config to set 'api.tilt.root' in config.ru" + end - def tilt_template(template) - if Grape::Rabl.configuration.cache_template_loading - GrapeRabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) } - else - ::Tilt.new(view_path(template), tilt_options) + def tilt_template(template) + if Grape::Rabl.configuration.cache_template_loading + Grape::Rabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) } + else + ::Tilt.new(view_path(template), tilt_options) + end end - end - def tilt_options - { format: env['api.format'], view_path: env['api.tilt.root'] } - end + def tilt_options + { format: env['api.format'], view_path: env['api.tilt.root'] } + end - def layout_template - layout_path = view_path(env['api.tilt.layout'] || 'layouts/application') - if Grape::Rabl.configuration.cache_template_loading - GrapeRabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) } - else - ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) + def layout_template + layout_path = view_path(env['api.tilt.layout'] || 'layouts/application') + if Grape::Rabl.configuration.cache_template_loading + Grape::Rabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) } + else + ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) + end end end end diff --git a/lib/grape-rabl/render.rb b/lib/grape-rabl/render.rb index 8e2a623..5838159 100644 --- a/lib/grape-rabl/render.rb +++ b/lib/grape-rabl/render.rb @@ -1,10 +1,12 @@ -module GrapeRabl - module Render - def render(options = {}) - env['api.tilt.rabl'] = options[:rabl] - env['api.tilt.rabl_locals'] = options[:locals] +module Grape + module Rabl + module Render + def render(options = {}) + env['api.tilt.rabl'] = options[:rabl] + env['api.tilt.rabl_locals'] = options[:locals] + end end end end -Grape::Endpoint.send(:include, GrapeRabl::Render) +Grape::Endpoint.send(:include, Grape::Rabl::Render) diff --git a/lib/grape/rabl.rb b/lib/grape/rabl.rb index db75dd3..61cf891 100644 --- a/lib/grape/rabl.rb +++ b/lib/grape/rabl.rb @@ -1 +1,13 @@ require 'grape-rabl' + +module Grape + module Formatter + module Rabl + class << self + def call(object, env) + Grape::Rabl::Formatter.new(object, env).render + end + end + end + end +end From c07e4483d0529a524957e1fdce098805cd99bd35 Mon Sep 17 00:00:00 2001 From: dB Date: Fri, 26 Jun 2015 09:26:24 -0400 Subject: [PATCH 07/29] Preparing for release, v0.4.0. --- CHANGELOG.md | 3 +-- lib/grape-rabl/version.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f2221..1aa87b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ -#### Next +#### v0.4.0 * Make grape-rabl thread-safe. [#37](https://github.com/LTe/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella) -* Your contribution here. #### v0.3.1 diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index f6b4615..86a8d71 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.3.2' + VERSION = '0.4.0' end end From f727e1d4111c1c3a658652cf5eafea7733ad6860 Mon Sep 17 00:00:00 2001 From: dB Date: Fri, 26 Jun 2015 09:27:55 -0400 Subject: [PATCH 08/29] Preparing for next development iteration, 0.4.1. --- CHANGELOG.md | 4 ++++ lib/grape-rabl/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa87b2..e040f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Next + +* Your contribution here. + #### v0.4.0 * Make grape-rabl thread-safe. [#37](https://github.com/LTe/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella) diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index 86a8d71..9751270 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.4.0' + VERSION = '0.4.1' end end From 94de02b398561b77e9e3db4fb554080bf80d05ff Mon Sep 17 00:00:00 2001 From: Fran J Martinez Date: Wed, 15 Jul 2015 07:33:10 -0400 Subject: [PATCH 09/29] Automatically require grape/rabl. --- CHANGELOG.md | 1 + README.md | 15 --------------- lib/grape-rabl.rb | 1 + 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e040f07..b3b39c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ #### Next +* Automatically require 'grape/rabl'. [#39](https://github.com/LTe/grape-rabl/issues/39) [@martinezcoder](https://github.com/martinezcoder) * Your contribution here. #### v0.4.0 diff --git a/README.md b/README.md index e9dcaeb..75ab7ea 100644 --- a/README.md +++ b/README.md @@ -23,18 +23,9 @@ And then execute: ## 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 @@ -78,8 +69,6 @@ You can override the default layout conventions: ```ruby # config.ru -require 'grape/rabl' - use Rack::Config do |env| env['api.tilt.root'] = '/path/to/view/root/directory' env['api.tilt.layout'] = 'layouts/another' @@ -94,8 +83,6 @@ You can enable template caching: ```ruby # config.ru -require 'grape/rabl' - Grape::Rabl.configure do |config| config.cache_template_loading = true # default: false end @@ -114,8 +101,6 @@ get "/home", :rabl => "view.rabl" ```ruby # config.ru -require 'grape/rabl' - use Rack::Config do |env| env['api.tilt.root'] = '/path/to/view/root/directory' end diff --git a/lib/grape-rabl.rb b/lib/grape-rabl.rb index f085d06..584f408 100644 --- a/lib/grape-rabl.rb +++ b/lib/grape-rabl.rb @@ -1,6 +1,7 @@ require 'rabl' require 'grape' require 'hashie/hash' +require 'grape/rabl' require 'grape-rabl/tilt' require 'grape-rabl/version' require 'grape-rabl/formatter' From 9f2d1c9f20469d2c5284f8f5643f6b1ab2059f9d Mon Sep 17 00:00:00 2001 From: dB Date: Mon, 3 Aug 2015 08:26:41 -0400 Subject: [PATCH 10/29] Preparing for release, 0.4.1. --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3b39c5..c03bb1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ -#### Next +#### v0.4.1 * Automatically require 'grape/rabl'. [#39](https://github.com/LTe/grape-rabl/issues/39) [@martinezcoder](https://github.com/martinezcoder) -* Your contribution here. #### v0.4.0 From afa18a53e3cde2e1a7856f3aeb06a7439200f0c3 Mon Sep 17 00:00:00 2001 From: dB Date: Mon, 3 Aug 2015 08:27:17 -0400 Subject: [PATCH 11/29] Preparing for next development iteration, 0.4.2. --- CHANGELOG.md | 4 ++++ lib/grape-rabl/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c03bb1c..312e3c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Next + +* Your contribution here. + #### v0.4.1 * Automatically require 'grape/rabl'. [#39](https://github.com/LTe/grape-rabl/issues/39) [@martinezcoder](https://github.com/martinezcoder) diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index 9751270..d534d97 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.4.1' + VERSION = '0.4.2' end end From 531a12c97a8e141d109ef7da7732ea26d01e7dd3 Mon Sep 17 00:00:00 2001 From: dB Date: Thu, 20 Aug 2015 07:08:33 -0400 Subject: [PATCH 12/29] LTe => ruby-grape. --- CHANGELOG.md | 58 +++++++++++----------- CONTRIBUTING.md | 118 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 10 ++-- grape-rabl.gemspec | 2 +- 4 files changed, 153 insertions(+), 35 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 312e3c5..3692326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,71 +4,71 @@ #### v0.4.1 -* Automatically require 'grape/rabl'. [#39](https://github.com/LTe/grape-rabl/issues/39) [@martinezcoder](https://github.com/martinezcoder) +* Automatically require 'grape/rabl'. [#39](https://github.com/ruby-grape/grape-rabl/issues/39) [@martinezcoder](https://github.com/martinezcoder) #### v0.4.0 -* Make grape-rabl thread-safe. [#37](https://github.com/LTe/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella) +* Make grape-rabl thread-safe. [#37](https://github.com/ruby-grape/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella) #### v0.3.1 -* The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) +* The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/ruby-grape/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) #### v0.3.0 -* Enable using a layout template in Rabl. [@koko1000ban](https://github.com/koko1000ban) [view commit](https://github.com/LTe/grape-rabl/commit/1fbfbd58c3fb320be1b52b3247fda2a23cacc9fc) -* Implemented Rubocop, Ruby style linter. [@dblock](https://github.com/dblock) [view commit](https://github.com/LTe/grape-rabl/commit/1211056de22a5989c063d57b7b37ebb1f1977e83) -* Removed JRuby support. [@dblock](https://github.com/dblock) [view commit](https://github.com/LTe/grape-rabl/commit/59905c1b09670fe08501e09bad4ec8714839f2d3) -* Enable using locals with #render. [@hobofan](https://github.com/hobofan) [view commit](https://github.com/LTe/grape-rabl/commit/6c24130f6a670e52e6119c56904b8ed2e6f60b39) -* Enable support for template caching. [#28](https://github.com/LTe/grape-rabl/pull/28) [@kushkella](https://github.com/kushkella) [view commit](https://github.com/LTe/grape-rabl/commit/79b1e58d767c6286b510af669e718310c0ad25c2) +* Enable using a layout template in Rabl. [@koko1000ban](https://github.com/koko1000ban) [view commit](https://github.com/ruby-grape/grape-rabl/commit/1fbfbd58c3fb320be1b52b3247fda2a23cacc9fc) +* Implemented Rubocop, Ruby style linter. [@dblock](https://github.com/dblock) [view commit](https://github.com/ruby-grape/grape-rabl/commit/1211056de22a5989c063d57b7b37ebb1f1977e83) +* Removed JRuby support. [@dblock](https://github.com/dblock) [view commit](https://github.com/ruby-grape/grape-rabl/commit/59905c1b09670fe08501e09bad4ec8714839f2d3) +* Enable using locals with #render. [@hobofan](https://github.com/hobofan) [view commit](https://github.com/ruby-grape/grape-rabl/commit/6c24130f6a670e52e6119c56904b8ed2e6f60b39) +* Enable support for template caching. [#28](https://github.com/ruby-grape/grape-rabl/pull/28) [@kushkella](https://github.com/kushkella) [view commit](https://github.com/ruby-grape/grape-rabl/commit/79b1e58d767c6286b510af669e718310c0ad25c2) #### v0.2.2 -* Relaxed dependency on a specific version of Grape. [#20](https://github.com/LTe/grape-rabl/pull/20) [@cheef](https://github.com/cheef) [view commit](https://github.com/LTe/grape-rabl/commit/56da0a5bcecb16501cdd93ac25f3b6ca6d7a86f0) +* Relaxed dependency on a specific version of Grape. [#20](https://github.com/ruby-grape/grape-rabl/pull/20) [@cheef](https://github.com/cheef) [view commit](https://github.com/ruby-grape/grape-rabl/commit/56da0a5bcecb16501cdd93ac25f3b6ca6d7a86f0) #### v0.2.1 -* Fix: render template according to request format. [#11](https://github.com/LTe/grape-rabl/pull/11) [@alovak](https://github.com/alovak) [view commit](http://github.com/LTe/grape-rabl/commit/f9658cf7a3026122afbb77e0da613731a5828338) +* Fix: render template according to request format. [#11](https://github.com/ruby-grape/grape-rabl/pull/11) [@alovak](https://github.com/alovak) [view commit](http://github.com/ruby-grape/grape-rabl/commit/f9658cf7a3026122afbb77e0da613731a5828338) #### v0.2.0 -* Allow to use partials in Grape. [#10](https://github.com/LTe/grape-rabl/pull/10) [@ichilton](https://github.com/ichilton) [view commit](http://github.com/LTe/grape-rabl/commit/72c96c5acc9d8000f56ee8400ae0229053fb3e7e) -* Stick to gem conventions. [@LTe](https://github.com/lte) [view commit](http://github.com/LTe/grape-rabl/commit/aabd0e2ad72f56a75427eebcc586deed57cf5f58) -* Update for Grape 0.3 compatibility. [@alovak](https://github.com/alovak) [view commit](http://github.com/LTe/grape-rabl/commit/78bfdceffbfe90b700868ff1e79ab87e8baded81) -* Format fix. [@LTe](https://github.com/lte) [view commit](http://github.com/LTe/grape-rabl/commit/13749cc18d332dcd0050bb32980cc233868a7992) +* Allow to use partials in Grape. [#10](https://github.com/ruby-grape/grape-rabl/pull/10) [@ichilton](https://github.com/ichilton) [view commit](http://github.com/ruby-grape/grape-rabl/commit/72c96c5acc9d8000f56ee8400ae0229053fb3e7e) +* Stick to gem conventions. [@LTe](https://github.com/lte) [view commit](http://github.com/ruby-grape/grape-rabl/commit/aabd0e2ad72f56a75427eebcc586deed57cf5f58) +* Update for Grape 0.3 compatibility. [@alovak](https://github.com/alovak) [view commit](http://github.com/ruby-grape/grape-rabl/commit/78bfdceffbfe90b700868ff1e79ab87e8baded81) +* Format fix. [@LTe](https://github.com/lte) [view commit](http://github.com/ruby-grape/grape-rabl/commit/13749cc18d332dcd0050bb32980cc233868a7992) #### v0.1.0 -* Updated w/ released Grape 0.2.3. [view commit](http://github.com/LTe/grape-rabl/commit/9a055dfd8e13e0952a587de7a2e19c9f762e939c) -* Added link to Rabl. [view commit](http://github.com/LTe/grape-rabl/commit/2a7650cb5f9327761cac8b928453e451a973e131) -* Grape 0.2.x and put back dependency status. [view commit](http://github.com/LTe/grape-rabl/commit/9c1183f3758db8a79737ff35f0c328be646a3f65) -* Grape 0.2.3. [view commit](http://github.com/LTe/grape-rabl/commit/d06a6559a02095e1d84fbbd8df0c3eccdd31930b) -* Updated Grape dependency via .gemspec. [view commit](http://github.com/LTe/grape-rabl/commit/fd44b6a91fa327438eac968fea62ac00ec3ae01f) +* Updated w/ released Grape 0.2.3. [view commit](http://github.com/ruby-grape/grape-rabl/commit/9a055dfd8e13e0952a587de7a2e19c9f762e939c) +* Added link to Rabl. [view commit](http://github.com/ruby-grape/grape-rabl/commit/2a7650cb5f9327761cac8b928453e451a973e131) +* Grape 0.2.x and put back dependency status. [view commit](http://github.com/ruby-grape/grape-rabl/commit/9c1183f3758db8a79737ff35f0c328be646a3f65) +* Grape 0.2.3. [view commit](http://github.com/ruby-grape/grape-rabl/commit/d06a6559a02095e1d84fbbd8df0c3eccdd31930b) +* Updated Grape dependency via .gemspec. [view commit](http://github.com/ruby-grape/grape-rabl/commit/fd44b6a91fa327438eac968fea62ac00ec3ae01f) #### v0.0.6 -* Use Grape formatter syntax instead of monkey-patching. [view commit](http://github.com/LTe/grape-rabl/commit/bfba4c382933fd0f912d9114676b6d79d627c3be) -* Close block code in README. [view commit](http://github.com/LTe/grape-rabl/commit/f397a0de4399d0797b5e327d56234464091d7e3d) -* Change home to user. [view commit](http://github.com/LTe/grape-rabl/commit/45178ec13c613d872c65475b330d20a548459681) +* Use Grape formatter syntax instead of monkey-patching. [view commit](http://github.com/ruby-grape/grape-rabl/commit/bfba4c382933fd0f912d9114676b6d79d627c3be) +* Close block code in README. [view commit](http://github.com/ruby-grape/grape-rabl/commit/f397a0de4399d0797b5e327d56234464091d7e3d) +* Change home to user. [view commit](http://github.com/ruby-grape/grape-rabl/commit/45178ec13c613d872c65475b330d20a548459681) #### v0.0.5 -* Respect default_format for rabl response. [view commit](http://github.com/LTe/grape-rabl/commit/ac54ebbb1d43d1fb76ee9516c5aa683c750c73b0) +* Respect default_format for rabl response. [view commit](http://github.com/ruby-grape/grape-rabl/commit/ac54ebbb1d43d1fb76ee9516c5aa683c750c73b0) #### v0.0.4 -* Require `grape/rabl`. [view commit](http://github.com/LTe/grape-rabl/commit/e99a185b20974f5e72ac3c19ec377a5853780a33) +* Require `grape/rabl`. [view commit](http://github.com/ruby-grape/grape-rabl/commit/e99a185b20974f5e72ac3c19ec377a5853780a33) #### v0.0.3 -* Template without `.rabl`. [view commit](http://github.com/LTe/grape-rabl/commit/cecca03a680f8ae50b406e1b8c170eba27d1bc99) +* Template without `.rabl`. [view commit](http://github.com/ruby-grape/grape-rabl/commit/cecca03a680f8ae50b406e1b8c170eba27d1bc99) #### v0.0.2 -* Add Travis. [view commit](http://github.com/LTe/grape-rabl/commit/71c905bc91066c6fdb628afb555561e23219e213) -* Remove ruby debug. [view commit](http://github.com/LTe/grape-rabl/commit/f80fad14a49b14ae7264b08eff12832c37cbd0b2) -* Works with rubinius. [view commit](http://github.com/LTe/grape-rabl/commit/fceece344de095916ded7c477bb5891537bb8663) -* Add dependency status. [view commit](http://github.com/LTe/grape-rabl/commit/66820fb52155c65d4cd9bd7b67f0f22c1105fa46) +* Add Travis. [view commit](http://github.com/ruby-grape/grape-rabl/commit/71c905bc91066c6fdb628afb555561e23219e213) +* Remove ruby debug. [view commit](http://github.com/ruby-grape/grape-rabl/commit/f80fad14a49b14ae7264b08eff12832c37cbd0b2) +* Works with rubinius. [view commit](http://github.com/ruby-grape/grape-rabl/commit/fceece344de095916ded7c477bb5891537bb8663) +* Add dependency status. [view commit](http://github.com/ruby-grape/grape-rabl/commit/66820fb52155c65d4cd9bd7b67f0f22c1105fa46) #### v0.0.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..97d0466 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,118 @@ +Contributing to Grape-Rabl +========================== + +Grape-Rabl is work of [many of contributors](https://github.com/ruby-grape/grape-rabl/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/ruby-grape/grape-rabl/pulls), [propose features and discuss issues](https://github.com/ruby-grape/grape-rabl/issues). When in doubt, ask a question in the [Grape Google Group](http://groups.google.com/group/ruby-grape). + +#### Fork the Project + +Fork the [project on Github](https://github.com/ruby-grape/grape-rabl) and check out your copy. + +``` +git clone https://github.com/contributor/grape-rabl.git +cd grape-rabl +git remote add upstream https://github.com/ruby-grape/grape-rabl.git +``` + +#### Create a Topic Branch + +Make sure your fork is up-to-date and create a topic branch for your feature or bug fix. + +``` +git checkout master +git pull upstream master +git checkout -b my-feature-branch +``` + +#### Bundle Install and Test + +Ensure that you can build the project and run tests. + +``` +bundle install +bundle exec rake +``` + +#### Write Tests + +Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/grape-rabl](spec/grape-rabl). + +We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix. + +#### Write Code + +Implement your feature or bug fix. + +Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted. + +Make sure that `bundle exec rake` completes without errors. + +#### Write Documentation + +Document any external behavior in the [README](README.md). + +#### Update Changelog + +Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account. + +#### Commit Changes + +Make sure git knows your name and email address: + +``` +git config --global user.name "Your Name" +git config --global user.email "contributor@example.com" +``` + +Writing good commit logs is important. A commit log should describe what changed and why. + +``` +git add ... +git commit +``` + +#### Push + +``` +git push origin my-feature-branch +``` + +#### Make a Pull Request + +Go to https://github.com/contributor/grape-rabl and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days. + +#### Rebase + +If you've been working on a change for a while, rebase with upstream/master. + +``` +git fetch upstream +git rebase upstream/master +git push origin my-feature-branch -f +``` + +#### Update CHANGELOG Again + +Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows. + +``` +* [#123](https://github.com/ruby-grape/grape-rabl/pull/123): Reticulated splines - [@contributor](https://github.com/contributor). +``` + +Amend your previous commit and force push the changes. + +``` +git commit --amend +git push origin my-feature-branch -f +``` + +#### Check on Your Pull Request + +Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above. + +#### Be Patient + +It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there! + +#### Thank You + +Please do know that we really appreciate and value your time and work. We love you, really. diff --git a/README.md b/README.md index 75ab7ea..cf4b68b 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github.com/intridea/grape)! [![Gem Version](http://img.shields.io/gem/v/grape-rabl.svg)](http://badge.fury.io/rb/grape-rabl) -[![Build Status](http://img.shields.io/travis/LTe/grape-rabl.svg)](https://travis-ci.org/LTe/grape-rabl) -[![Dependency Status](https://gemnasium.com/LTe/grape-rabl.svg)](https://gemnasium.com/LTe/grape-rabl) -[![Code Climate](https://codeclimate.com/github/LTe/grape-rabl.svg)](https://codeclimate.com/github/LTe/grape-rabl) -[![Coverage Status](https://img.shields.io/coveralls/LTe/grape-rabl.svg)](https://coveralls.io/r/LTe/grape-rabl?branch=master) +[![Build Status](http://img.shields.io/travis/ruby-grape/grape-rabl.svg)](https://travis-ci.org/ruby-grape/grape-rabl) +[![Dependency Status](https://gemnasium.com/ruby-grape/grape-rabl.svg)](https://gemnasium.com/ruby-grape/grape-rabl) +[![Code Climate](https://codeclimate.com/github/ruby-grape/grape-rabl.svg)](https://codeclimate.com/github/ruby-grape/grape-rabl) +[![Coverage Status](https://img.shields.io/coveralls/ruby-grape/grape-rabl.svg)](https://coveralls.io/r/ruby-grape/grape-rabl?branch=master) ## Installation @@ -204,5 +204,5 @@ Enjoy :) 5. Create new Pull Request -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/LTe/grape-rabl/trend.png)](https://bitdeli.com/free "Bitdeli Badge") +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ruby-grape/grape-rabl/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/grape-rabl.gemspec b/grape-rabl.gemspec index cbf120d..a9a723a 100644 --- a/grape-rabl.gemspec +++ b/grape-rabl.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |gem| gem.email = ["piotr.nielacny@gmail.com"] gem.description = %q{Use rabl in grape} gem.summary = %q{Use rabl in grape} - gem.homepage = "https://github.com/LTe/grape-rabl" + gem.homepage = "https://github.com/ruby-grape/grape-rabl" gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.files = `git ls-files`.split("\n") From 9ff2f9ddf9540c4c3692914aa7c65294462f0307 Mon Sep 17 00:00:00 2001 From: Gonzalo HQ063 Date: Thu, 10 Sep 2015 23:17:44 -0300 Subject: [PATCH 13/29] Fix a typo on readme documentation Change "Gape-rabl" for "Grape-rabl" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf4b68b..908b096 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ end ### Enable template caching -Gape-rabl allows for template caching after templates are loaded initially. +Grape-rabl allows for template caching after templates are loaded initially. You can enable template caching: From c0eb0e3174c594cd276f0850a95a18937d23c70e Mon Sep 17 00:00:00 2001 From: Kush Kella Date: Tue, 7 Jun 2016 15:05:15 -0700 Subject: [PATCH 14/29] use tilt_options and path as cache key for templates --- .travis.yml | 4 ++-- CHANGELOG.md | 1 + lib/grape-rabl/formatter.rb | 8 ++++++-- spec/grape_rabl_spec.rb | 25 +++++++++++++++++++++++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index b492663..54e90a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ rvm: - - 1.9.3 - 2.0.0 - 2.1.0 - ruby-head - jruby-19mode - jruby-head - - rbx-2.2.10 + - rbx-2 matrix: allow_failures: - rvm: jruby-19mode - rvm: jruby-head - rvm: ruby-head + - rvm: rbx-2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3692326..916b8a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ #### Next +* Fix template caching for multiple formats. [#43](https://github.com/ruby-grape/grape-rabl/pull/43) [@kushkella](https://github.com/kushkella) * Your contribution here. #### v0.4.1 diff --git a/lib/grape-rabl/formatter.rb b/lib/grape-rabl/formatter.rb index eca5624..a461a26 100644 --- a/lib/grape-rabl/formatter.rb +++ b/lib/grape-rabl/formatter.rb @@ -67,7 +67,7 @@ def set_view_root def tilt_template(template) if Grape::Rabl.configuration.cache_template_loading - Grape::Rabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) } + Grape::Rabl::Formatter.tilt_cache.fetch(tilt_cache_key(template)) { ::Tilt.new(view_path(template), tilt_options) } else ::Tilt.new(view_path(template), tilt_options) end @@ -80,11 +80,15 @@ def tilt_options def layout_template layout_path = view_path(env['api.tilt.layout'] || 'layouts/application') if Grape::Rabl.configuration.cache_template_loading - Grape::Rabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) } + Grape::Rabl::Formatter.tilt_cache.fetch(tilt_cache_key(layout_path)) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) } else ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) end end + + def tilt_cache_key(path) + Digest::MD5.hexdigest("#{path}#{tilt_options}") + end end end end diff --git a/spec/grape_rabl_spec.rb b/spec/grape_rabl_spec.rb index 86e2f26..0044c40 100644 --- a/spec/grape_rabl_spec.rb +++ b/spec/grape_rabl_spec.rb @@ -6,8 +6,9 @@ end before do - subject.format :json + subject.default_format :json subject.formatter :json, Grape::Formatter::Rabl + subject.formatter :xml, Grape::Formatter::Rabl subject.helpers MyHelper end @@ -166,7 +167,27 @@ def app old_response.should == new_response end - it 'should serve new template if cache_template_loading' do + it 'should maintain different cached templates for different formats' do + Grape::Rabl.configure do |config| + config.cache_template_loading = true + end + get '/home' + last_response.status.should be == 200 + json_response = last_response.body + get '/home.xml' + last_response.status.should be == 200 + xml_response = last_response.body + json_response.should_not be == xml_response + open(@template, 'a') { |f| f << 'node(:test) { "test" }' } + get '/home.xml' + last_response.status.should be == 200 + last_response.body.should be == xml_response + get '/home.json' + last_response.status.should be == 200 + last_response.body.should be == json_response + end + + it 'should serve new template unless cache_template_loading' do get '/home' last_response.status.should be == 200 old_response = last_response.body From aa1a0cf6147170c7d3ca53afe45a2f601d89e767 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 8 Jun 2016 16:02:19 -0400 Subject: [PATCH 15/29] Upgraded RSpec and RuboCop. --- .rubocop.yml | 30 +---------------- .rubocop_todo.yml | 50 +++++++++++++++++++++++++++ Gemfile | 16 ++++----- Rakefile | 4 +-- grape-rabl.gemspec | 22 ++++++------ lib/grape-rabl.rb | 2 +- lib/grape-rabl/formatter.rb | 4 +-- lib/grape-rabl/version.rb | 2 +- spec/grape_rabl_configuration.rb | 6 ++-- spec/grape_rabl_layout_spec.rb | 26 +++++++------- spec/grape_rabl_partials_spec.rb | 5 +-- spec/grape_rabl_spec.rb | 58 ++++++++++++++++---------------- spec/grape_rabl_xml_spec.rb | 8 ++--- spec/spec_helper.rb | 1 + 14 files changed, 130 insertions(+), 104 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index a80d52c..01732de 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,32 +3,4 @@ AllCops: - vendor/** - .bundle -LineLength: - Enabled: false - -MethodLength: - Enabled: false - -ClassLength: - Enabled: false - -Documentation: - # don't require classes to be documented - Enabled: false - -Encoding: - # no need to always specify encoding - Enabled: false - -CollectionMethods: - # don't prefer map to collect, recuce to inject - Enabled: false - -RescueException: - Enabled: false - -DoubleNegation: - Enabled: false - -FileName: - Enabled: false +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..52bc357 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,50 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-06-08 16:00:13 -0400 using RuboCop version 0.40.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +Lint/RescueException: + Exclude: + - 'spec/grape_rabl_spec.rb' + +# Offense count: 21 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# URISchemes: http, https +Metrics/LineLength: + Max: 148 + +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 13 + +# Offense count: 5 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/grape-rabl.rb' + - 'lib/grape-rabl/configuration.rb' + - 'lib/grape-rabl/formatter.rb' + - 'lib/grape-rabl/render.rb' + - 'lib/grape/rabl.rb' + +# Offense count: 1 +Style/DoubleNegation: + Exclude: + - 'lib/grape-rabl/formatter.rb' + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts. +Style/FileName: + Exclude: + - 'lib/grape-rabl.rb' + +# Offense count: 1 +Style/IfInsideElse: + Exclude: + - 'lib/grape-rabl/formatter.rb' diff --git a/Gemfile b/Gemfile index 5fb1c79..e19988a 100644 --- a/Gemfile +++ b/Gemfile @@ -3,18 +3,18 @@ source 'https://rubygems.org' gemspec group :development do - gem "rubocop", "0.20.1" + gem 'rubocop', '0.40.0' end group :test do - gem "json", '~> 1.7.7' - gem "rspec", "~> 2.12.0" - gem "rack-test" - gem "rake" - gem "coveralls", require: false - gem "rabl", :github => "nesquena/rabl" + gem 'json' + gem 'rspec' + gem 'rack-test' + gem 'rake' + gem 'coveralls', require: false + gem 'rabl' platforms :rbx do - gem "iconv" + gem 'iconv' end end diff --git a/Rakefile b/Rakefile index ce4b18c..a0298c6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ #!/usr/bin/env rake -require "bundler/gem_tasks" +require 'bundler/gem_tasks' require 'rspec/core' require 'rspec/core/rake_task' @@ -9,6 +9,6 @@ RSpec::Core::RakeTask.new(:spec) do |spec| end require 'rubocop/rake_task' -Rubocop::RakeTask.new(:rubocop) +RuboCop::RakeTask.new(:rubocop) task default: [:rubocop, :spec] diff --git a/grape-rabl.gemspec b/grape-rabl.gemspec index a9a723a..a1d5cfa 100644 --- a/grape-rabl.gemspec +++ b/grape-rabl.gemspec @@ -3,21 +3,21 @@ require File.expand_path('../lib/grape-rabl/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Piotr Niełacny"] - gem.email = ["piotr.nielacny@gmail.com"] - gem.description = %q{Use rabl in grape} - gem.summary = %q{Use rabl in grape} - gem.homepage = "https://github.com/ruby-grape/grape-rabl" + gem.email = ['piotr.nielacny@gmail.com'] + gem.description = 'Use rabl in grape' + gem.summary = 'Use rabl in grape' + gem.homepage = 'https://github.com/ruby-grape/grape-rabl' - gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - gem.name = "grape-rabl" - gem.require_paths = ["lib"] + gem.name = 'grape-rabl' + gem.require_paths = ['lib'] gem.version = Grape::Rabl::VERSION gem.required_ruby_version = '>= 1.9.3' - gem.add_dependency "grape" - gem.add_dependency "rabl" - gem.add_dependency "tilt" - gem.add_dependency "i18n" + gem.add_dependency 'grape' + gem.add_dependency 'rabl' + gem.add_dependency 'tilt' + gem.add_dependency 'i18n' end diff --git a/lib/grape-rabl.rb b/lib/grape-rabl.rb index 584f408..8b95a6f 100644 --- a/lib/grape-rabl.rb +++ b/lib/grape-rabl.rb @@ -11,7 +11,7 @@ module Grape module Rabl class << self - def configure(&block) + def configure yield(configuration) configuration end diff --git a/lib/grape-rabl/formatter.rb b/lib/grape-rabl/formatter.rb index a461a26..2257214 100644 --- a/lib/grape-rabl/formatter.rb +++ b/lib/grape-rabl/formatter.rb @@ -48,7 +48,7 @@ def rablable? end def rabl - fail 'missing rabl template' unless rabl_template + raise 'missing rabl template' unless rabl_template set_view_root unless env['api.tilt.root'] yield rabl_template end @@ -62,7 +62,7 @@ def rabl_template end def set_view_root - fail "Use Rack::Config to set 'api.tilt.root' in config.ru" + raise "Use Rack::Config to set 'api.tilt.root' in config.ru" end def tilt_template(template) diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index d534d97..047715b 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.4.2' + VERSION = '0.4.2'.freeze end end diff --git a/spec/grape_rabl_configuration.rb b/spec/grape_rabl_configuration.rb index 41a7f49..db58120 100644 --- a/spec/grape_rabl_configuration.rb +++ b/spec/grape_rabl_configuration.rb @@ -3,16 +3,16 @@ describe 'Grape::Rabl configuration' do context 'configuration' do it 'returns default values' do - Grape::Rabl.configuration.cache_template_loading.should == false + expect(Grape::Rabl.configuration.cache_template_loading).to eq(false) end it 'should set and reset configuration' do Grape::Rabl.configure do |config| config.cache_template_loading = true end - Grape::Rabl.configuration.cache_template_loading.should be == true + expect(Grape::Rabl.configuration.cache_template_loading).to eq(true) Grape::Rabl.reset_configuration! - Grape::Rabl.configuration.cache_template_loading.should == false + expect(Grape::Rabl.configuration.cache_template_loading).to eq(false) end end end diff --git a/spec/grape_rabl_layout_spec.rb b/spec/grape_rabl_layout_spec.rb index 1f55af8..6ec7fc3 100644 --- a/spec/grape_rabl_layout_spec.rb +++ b/spec/grape_rabl_layout_spec.rb @@ -28,8 +28,9 @@ def app end get('/about') - parsed_response.should == - JSON.parse(%Q({"status":200,"result":{"user":{"name":"LTe","project":{"name":"First"}}}})) + expect(parsed_response).to eq( + JSON.parse(%({"status":200,"result":{"user":{"name":"LTe","project":{"name":"First"}}}})) + ) end end @@ -47,17 +48,18 @@ def app get('/about') puts last_response.body - parsed_response.should == - JSON.parse(%Q({"result":{"user":{"name":"LTe","project":{"name":"First"}}}})) + expect(parsed_response).to eq( + JSON.parse(%({"result":{"user":{"name":"LTe","project":{"name":"First"}}}})) + ) end end context 'layout cache' do before do - @views_dir = FileUtils.mkdir_p("#{File.expand_path("..", File.dirname(__FILE__))}/tmp")[0] + @views_dir = FileUtils.mkdir_p("#{File.expand_path('..', File.dirname(__FILE__))}/tmp")[0] @layout = "#{@views_dir}/layouts/application.rabl" FileUtils.cp_r("#{File.dirname(__FILE__)}/views/layout_test/.", @views_dir) - subject.before { env['api.tilt.root'] = "#{File.expand_path("..", File.dirname(__FILE__))}/tmp" } + subject.before { env['api.tilt.root'] = "#{File.expand_path('..', File.dirname(__FILE__))}/tmp" } subject.get('/home', rabl: 'user') do @user = OpenStruct.new(name: 'LTe', email: 'email@example.com') @project = OpenStruct.new(name: 'First') @@ -75,24 +77,24 @@ def app config.cache_template_loading = true end get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) old_response = last_response.body open(@layout, 'a') { |f| f << 'node(:test) { "test" }' } get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) new_response = last_response.body - old_response.should == new_response + expect(old_response).to eq(new_response) end it 'should serve new template if cache_template_loading' do get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) old_response = last_response.body open(@layout, 'a') { |f| f << 'node(:test) { "test" }' } get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) new_response = last_response.body - old_response.should_not == new_response + expect(old_response).not_to eq(new_response) end end end diff --git a/spec/grape_rabl_partials_spec.rb b/spec/grape_rabl_partials_spec.rb index fcea707..ea40d96 100644 --- a/spec/grape_rabl_partials_spec.rb +++ b/spec/grape_rabl_partials_spec.rb @@ -25,7 +25,8 @@ def app end get('/home') - parsed_response.should == - JSON.parse("{\"project\":{\"name\":\"First\",\"info\":{\"type\":\"paper\"},\"author\":{\"author\":\"LTe\"}}}") + expect(parsed_response).to eq( + JSON.parse('{"project":{"name":"First","info":{"type":"paper"},"author":{"author":"LTe"}}}') + ) end end diff --git a/spec/grape_rabl_spec.rb b/spec/grape_rabl_spec.rb index 0044c40..601506d 100644 --- a/spec/grape_rabl_spec.rb +++ b/spec/grape_rabl_spec.rb @@ -19,7 +19,7 @@ def app it 'should work without rabl template' do subject.get('/home') { 'Hello World' } get '/home' - last_response.body.should == "\"Hello World\"" + expect(last_response.body).to eq('"Hello World"') end it 'should raise error about root directory' do @@ -27,11 +27,11 @@ def app subject.get('/home', rabl: true) {} get '/home' rescue Exception => e - e.message.should include "Use Rack::Config to set 'api.tilt.root' in config.ru" + expect(e.message).to include "Use Rack::Config to set 'api.tilt.root' in config.ru" end end - context 'titl root is setup' do + context 'titl root is setup' do let(:parsed_response) { JSON.parse(last_response.body) } before do @@ -42,7 +42,7 @@ def app it 'should execute helper' do subject.get('/home', rabl: 'helper') { @user = OpenStruct.new } get '/home' - parsed_response.should == JSON.parse("{\"user\":{\"helper\":\"my_helper\"}}") + expect(parsed_response).to eq(JSON.parse('{"user":{"helper":"my_helper"}}')) end end @@ -76,33 +76,33 @@ def app it 'renders template passed as argument to render method' do get('/home') - parsed_response.should == JSON.parse('{"admin":{"name":"LTe"}}') + expect(parsed_response).to eq(JSON.parse('{"admin":{"name":"LTe"}}')) end it 'renders admin template' do get('/admin/1') - parsed_response.should == JSON.parse('{"admin":{"name":"LTe"}}') + expect(parsed_response).to eq(JSON.parse('{"admin":{"name":"LTe"}}')) end it 'renders user template' do get('/admin/2') - parsed_response.should == JSON.parse('{"user":{"name":"LTe","project":null}}') + expect(parsed_response).to eq(JSON.parse('{"user":{"name":"LTe","project":null}}')) end it 'renders template passed as argument to render method with locals' do get('/home-detail') - parsed_response.should == JSON.parse('{"admin":{"name":"LTe","details":"amazing detail"}}') + expect(parsed_response).to eq(JSON.parse('{"admin":{"name":"LTe","details":"amazing detail"}}')) end it 'renders with locals without overriding template' do get('/about-detail') - parsed_response.should == JSON.parse('{"user":{"name":"LTe","details":"just a user","project":null}}') + expect(parsed_response).to eq(JSON.parse('{"user":{"name":"LTe","details":"just a user","project":null}}')) end it 'does not save rabl options after called #render method' do get('/home') get('/about') - parsed_response.should == JSON.parse('{"user":{"name":"LTe","project":null}}') + expect(parsed_response).to eq(JSON.parse('{"user":{"name":"LTe","project":null}}')) end it 'does not modify endpoint options' do @@ -114,14 +114,14 @@ def app it 'should respond with proper content-type' do subject.get('/home', rabl: 'user') {} get('/home') - last_response.headers['Content-Type'].should == 'application/json' + expect(last_response.headers['Content-Type']).to eq('application/json') end it 'should not raise error about root directory' do subject.get('/home', rabl: 'user') {} get '/home' - last_response.status.should eq 200 - last_response.body.should_not include "Use Rack::Config to set 'api.tilt.root' in config.ru" + expect(last_response.status).to eq 200 + expect(last_response.body).not_to include "Use Rack::Config to set 'api.tilt.root' in config.ru" end ['user', 'user.rabl'].each do |rabl_option| @@ -132,16 +132,16 @@ def app end get '/home' - parsed_response.should == JSON.parse('{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}') + expect(parsed_response).to eq(JSON.parse('{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}')) end end describe 'template cache' do before do - @views_dir = FileUtils.mkdir_p("#{File.expand_path("..", File.dirname(__FILE__))}/tmp")[0] + @views_dir = FileUtils.mkdir_p("#{File.expand_path('..', File.dirname(__FILE__))}/tmp")[0] @template = "#{@views_dir}/user.rabl" FileUtils.cp("#{File.dirname(__FILE__)}/views/user.rabl", @template) - subject.before { env['api.tilt.root'] = "#{File.expand_path("..", File.dirname(__FILE__))}/tmp" } + subject.before { env['api.tilt.root'] = "#{File.expand_path('..', File.dirname(__FILE__))}/tmp" } subject.get('/home', rabl: 'user') do @user = OpenStruct.new(name: 'LTe', email: 'email@example.com') @project = OpenStruct.new(name: 'First') @@ -158,13 +158,13 @@ def app config.cache_template_loading = true end get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) old_response = last_response.body open(@template, 'a') { |f| f << 'node(:test) { "test" }' } get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) new_response = last_response.body - old_response.should == new_response + expect(old_response).to eq(new_response) end it 'should maintain different cached templates for different formats' do @@ -172,30 +172,30 @@ def app config.cache_template_loading = true end get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) json_response = last_response.body get '/home.xml' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) xml_response = last_response.body - json_response.should_not be == xml_response + expect(json_response).not_to eq(xml_response) open(@template, 'a') { |f| f << 'node(:test) { "test" }' } get '/home.xml' - last_response.status.should be == 200 - last_response.body.should be == xml_response + expect(last_response.status).to eq(200) + expect(last_response.body).to eq(xml_response) get '/home.json' - last_response.status.should be == 200 - last_response.body.should be == json_response + expect(last_response.status).to eq(200) + expect(last_response.body).to eq(json_response) end it 'should serve new template unless cache_template_loading' do get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) old_response = last_response.body open(@template, 'a') { |f| f << 'node(:test) { "test" }' } get '/home' - last_response.status.should be == 200 + expect(last_response.status).to eq(200) new_response = last_response.body - old_response.should_not == new_response + expect(old_response).not_to eq(new_response) end end end diff --git a/spec/grape_rabl_xml_spec.rb b/spec/grape_rabl_xml_spec.rb index 788905e..2ee2394 100644 --- a/spec/grape_rabl_xml_spec.rb +++ b/spec/grape_rabl_xml_spec.rb @@ -14,7 +14,7 @@ def app subject end - context 'with xml format' do + context 'with xml format' do before do subject.before do env['api.tilt.root'] = "#{File.dirname(__FILE__)}/views" @@ -25,7 +25,7 @@ def app it 'should respond with proper content-type' do subject.get('/home', rabl: 'user') {} get('/home') - last_response.headers['Content-Type'].should == 'application/xml' + expect(last_response.headers['Content-Type']).to eq('application/xml') end ['user', 'user.rabl'].each do |rabl_option| @@ -37,7 +37,7 @@ def app get '/home' - last_response.body.should == %Q( + expect(last_response.body).to eq(%( LTe email@example.com @@ -45,7 +45,7 @@ def app First -) +)) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69f15f..9e20682 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,7 @@ RSpec.configure do |config| config.include Rack::Test::Methods + config.raise_errors_for_deprecations! end Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } From 55d9e42b23a0553f7268617b0722e4b7df4388df Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 8 Jun 2016 17:04:57 -0400 Subject: [PATCH 16/29] Preparing for release, 0.4.2. --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916b8a2..01ec226 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ -#### Next +#### v0.4.2 * Fix template caching for multiple formats. [#43](https://github.com/ruby-grape/grape-rabl/pull/43) [@kushkella](https://github.com/kushkella) -* Your contribution here. #### v0.4.1 From f94eb4842eebcacc76d48de9f26ecaa4b879ca34 Mon Sep 17 00:00:00 2001 From: dblock Date: Wed, 8 Jun 2016 17:05:44 -0400 Subject: [PATCH 17/29] Preparing for next development iteration, 0.4.3. --- CHANGELOG.md | 4 ++++ lib/grape-rabl/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01ec226..bf96d7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Next + +* Your contribution here. + #### v0.4.2 * Fix template caching for multiple formats. [#43](https://github.com/ruby-grape/grape-rabl/pull/43) [@kushkella](https://github.com/kushkella) diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index 047715b..0f7afb7 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.4.2'.freeze + VERSION = '0.4.3'.freeze end end From 6b65bef3a8640b9d67070bba06bdf9d2913c2cf1 Mon Sep 17 00:00:00 2001 From: Tomohiro Suwa Date: Wed, 5 Jul 2017 18:36:10 +0900 Subject: [PATCH 18/29] Don't require hashie --- .travis.yml | 5 +++-- grape-rabl.gemspec | 2 +- lib/grape-rabl.rb | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54e90a8..8b03a5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ +before_install: gem install bundler -v '1.15.0' rvm: - - 2.0.0 - - 2.1.0 + - 2.2.0 + - 2.3.0 - ruby-head - jruby-19mode - jruby-head diff --git a/grape-rabl.gemspec b/grape-rabl.gemspec index a1d5cfa..d394d57 100644 --- a/grape-rabl.gemspec +++ b/grape-rabl.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| gem.name = 'grape-rabl' gem.require_paths = ['lib'] gem.version = Grape::Rabl::VERSION - gem.required_ruby_version = '>= 1.9.3' + gem.required_ruby_version = '>= 2.2.0' gem.add_dependency 'grape' gem.add_dependency 'rabl' diff --git a/lib/grape-rabl.rb b/lib/grape-rabl.rb index 8b95a6f..5b56ea1 100644 --- a/lib/grape-rabl.rb +++ b/lib/grape-rabl.rb @@ -1,6 +1,5 @@ require 'rabl' require 'grape' -require 'hashie/hash' require 'grape/rabl' require 'grape-rabl/tilt' require 'grape-rabl/version' From 6d80eeaac9295cf8ffeece19a5c80057f1c54ef1 Mon Sep 17 00:00:00 2001 From: Tomohiro Suwa Date: Thu, 6 Jul 2017 12:46:06 +0900 Subject: [PATCH 19/29] Update the CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf96d7a..fa0169b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ #### Next -* Your contribution here. +* Don't require unused hashie and drop support of Ruby 2.0, 2.1 #### v0.4.2 From 45e82f6504711aef2f53635d7fbb73ac47ed5201 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 6 Jul 2017 17:40:20 -0400 Subject: [PATCH 20/29] Added Danger, PR linter. --- .travis.yml | 10 ++++---- CHANGELOG.md | 68 +++++++++++++++++++++++++++------------------------- Dangerfile | 1 + Gemfile | 5 +--- 4 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 Dangerfile diff --git a/.travis.yml b/.travis.yml index 8b03a5d..d052915 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,11 @@ rvm: - 2.2.0 - 2.3.0 - ruby-head - - jruby-19mode - - jruby-head - - rbx-2 matrix: + include: + - rvm: 2.3.1 + script: + - bundle exec danger allow_failures: - - rvm: jruby-19mode - - rvm: jruby-head - rvm: ruby-head - - rvm: rbx-2 diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0169b..86e43a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,79 +1,83 @@ #### Next -* Don't require unused hashie and drop support of Ruby 2.0, 2.1 +* [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Don't require unused hashie - [@tsuwatch](https://github.com/tsuwatch). +* [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Support Ruby >= 2.2 - [@tsuwatch](https://github.com/tsuwatch). +* [#45](https://github.com/ruby-grape/grape-rabl/pull/45): Added danger, PR linter - [@dblock](https://github.com/dblock). +* Your contribution here. #### v0.4.2 -* Fix template caching for multiple formats. [#43](https://github.com/ruby-grape/grape-rabl/pull/43) [@kushkella](https://github.com/kushkella) +* [#43](https://github.com/ruby-grape/grape-rabl/pull/43): Fix template caching for multiple formats - [@kushkella](https://github.com/kushkella). #### v0.4.1 -* Automatically require 'grape/rabl'. [#39](https://github.com/ruby-grape/grape-rabl/issues/39) [@martinezcoder](https://github.com/martinezcoder) +* [#39](https://github.com/ruby-grape/grape-rabl/issues/39): Automatically require 'grape/rabl' - [@martinezcoder](https://github.com/martinezcoder). #### v0.4.0 -* Make grape-rabl thread-safe. [#37](https://github.com/ruby-grape/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella) +* [#37](https://github.com/ruby-grape/grape-rabl/issues/37): Make grape-rabl thread-safe - [@kushkella](https://github.com/kushkella). #### v0.3.1 -* The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/ruby-grape/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck) +* [#35](https://github.com/ruby-grape/grape-rabl/issues/35): The `render` method will no longer modify endpoint options at runtime - [@yesmeck](https://github.com/yesmeck). #### v0.3.0 -* Enable using a layout template in Rabl. [@koko1000ban](https://github.com/koko1000ban) [view commit](https://github.com/ruby-grape/grape-rabl/commit/1fbfbd58c3fb320be1b52b3247fda2a23cacc9fc) -* Implemented Rubocop, Ruby style linter. [@dblock](https://github.com/dblock) [view commit](https://github.com/ruby-grape/grape-rabl/commit/1211056de22a5989c063d57b7b37ebb1f1977e83) -* Removed JRuby support. [@dblock](https://github.com/dblock) [view commit](https://github.com/ruby-grape/grape-rabl/commit/59905c1b09670fe08501e09bad4ec8714839f2d3) -* Enable using locals with #render. [@hobofan](https://github.com/hobofan) [view commit](https://github.com/ruby-grape/grape-rabl/commit/6c24130f6a670e52e6119c56904b8ed2e6f60b39) -* Enable support for template caching. [#28](https://github.com/ruby-grape/grape-rabl/pull/28) [@kushkella](https://github.com/kushkella) [view commit](https://github.com/ruby-grape/grape-rabl/commit/79b1e58d767c6286b510af669e718310c0ad25c2) +* [#22](https://github.com/ruby-grape/grape-rabl/pull/22): Enable using a layout template in Rabl - [@koko1000ban](https://github.com/koko1000ban). +* Implemented Rubocop, Ruby style linter - [@dblock](https://github.com/dblock). +* Removed JRuby support - [@dblock](https://github.com/dblock). +* Enable using locals with `.render` - [@hobofan](https://github.com/hobofan). +* Enable support for template caching - [@kushkella](https://github.com/kushkella). + #### v0.2.2 -* Relaxed dependency on a specific version of Grape. [#20](https://github.com/ruby-grape/grape-rabl/pull/20) [@cheef](https://github.com/cheef) [view commit](https://github.com/ruby-grape/grape-rabl/commit/56da0a5bcecb16501cdd93ac25f3b6ca6d7a86f0) +* [#20](https://github.com/ruby-grape/grape-rabl/pull/20): Relaxed dependency on a specific version of Grape - [@cheef](https://github.com/cheef). #### v0.2.1 -* Fix: render template according to request format. [#11](https://github.com/ruby-grape/grape-rabl/pull/11) [@alovak](https://github.com/alovak) [view commit](http://github.com/ruby-grape/grape-rabl/commit/f9658cf7a3026122afbb77e0da613731a5828338) +* [#11](https://github.com/ruby-grape/grape-rabl/pull/11): Fix: render template according to request format - [@alovak](https://github.com/alovak). #### v0.2.0 -* Allow to use partials in Grape. [#10](https://github.com/ruby-grape/grape-rabl/pull/10) [@ichilton](https://github.com/ichilton) [view commit](http://github.com/ruby-grape/grape-rabl/commit/72c96c5acc9d8000f56ee8400ae0229053fb3e7e) -* Stick to gem conventions. [@LTe](https://github.com/lte) [view commit](http://github.com/ruby-grape/grape-rabl/commit/aabd0e2ad72f56a75427eebcc586deed57cf5f58) -* Update for Grape 0.3 compatibility. [@alovak](https://github.com/alovak) [view commit](http://github.com/ruby-grape/grape-rabl/commit/78bfdceffbfe90b700868ff1e79ab87e8baded81) -* Format fix. [@LTe](https://github.com/lte) [view commit](http://github.com/ruby-grape/grape-rabl/commit/13749cc18d332dcd0050bb32980cc233868a7992) +* [#10](https://github.com/ruby-grape/grape-rabl/pull/10): Allow to use partials in Grape - [@ichilton](https://github.com/ichilton). +* Stick to gem conventions - [@LTe](https://github.com/lte). +* [#13](https://github.com/ruby-grape/grape-rabl/pull/13): Update for Grape 0.3 compatibility - [@alovak](https://github.com/alovak). +* Format fix - [@LTe](https://github.com/LTe). #### v0.1.0 -* Updated w/ released Grape 0.2.3. [view commit](http://github.com/ruby-grape/grape-rabl/commit/9a055dfd8e13e0952a587de7a2e19c9f762e939c) -* Added link to Rabl. [view commit](http://github.com/ruby-grape/grape-rabl/commit/2a7650cb5f9327761cac8b928453e451a973e131) -* Grape 0.2.x and put back dependency status. [view commit](http://github.com/ruby-grape/grape-rabl/commit/9c1183f3758db8a79737ff35f0c328be646a3f65) -* Grape 0.2.3. [view commit](http://github.com/ruby-grape/grape-rabl/commit/d06a6559a02095e1d84fbbd8df0c3eccdd31930b) -* Updated Grape dependency via .gemspec. [view commit](http://github.com/ruby-grape/grape-rabl/commit/fd44b6a91fa327438eac968fea62ac00ec3ae01f) +* Updated w/released Grape 0.2.3 - [@dblock](https://github.com/dblock). +* Added link to Rabl - [@dblock](https://github.com/dblock). +* Grape 0.2.x and put back dependency status - [@dblock](https://github.com/dblock). +* Grape 0.2.3 - [@dblock](https://github.com/dblock). +* Updated Grape dependency via .gemspec - [@dblock](https://github.com/dblock). #### v0.0.6 -* Use Grape formatter syntax instead of monkey-patching. [view commit](http://github.com/ruby-grape/grape-rabl/commit/bfba4c382933fd0f912d9114676b6d79d627c3be) -* Close block code in README. [view commit](http://github.com/ruby-grape/grape-rabl/commit/f397a0de4399d0797b5e327d56234464091d7e3d) -* Change home to user. [view commit](http://github.com/ruby-grape/grape-rabl/commit/45178ec13c613d872c65475b330d20a548459681) +* [#6](https://github.com/ruby-grape/grape-rabl/pull/6): Use Grape formatter syntax instead of monkey-patching - [@dblock](https://github.com/dblock). +* Close block code in README - [@LTe](https://github.com/LTe). +* Change home to user - [@LTe](https://github.com/LTe). #### v0.0.5 -* Respect default_format for rabl response. [view commit](http://github.com/ruby-grape/grape-rabl/commit/ac54ebbb1d43d1fb76ee9516c5aa683c750c73b0) +* Respect `default_format` for rabl response - [@LTe](https://github.com/LTe). #### v0.0.4 -* Require `grape/rabl`. [view commit](http://github.com/ruby-grape/grape-rabl/commit/e99a185b20974f5e72ac3c19ec377a5853780a33) +* Require `grape/rabl` - [@LTe](https://github.com/LTe). #### v0.0.3 -* Template without `.rabl`. [view commit](http://github.com/ruby-grape/grape-rabl/commit/cecca03a680f8ae50b406e1b8c170eba27d1bc99) +* Template without `.rabl` - [@LTe](https://github.com/LTe). #### v0.0.2 -* Add Travis. [view commit](http://github.com/ruby-grape/grape-rabl/commit/71c905bc91066c6fdb628afb555561e23219e213) -* Remove ruby debug. [view commit](http://github.com/ruby-grape/grape-rabl/commit/f80fad14a49b14ae7264b08eff12832c37cbd0b2) -* Works with rubinius. [view commit](http://github.com/ruby-grape/grape-rabl/commit/fceece344de095916ded7c477bb5891537bb8663) -* Add dependency status. [view commit](http://github.com/ruby-grape/grape-rabl/commit/66820fb52155c65d4cd9bd7b67f0f22c1105fa46) +* Add Travis - [@LTe](https://github.com/LTe). +* Remove ruby debug - [@LTe](https://github.com/LTe). +* Works with rubinius - [@LTe](https://github.com/LTe). +* Add dependency status - [@LTe](https://github.com/LTe). #### v0.0.1 -* Initial public release. [@LTe](https://github.com/lte) +* Initial public release - [@LTe](https://github.com/lte). diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..f05fedd --- /dev/null +++ b/Dangerfile @@ -0,0 +1 @@ +danger.import_dangerfile(gem: 'ruby-grape-danger') diff --git a/Gemfile b/Gemfile index e19988a..49d1e91 100644 --- a/Gemfile +++ b/Gemfile @@ -13,8 +13,5 @@ group :test do gem 'rake' gem 'coveralls', require: false gem 'rabl' - - platforms :rbx do - gem 'iconv' - end + gem 'ruby-grape-danger', '~> 0.1.1', require: false end From 6d83f8789f083e5a5d32d2994b4278c897a1d511 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 17 Nov 2017 09:47:55 -0500 Subject: [PATCH 21/29] Preparing for release, 0.4.3. --- CHANGELOG.md | 3 +-- README.md | 9 ++------ RELEASING.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 RELEASING.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 86e43a8..5dba4f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,8 @@ -#### Next +#### v0.4.3 * [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Don't require unused hashie - [@tsuwatch](https://github.com/tsuwatch). * [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Support Ruby >= 2.2 - [@tsuwatch](https://github.com/tsuwatch). * [#45](https://github.com/ruby-grape/grape-rabl/pull/45): Added danger, PR linter - [@dblock](https://github.com/dblock). -* Your contribution here. #### v0.4.2 diff --git a/README.md b/README.md index 908b096..921393e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ And then execute: ## Usage ### Setup view root directory + ```ruby # config.ru use Rack::Config do |env| @@ -194,15 +195,9 @@ See ["Writing Tests"](https://github.com/intridea/grape#writing-tests) in [https 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 - +See [CONTRIBUTING](CONTRIBUTING.md). [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ruby-grape/grape-rabl/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..a90834f --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,64 @@ +# Releasing Grape-Rabl + +There're no particular rules about when to release grape-rabl. Release bug fixes frequently, features not so frequently and breaking API changes rarely. + +### Release + +Run tests, check that all tests succeed locally. + +``` +bundle install +rake +``` + +Check that the last build succeeded in [Travis CI](https://travis-ci.org/ruby-grape/grape-rabl) for all supported platforms. + +Increment the version, modify [lib/grape-rabl/version.rb](lib/grape-rabl/version.rb). + +* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.7.1` to `0.7.2`). +* Increment the second number if the release contains major features or breaking API changes (eg. change `0.7.1` to `0.8.0`). + +Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version. + +``` +### 0.7.2 (February 6, 2014) +``` + +Remove the line with "Your contribution here.", since there will be no more contributions to this release. + +Commit your changes. + +``` +git add CHANGELOG.md lib/grape-rabl/version.rb +git commit -m "Preparing for release, 0.7.2." +git push origin master +``` + +Release. + +``` +$ rake release + +grape-rabl 0.7.2 built to pkg/grape-rabl-0.7.2.gem. +Tagged v0.7.2. +Pushed git commits and tags. +Pushed grape-rabl 0.7.2 to rubygems.org. +``` + +### Prepare for the Next Version + +Add the next release to [CHANGELOG.md](CHANGELOG.md). + +``` +#### Next + +* Your contribution here. +``` + +Commit your changes. + +``` +git add CHANGELOG.md +git commit -m "Preparing for next development iteration, 0.7.3." +git push origin master +``` From e5e3cac1a57cbaee60d947b198293f56fd43749c Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 17 Nov 2017 09:48:30 -0500 Subject: [PATCH 22/29] Preparing for next developer iteration, 0.4.4. --- CHANGELOG.md | 4 ++++ lib/grape-rabl/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dba4f9..6680260 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Next + +* Your contribution here. + #### v0.4.3 * [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Don't require unused hashie - [@tsuwatch](https://github.com/tsuwatch). diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index 0f7afb7..c7fafc9 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.4.3'.freeze + VERSION = '0.4.4'.freeze end end From 16216b59052e6053d6888c7b57c25d6c0d0f3a51 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 17 Nov 2017 09:50:06 -0500 Subject: [PATCH 23/29] Removed non-working badge. [ci skip] --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 921393e..a48674d 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,3 @@ Enjoy :) ## Contributing See [CONTRIBUTING](CONTRIBUTING.md). - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ruby-grape/grape-rabl/trend.png)](https://bitdeli.com/free "Bitdeli Badge") - From c17f5ff7e24aa53b50e5668d4e39613b4d41e298 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 17 Nov 2017 09:52:17 -0500 Subject: [PATCH 24/29] Upgraded RuboCop to 0.51.0. --- .rubocop_todo.yml | 24 +++++++++++++++--------- Gemfile | 8 ++++---- Rakefile | 2 +- grape-rabl.gemspec | 6 +++--- spec/views/_partial.rabl | 2 +- spec/views/admin.rabl | 2 +- spec/views/info.rabl | 2 +- spec/views/project.rabl | 6 +++--- spec/views/user.rabl | 2 +- 9 files changed, 30 insertions(+), 24 deletions(-) mode change 100644 => 100755 Rakefile diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 52bc357..eb3c70e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-06-08 16:00:13 -0400 using RuboCop version 0.40.0. +# on 2017-11-17 09:51:46 -0500 using RuboCop version 0.51.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -11,8 +11,13 @@ Lint/RescueException: Exclude: - 'spec/grape_rabl_spec.rb' -# Offense count: 21 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# Offense count: 8 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 169 + +# Offense count: 23 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 148 @@ -22,6 +27,13 @@ Metrics/LineLength: Metrics/MethodLength: Max: 13 +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/grape-rabl.rb' + # Offense count: 5 Style/Documentation: Exclude: @@ -38,12 +50,6 @@ Style/DoubleNegation: Exclude: - 'lib/grape-rabl/formatter.rb' -# Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts. -Style/FileName: - Exclude: - - 'lib/grape-rabl.rb' - # Offense count: 1 Style/IfInsideElse: Exclude: diff --git a/Gemfile b/Gemfile index 49d1e91..38f35e9 100644 --- a/Gemfile +++ b/Gemfile @@ -3,15 +3,15 @@ source 'https://rubygems.org' gemspec group :development do - gem 'rubocop', '0.40.0' + gem 'rubocop', '0.51.0' end group :test do + gem 'coveralls', require: false gem 'json' - gem 'rspec' + gem 'rabl' gem 'rack-test' gem 'rake' - gem 'coveralls', require: false - gem 'rabl' + gem 'rspec' gem 'ruby-grape-danger', '~> 0.1.1', require: false end diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index a0298c6..1dd0ac7 --- a/Rakefile +++ b/Rakefile @@ -11,4 +11,4 @@ end require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) -task default: [:rubocop, :spec] +task default: %i[rubocop spec] diff --git a/grape-rabl.gemspec b/grape-rabl.gemspec index d394d57..321ed27 100644 --- a/grape-rabl.gemspec +++ b/grape-rabl.gemspec @@ -1,8 +1,8 @@ -# -*- encoding: utf-8 -*- + require File.expand_path('../lib/grape-rabl/version', __FILE__) Gem::Specification.new do |gem| - gem.authors = ["Piotr Niełacny"] + gem.authors = ['Piotr Niełacny'] gem.email = ['piotr.nielacny@gmail.com'] gem.description = 'Use rabl in grape' gem.summary = 'Use rabl in grape' @@ -17,7 +17,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 2.2.0' gem.add_dependency 'grape' + gem.add_dependency 'i18n' gem.add_dependency 'rabl' gem.add_dependency 'tilt' - gem.add_dependency 'i18n' end diff --git a/spec/views/_partial.rabl b/spec/views/_partial.rabl index 3470f4a..b2ea33b 100644 --- a/spec/views/_partial.rabl +++ b/spec/views/_partial.rabl @@ -1 +1 @@ -attributes :type \ No newline at end of file +attributes :type diff --git a/spec/views/admin.rabl b/spec/views/admin.rabl index 6255667..8c74f29 100644 --- a/spec/views/admin.rabl +++ b/spec/views/admin.rabl @@ -1,6 +1,6 @@ object @user => :admin attributes :name -node :details, :unless => lambda { |n| locals[:details].nil? } do |m| +node :details, unless: ->(_n) { locals[:details].nil? } do |_m| locals[:details] end diff --git a/spec/views/info.rabl b/spec/views/info.rabl index 21ab4a6..770c09d 100644 --- a/spec/views/info.rabl +++ b/spec/views/info.rabl @@ -1 +1 @@ -attributes :author \ No newline at end of file +attributes :author diff --git a/spec/views/project.rabl b/spec/views/project.rabl index 61539ea..7595600 100644 --- a/spec/views/project.rabl +++ b/spec/views/project.rabl @@ -2,9 +2,9 @@ object @project => :project attributes :name node :info do - partial "partial", object: @project.type + partial 'partial', object: @project.type end child @author => :author do - extends "info" -end \ No newline at end of file + extends 'info' +end diff --git a/spec/views/user.rabl b/spec/views/user.rabl index 8ba931d..4b8c5c7 100644 --- a/spec/views/user.rabl +++ b/spec/views/user.rabl @@ -5,6 +5,6 @@ child @project => :project do attributes :name end -node :details, :unless => lambda { |n| locals[:details].nil? } do |m| +node :details, unless: ->(_n) { locals[:details].nil? } do |_m| locals[:details] end From 0ecce931bff562a7e9053eff0ecaec4b6ae3f3a2 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 15 Jul 2019 16:20:58 +0200 Subject: [PATCH 25/29] README: Drop Gemnasium badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index a48674d..c136681 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github [![Gem Version](http://img.shields.io/gem/v/grape-rabl.svg)](http://badge.fury.io/rb/grape-rabl) [![Build Status](http://img.shields.io/travis/ruby-grape/grape-rabl.svg)](https://travis-ci.org/ruby-grape/grape-rabl) -[![Dependency Status](https://gemnasium.com/ruby-grape/grape-rabl.svg)](https://gemnasium.com/ruby-grape/grape-rabl) [![Code Climate](https://codeclimate.com/github/ruby-grape/grape-rabl.svg)](https://codeclimate.com/github/ruby-grape/grape-rabl) [![Coverage Status](https://img.shields.io/coveralls/ruby-grape/grape-rabl.svg)](https://coveralls.io/r/ruby-grape/grape-rabl?branch=master) From 359298a93642e65f3813997f72f49a1c30bd300a Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 15 Jul 2019 16:54:01 +0200 Subject: [PATCH 26/29] README: Repair link to Grape project --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c136681..bf364de 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Grape::Rabl -Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github.com/intridea/grape)! +Use [Rabl](https://github.com/nesquena/rabl) templates in [Grape](https://github.com/ruby-grape/grape)! [![Gem Version](http://img.shields.io/gem/v/grape-rabl.svg)](http://badge.fury.io/rb/grape-rabl) [![Build Status](http://img.shields.io/travis/ruby-grape/grape-rabl.svg)](https://travis-ci.org/ruby-grape/grape-rabl) @@ -190,7 +190,7 @@ end ## Specs -See ["Writing Tests"](https://github.com/intridea/grape#writing-tests) in [https://github.com/intridea/grape](grape) README. +See ["Writing Tests"](https://github.com/ruby-grape/grape#writing-tests) in [grape](https://github.com/ruby-grape/grape) README. Enjoy :) From f808c48c53d2053fbf8e2605a1f4598ecf434ed5 Mon Sep 17 00:00:00 2001 From: Chris Bloom Date: Mon, 18 Nov 2019 09:03:08 -0500 Subject: [PATCH 27/29] Allow fallback to use formatter for default format (#34) --- CHANGELOG.md | 4 ++ README.md | 6 ++- UPGRADING.md | 32 ++++++++++++ lib/grape-rabl/formatter.rb | 8 ++- lib/grape-rabl/version.rb | 2 +- spec/grape_rabl_formatter_spec.rb | 84 +++++++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 UPGRADING.md create mode 100644 spec/grape_rabl_formatter_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 6680260..13526af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ * Your contribution here. +#### v0.5.0 + +* [#34](https://github.com/ruby-grape/grape-rabl/pulls/34): If no RABL template is specified, fallback to the default response format as determined by Grape - [@chrisbloom7](https://github.com/chrisbloom7). + #### v0.4.3 * [#44](https://github.com/ruby-grape/grape-rabl/issues/44): Don't require unused hashie - [@tsuwatch](https://github.com/tsuwatch). diff --git a/README.md b/README.md index bf364de..f8836d0 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ And then execute: $ bundle +## Upgrading + +See [UPGRADING](UPGRADING.md). + ## Usage ### Setup view root directory @@ -134,7 +138,7 @@ class UserAPI < Grape::API @history = User.find(params[:id]).history end - # do not use rabl, fallback to the defalt Grape JSON formatter + # do not use rabl, fallback to the default Grape response formatter get '/users' do User.all end diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..365512b --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,32 @@ +# Upgrading Grape::Rabl + +## Upgrading to >= 0.5 + +### Fallback rendering when no RABL template is defined + +Prior to v0.5.0, Grape::Rabl would always render content as JSON when no Rabl template was specified for a request. Beginning in v0.5.0 Grape::Rabl will now fallback to using the default response format [as determined by Grape](https://github.com/ruby-grape/grape#api-formats) + +```ruby +class SampleApi < Grape::API + format :xml + formatter :xml, Grape::Formatter::Rabl + + get 'list' do + %w[thing] + end +end +``` + +#### Former behavior + +```ruby +response.body # => ["thing"] +``` + +#### Current behavior + +```ruby +response.body # => \n\n thing\n +``` + +See [#34](https://github.com/ruby-grape/grape-rabl/pull/34) for more information. diff --git a/lib/grape-rabl/formatter.rb b/lib/grape-rabl/formatter.rb index 2257214..d0734ba 100644 --- a/lib/grape-rabl/formatter.rb +++ b/lib/grape-rabl/formatter.rb @@ -29,12 +29,18 @@ def render end end else - Grape::Formatter::Json.call object, env + fallback_formatter.call object, env end end private + # Find a formatter to fallback to. `env[Grape::Env::API_FORMAT]` will always be a + # valid formatter, otherwise a HTTP 406 error would have already have been thrown + def fallback_formatter + Grape::Formatter.formatter_for(env[Grape::Env::API_FORMAT]) + end + def view_path(template) if template.split('.')[-1] == 'rabl' File.join(env['api.tilt.root'], template) diff --git a/lib/grape-rabl/version.rb b/lib/grape-rabl/version.rb index c7fafc9..82bbe09 100644 --- a/lib/grape-rabl/version.rb +++ b/lib/grape-rabl/version.rb @@ -1,5 +1,5 @@ module Grape module Rabl - VERSION = '0.4.4'.freeze + VERSION = '0.5.0'.freeze end end diff --git a/spec/grape_rabl_formatter_spec.rb b/spec/grape_rabl_formatter_spec.rb new file mode 100644 index 0000000..eed3275 --- /dev/null +++ b/spec/grape_rabl_formatter_spec.rb @@ -0,0 +1,84 @@ +require 'spec_helper' + +describe 'Grape::Rabl formatter' do + subject do + Class.new(Grape::API) + end + + let(:xml_render) do + %( + + + bad + things + happened + + +) + end + + def app + subject + end + + context 'rendering' do + context 'when no rabl template is specified' do + before do + # Grape::API defaults to the following declarations: + # content_type :xml, 'application/xml' + # content_type :json, 'application/json' + # content_type :binary, 'application/octet-stream' + # content_type :txt, 'text/plain' + # default_format :txt + subject.formatter :xml, Grape::Formatter::Rabl + subject.formatter :txt, Grape::Formatter::Rabl + subject.get('/oops') { { errors: %w[bad things happened] } } + expect_any_instance_of(Grape::Rabl::Formatter).to receive(:render).and_call_original + end + + it 'falls back to :txt given no other format information' do + get '/oops' + expect(last_response.body).to eq('{:errors=>["bad", "things", "happened"]}') + expect(last_response.headers['Content-Type']).to eq('text/plain') + end + + it 'falls back to the file extension if it is a valid format' do + get '/oops.xml' + expect(last_response.body).to eq(xml_render) + expect(last_response.headers['Content-Type']).to eq('application/xml') + end + + it 'falls back to the value of the `format` parameter in the query string if it is provided' do + get '/oops?format=xml' + expect(last_response.body).to eq(xml_render) + expect(last_response.headers['Content-Type']).to eq('application/xml') + end + + it 'falls back to the format set by the `format` option if it is a valid format' do + # `format` option must be declared before endpoint + subject.format :xml + subject.get('/oops/2') { { errors: %w[bad things happened] } } + + get '/oops/2' + expect(last_response.body).to eq(xml_render) + expect(last_response.headers['Content-Type']).to eq('application/xml') + end + + it 'falls back to the `Accept` header if it is a valid format' do + get '/oops', {}, 'HTTP_ACCEPT' => 'application/xml' + expect(last_response.body).to eq(xml_render) + expect(last_response.headers['Content-Type']).to eq('application/xml') + end + + it 'falls back to the default_format option if it is a valid format' do + # `default_format` option must be declared before endpoint + subject.default_format :xml + subject.get('/oops/2') { { errors: %w[bad things happened] } } + + get '/oops/2' + expect(last_response.body).to eq(xml_render) + expect(last_response.headers['Content-Type']).to eq('application/xml') + end + end + end +end From 6349067839ae93388d6625f49bf80aa7233d5d32 Mon Sep 17 00:00:00 2001 From: Chris Bloom Date: Tue, 19 Nov 2019 11:52:42 -0500 Subject: [PATCH 28/29] Preparing for release 0.5.0 --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13526af..a36e949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,3 @@ -#### Next - -* Your contribution here. - #### v0.5.0 * [#34](https://github.com/ruby-grape/grape-rabl/pulls/34): If no RABL template is specified, fallback to the default response format as determined by Grape - [@chrisbloom7](https://github.com/chrisbloom7). From b201ebdb0dc44906e5b42619f060fa3ac4e5bdfd Mon Sep 17 00:00:00 2001 From: Chris Bloom Date: Tue, 19 Nov 2019 12:00:45 -0500 Subject: [PATCH 29/29] Preparing for next development iteration, 0.5.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a36e949..13526af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### Next + +* Your contribution here. + #### v0.5.0 * [#34](https://github.com/ruby-grape/grape-rabl/pulls/34): If no RABL template is specified, fallback to the default response format as determined by Grape - [@chrisbloom7](https://github.com/chrisbloom7).