force_format 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +31 -0
- data/Appraisals +7 -0
- data/Gemfile +0 -3
- data/README.md +69 -24
- data/Rakefile +4 -0
- data/force_format.gemspec +2 -1
- data/gemfiles/3.2.gemfile +8 -0
- data/gemfiles/3.2.gemfile.lock +128 -0
- data/gemfiles/4.0.gemfile +8 -0
- data/gemfiles/4.0.gemfile.lock +123 -0
- data/lib/force_format/{controller_access.rb → controller.rb} +4 -3
- data/lib/force_format/errors.rb +4 -1
- data/lib/force_format/railtie.rb +4 -4
- data/lib/force_format/version.rb +1 -1
- data/lib/force_format/{view_patch.rb → view.rb} +1 -1
- data/spec/array_options_spec.rb +109 -0
- data/spec/{dummy → dummy3.2}/README.rdoc +0 -0
- data/spec/{dummy → dummy3.2}/Rakefile +0 -0
- data/spec/{dummy → dummy3.2}/app/assets/javascripts/application.js +0 -0
- data/spec/{dummy → dummy3.2}/app/assets/stylesheets/application.css +0 -0
- data/spec/{dummy → dummy3.2}/app/controllers/application_controller.rb +0 -0
- data/spec/{dummy → dummy3.2}/app/controllers/pages_controller.rb +0 -0
- data/spec/{dummy → dummy3.2}/app/helpers/application_helper.rb +0 -0
- data/spec/{dummy → dummy3.2}/app/mailers/.gitkeep +0 -0
- data/spec/{dummy → dummy3.2}/app/models/.gitkeep +0 -0
- data/spec/{dummy → dummy3.2}/app/views/layouts/application.html.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/index.html.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/with_html.html.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/with_html_js.html.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/with_html_js.js.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/with_js.js.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/with_json.json.erb +0 -0
- data/spec/{dummy → dummy3.2}/app/views/pages/with_xml.xml.erb +0 -0
- data/spec/{dummy → dummy3.2}/config/application.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/boot.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/database.yml +0 -0
- data/spec/{dummy → dummy3.2}/config/environment.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/environments/development.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/environments/production.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/environments/test.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/initializers/inflections.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/initializers/mime_types.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/initializers/secret_token.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/initializers/session_store.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/{dummy → dummy3.2}/config/locales/en.yml +0 -0
- data/spec/{dummy → dummy3.2}/config/routes.rb +0 -0
- data/spec/{dummy → dummy3.2}/config.ru +0 -0
- data/spec/{dummy/lib/assets/.gitkeep → dummy3.2/db/test.sqlite3} +0 -0
- data/spec/{dummy/log → dummy3.2/lib/assets}/.gitkeep +0 -0
- data/spec/{dummy/public/favicon.ico → dummy3.2/log/.gitkeep} +0 -0
- data/spec/{dummy → dummy3.2}/public/404.html +0 -0
- data/spec/{dummy → dummy3.2}/public/422.html +0 -0
- data/spec/{dummy → dummy3.2}/public/500.html +0 -0
- data/spec/dummy3.2/public/favicon.ico +0 -0
- data/spec/{dummy → dummy3.2}/script/rails +0 -0
- data/spec/dummy4.0/README.rdoc +28 -0
- data/spec/dummy4.0/Rakefile +6 -0
- data/spec/dummy4.0/app/assets/images/.keep +0 -0
- data/spec/dummy4.0/app/assets/javascripts/application.js +13 -0
- data/spec/dummy4.0/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy4.0/app/controllers/application_controller.rb +5 -0
- data/spec/dummy4.0/app/controllers/concerns/.keep +0 -0
- data/spec/dummy4.0/app/controllers/pages_controller.rb +4 -0
- data/spec/dummy4.0/app/helpers/application_helper.rb +2 -0
- data/spec/dummy4.0/app/mailers/.keep +0 -0
- data/spec/dummy4.0/app/models/.keep +0 -0
- data/spec/dummy4.0/app/models/concerns/.keep +0 -0
- data/spec/dummy4.0/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy4.0/app/views/pages/index.html.erb +0 -0
- data/spec/dummy4.0/app/views/pages/with_html.html.erb +0 -0
- data/spec/dummy4.0/app/views/pages/with_html_js.html.erb +0 -0
- data/spec/dummy4.0/app/views/pages/with_html_js.js.erb +0 -0
- data/spec/dummy4.0/app/views/pages/with_js.js.erb +0 -0
- data/spec/dummy4.0/app/views/pages/with_json.json.erb +0 -0
- data/spec/dummy4.0/app/views/pages/with_xml.xml.erb +0 -0
- data/spec/dummy4.0/bin/bundle +3 -0
- data/spec/dummy4.0/bin/rails +4 -0
- data/spec/dummy4.0/bin/rake +4 -0
- data/spec/dummy4.0/config/application.rb +28 -0
- data/spec/dummy4.0/config/boot.rb +5 -0
- data/spec/dummy4.0/config/database.yml +25 -0
- data/spec/dummy4.0/config/environment.rb +5 -0
- data/spec/dummy4.0/config/environments/development.rb +29 -0
- data/spec/dummy4.0/config/environments/production.rb +80 -0
- data/spec/dummy4.0/config/environments/test.rb +36 -0
- data/spec/dummy4.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy4.0/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy4.0/config/initializers/inflections.rb +16 -0
- data/spec/dummy4.0/config/initializers/mime_types.rb +5 -0
- data/spec/dummy4.0/config/initializers/secret_token.rb +12 -0
- data/spec/dummy4.0/config/initializers/session_store.rb +3 -0
- data/spec/dummy4.0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy4.0/config/locales/en.yml +23 -0
- data/spec/dummy4.0/config/routes.rb +4 -0
- data/spec/dummy4.0/config.ru +4 -0
- data/spec/dummy4.0/db/test.sqlite3 +0 -0
- data/spec/dummy4.0/lib/assets/.keep +0 -0
- data/spec/dummy4.0/log/.keep +0 -0
- data/spec/dummy4.0/public/404.html +58 -0
- data/spec/dummy4.0/public/422.html +58 -0
- data/spec/dummy4.0/public/500.html +57 -0
- data/spec/dummy4.0/public/favicon.ico +0 -0
- data/spec/exception_spec.rb +36 -0
- data/spec/hash_options_spec.rb +105 -0
- data/spec/rails_behaviour_spec.rb +35 -0
- data/spec/skip_filter_spec.rb +99 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/wildcard_spec.rb +41 -0
- data/spec/without_options_spec.rb +73 -0
- metadata +216 -88
- data/spec/base_spec.rb +0 -429
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4345cd2da6375d312b3c78e8d675dce5334cd1c2
|
4
|
+
data.tar.gz: 541fd591fa06f058a59417c6abad05e05b6684da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d13f190eb6b6ece7829c9af976a64dac687fba1e4c3b2cf43bf85d595064d8f668ddb5c0be256f65fa3e4b490098530133f7cccede82258ca21c1dbc0cfa29e7
|
7
|
+
data.tar.gz: 1e3c7372ae4bcdc618f9d5f03a1ec3ae8695198442ccb6cb8d2605a757940318d0128ed170548df9f6d52f190b1e1c43cc2b99480de507afaebf0df9a2d2d5e4
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
script: "bundle exec rake spec"
|
4
|
+
bundler_args: ''
|
5
|
+
|
6
|
+
rvm:
|
7
|
+
- 1.9.3
|
8
|
+
- 2.0.0
|
9
|
+
|
10
|
+
env:
|
11
|
+
- RAILS_VERSION=3.2
|
12
|
+
- RAILS_VERSION=4.0
|
13
|
+
|
14
|
+
gemfile:
|
15
|
+
- gemfiles/3.2.gemfile
|
16
|
+
- gemfiles/4.0.gemfile
|
17
|
+
|
18
|
+
matrix:
|
19
|
+
exclude:
|
20
|
+
- rvm: 2.0.0
|
21
|
+
gemfile: gemfiles/4.0.gemfile
|
22
|
+
env: RAILS_VERSION=3.2
|
23
|
+
- rvm: 1.9.3
|
24
|
+
gemfile: gemfiles/4.0.gemfile
|
25
|
+
env: RAILS_VERSION=3.2
|
26
|
+
- rvm: 2.0.0
|
27
|
+
gemfile: gemfiles/3.2.gemfile
|
28
|
+
env: RAILS_VERSION=4.0
|
29
|
+
- rvm: 1.9.3
|
30
|
+
gemfile: gemfiles/3.2.gemfile
|
31
|
+
env: RAILS_VERSION=4.0
|
data/Appraisals
ADDED
data/Gemfile
CHANGED
@@ -5,9 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
# development dependencies will be added by default to the :development group.
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
# jquery-rails is used by the dummy application
|
9
|
-
gem "jquery-rails"
|
10
|
-
|
11
8
|
# Declare any dependencies that are still in development here instead of in
|
12
9
|
# your gemspec. These might include edge Rails or gems from your path or
|
13
10
|
# Git. Remember to move these dependencies to your gemspec before releasing
|
data/README.md
CHANGED
@@ -1,16 +1,38 @@
|
|
1
1
|
# force_format
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/force_format.png)](http://badge.fury.io/rb/force_format)
|
4
|
+
[![Build Status](https://travis-ci.org/marcusg/force_format.png?branch=master)](https://travis-ci.org/marcusg/force_format)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/marcusg/force_format.png)](https://codeclimate.com/github/marcusg/force_format)
|
6
|
+
[![Dependency Status](https://gemnasium.com/marcusg/force_format.png)](https://gemnasium.com/marcusg/force_format)
|
7
7
|
|
8
|
+
Define the formats your Rails application should respond to within your controllers.
|
8
9
|
|
9
|
-
##
|
10
|
+
## Background
|
11
|
+
|
12
|
+
Normally a Rails3 application tries to respond to all kinds of formats (e.g. html, xml, json, ...)
|
13
|
+
defined via ```respond_to``` inside the controller. Given the following setup for a controller responding
|
14
|
+
to html and javascript requests.
|
15
|
+
|
16
|
+
class PagesController < ApplicationController
|
17
|
+
|
18
|
+
def index
|
19
|
+
respond_to do |format|
|
20
|
+
format.html
|
21
|
+
format.js
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
10
25
|
|
11
|
-
|
26
|
+
All other requests will return a white page with status code 406 (Not Acceptable). FOr some this seems to be a correct behaviour but it may be important for some webapps to render out a error page giving a good description of the error - like 404 pages. In other words: if the action can't handle the requested format render out an error page with an supported format like html.
|
12
27
|
|
13
|
-
|
28
|
+
This is where ```force_format``` joins the game. The gem adds some accessible methods for your controllers based on before_filters. With that you can define the allowed formats for each controller action. If the requested mime-type does not
|
29
|
+
match one of the specified formats, ```force_format``` will raise a custom exception wich you can handle on you own (e.g. print out some useful sentences for your users).
|
30
|
+
|
31
|
+
Besides this, if you theoretical don't need the ```respond_to``` because you use templates which are rendered by default, you can omit the ```respond_to``` block when using ```force_format```.
|
32
|
+
|
33
|
+
## Requirements
|
34
|
+
|
35
|
+
```rails >= 3.2```
|
14
36
|
|
15
37
|
## Installation
|
16
38
|
|
@@ -31,8 +53,8 @@ Or install it yourself as:
|
|
31
53
|
#### Basics
|
32
54
|
|
33
55
|
Include the ```force_format_filter``` method in your controllers.
|
34
|
-
The important param is the ```:for => [:my, :formats]```.
|
35
|
-
With that given array of fomat types you can define the formats the
|
56
|
+
The important param is the ```:for => [:my, :formats]```.
|
57
|
+
With that given array of fomat types you can define the formats the
|
36
58
|
action should respond to (and hopefully find a template).
|
37
59
|
In addition it accepts ```:only => ...```, ```:except => ...```, ```:if => ...```
|
38
60
|
and ```:unless => ...``` parameters like the Rails filters.
|
@@ -45,15 +67,25 @@ and ```:unless => ...``` parameters like the Rails filters.
|
|
45
67
|
def index
|
46
68
|
end
|
47
69
|
end
|
48
|
-
|
49
|
-
|
70
|
+
|
71
|
+
|
72
|
+
#### Supported format types
|
73
|
+
For the moment the following (MIME-)types are available.
|
74
|
+
|
75
|
+
ForceFormat::Controller::FORCE_FORMAT_TYPES
|
76
|
+
=> [:html, :js, :json, :pdf, :csv, :zip, :xml]
|
77
|
+
|
78
|
+
|
79
|
+
#### Skip the filter
|
80
|
+
|
81
|
+
If you want to skip the filter in inherited controllers, use the ```skip_force_format_filter``` method.
|
50
82
|
It accepts the same parameters the ```force_format_filter``` methods except ```:for => ...```.
|
51
83
|
|
52
84
|
#### And more options...
|
53
85
|
|
54
|
-
Maybe you want to define the formats more granular, for example different per action.
|
55
|
-
To accomplish this, pass an hash with action names and required formats. Add a *:default* key with formats
|
56
|
-
for actions that are not specified directly.
|
86
|
+
Maybe you want to define the formats more granular, for example different per action.
|
87
|
+
To accomplish this, pass an hash with action names and required formats. Add a *:default* key with formats
|
88
|
+
for actions that are not specified directly.
|
57
89
|
|
58
90
|
|
59
91
|
class PagesController < ApplicationController
|
@@ -62,40 +94,53 @@ for actions that are not specified directly.
|
|
62
94
|
def index
|
63
95
|
# should respond with js
|
64
96
|
end
|
65
|
-
|
97
|
+
|
66
98
|
def new
|
67
99
|
# should respond with json or html
|
68
100
|
end
|
69
101
|
|
70
102
|
end
|
71
|
-
|
72
103
|
|
73
|
-
#### Exceptions
|
74
104
|
|
75
|
-
|
76
|
-
|
105
|
+
#### Handling exceptions
|
106
|
+
|
107
|
+
By default ```force_format``` raises an ```ForceFormat::Errors::UnknownFormat```
|
108
|
+
if a requested format matches none of the attributes specified via ```:for => ...```.
|
77
109
|
It should be easy to rescue from this exception, for example in your ```application_controller.rb```:
|
78
110
|
|
79
|
-
|
111
|
+
|
80
112
|
class ApplicationController < ActionController::Base
|
81
113
|
|
82
|
-
rescue_from
|
114
|
+
rescue_from ForceFormat::Errors::UnknownFormat, :with => :render_error
|
83
115
|
|
84
116
|
def render_error
|
85
117
|
# handle it
|
86
118
|
end
|
87
119
|
end
|
88
|
-
|
89
120
|
|
90
|
-
|
121
|
+
#### Use custom exception
|
122
|
+
|
123
|
+
You can pass an custom exception lambda to the ```force_format_filter``` method for a better error handling.
|
91
124
|
|
92
125
|
class PagesController < ApplicationController
|
93
126
|
force_format_filter :for => :html, :exception => lambda { |msg| raise(MyApp::AwesomeException.new(msg)) }
|
94
127
|
end
|
95
128
|
|
96
|
-
|
129
|
+
|
130
|
+
#### Widcard accept header
|
131
|
+
|
132
|
+
If an user agent sets the accept header wildcard like ```*/*``` ```force_format_filter``` would fallback
|
133
|
+
and set the ```request.format``` to *:html*. This is important for access via ```curl``` and I think for the
|
134
|
+
google bot too. If you don't want this behaviour of wildcard rewriting you can set the ```:skip_wildcard``` option.
|
135
|
+
|
136
|
+
class PagesController < ApplicationController
|
137
|
+
force_format_filter :for => :html, :skip_wildcard => true
|
138
|
+
end
|
139
|
+
|
140
|
+
NOTE: Call the method ```force_format_filter``` only once per controller!
|
97
141
|
If you call it multiple times, the last one would be used.
|
98
142
|
|
143
|
+
|
99
144
|
## TODO
|
100
145
|
1. More tests
|
101
146
|
2. More robust params checking
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
begin
|
3
3
|
require 'bundler/setup'
|
4
|
+
require 'appraisal'
|
5
|
+
require 'rspec/core/rake_task'
|
4
6
|
rescue LoadError
|
5
7
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
8
|
end
|
@@ -21,3 +23,5 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
21
23
|
end
|
22
24
|
|
23
25
|
Bundler::GemHelper.install_tasks
|
26
|
+
task :default => :spec
|
27
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/force_format.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'shoulda-matchers', '~> 2.4'
|
25
25
|
spec.add_development_dependency "sqlite3"
|
26
26
|
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "appraisal", "~> 0.5.2"
|
27
28
|
|
28
|
-
spec.add_dependency "rails", "
|
29
|
+
spec.add_dependency "rails", ">= 3.2"
|
29
30
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/marcus/Work/repos/github/force_format
|
3
|
+
specs:
|
4
|
+
force_format (0.0.6)
|
5
|
+
rails (>= 3.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.2.14)
|
11
|
+
actionpack (= 3.2.14)
|
12
|
+
mail (~> 2.5.4)
|
13
|
+
actionpack (3.2.14)
|
14
|
+
activemodel (= 3.2.14)
|
15
|
+
activesupport (= 3.2.14)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.5)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.14)
|
24
|
+
activesupport (= 3.2.14)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.14)
|
27
|
+
activemodel (= 3.2.14)
|
28
|
+
activesupport (= 3.2.14)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.14)
|
32
|
+
activemodel (= 3.2.14)
|
33
|
+
activesupport (= 3.2.14)
|
34
|
+
activesupport (3.2.14)
|
35
|
+
i18n (~> 0.6, >= 0.6.4)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
appraisal (0.5.2)
|
38
|
+
bundler
|
39
|
+
rake
|
40
|
+
arel (3.0.2)
|
41
|
+
builder (3.0.4)
|
42
|
+
coderay (1.0.9)
|
43
|
+
diff-lcs (1.2.4)
|
44
|
+
erubis (2.7.0)
|
45
|
+
hike (1.2.3)
|
46
|
+
i18n (0.6.5)
|
47
|
+
journey (1.0.4)
|
48
|
+
jquery-rails (3.0.4)
|
49
|
+
railties (>= 3.0, < 5.0)
|
50
|
+
thor (>= 0.14, < 2.0)
|
51
|
+
json (1.8.0)
|
52
|
+
mail (2.5.4)
|
53
|
+
mime-types (~> 1.16)
|
54
|
+
treetop (~> 1.4.8)
|
55
|
+
method_source (0.8.2)
|
56
|
+
mime-types (1.25)
|
57
|
+
multi_json (1.8.0)
|
58
|
+
polyglot (0.3.3)
|
59
|
+
pry (0.9.12.2)
|
60
|
+
coderay (~> 1.0.5)
|
61
|
+
method_source (~> 0.8)
|
62
|
+
slop (~> 3.4)
|
63
|
+
rack (1.4.5)
|
64
|
+
rack-cache (1.2)
|
65
|
+
rack (>= 0.4)
|
66
|
+
rack-ssl (1.3.3)
|
67
|
+
rack
|
68
|
+
rack-test (0.6.2)
|
69
|
+
rack (>= 1.0)
|
70
|
+
rails (3.2.14)
|
71
|
+
actionmailer (= 3.2.14)
|
72
|
+
actionpack (= 3.2.14)
|
73
|
+
activerecord (= 3.2.14)
|
74
|
+
activeresource (= 3.2.14)
|
75
|
+
activesupport (= 3.2.14)
|
76
|
+
bundler (~> 1.0)
|
77
|
+
railties (= 3.2.14)
|
78
|
+
railties (3.2.14)
|
79
|
+
actionpack (= 3.2.14)
|
80
|
+
activesupport (= 3.2.14)
|
81
|
+
rack-ssl (~> 1.3.2)
|
82
|
+
rake (>= 0.8.7)
|
83
|
+
rdoc (~> 3.4)
|
84
|
+
thor (>= 0.14.6, < 2.0)
|
85
|
+
rake (10.1.0)
|
86
|
+
rdoc (3.12.2)
|
87
|
+
json (~> 1.4)
|
88
|
+
rspec-core (2.14.5)
|
89
|
+
rspec-expectations (2.14.3)
|
90
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
91
|
+
rspec-mocks (2.14.3)
|
92
|
+
rspec-rails (2.14.0)
|
93
|
+
actionpack (>= 3.0)
|
94
|
+
activesupport (>= 3.0)
|
95
|
+
railties (>= 3.0)
|
96
|
+
rspec-core (~> 2.14.0)
|
97
|
+
rspec-expectations (~> 2.14.0)
|
98
|
+
rspec-mocks (~> 2.14.0)
|
99
|
+
shoulda-matchers (2.4.0)
|
100
|
+
activesupport (>= 3.0.0)
|
101
|
+
slop (3.4.6)
|
102
|
+
sprockets (2.2.2)
|
103
|
+
hike (~> 1.2)
|
104
|
+
multi_json (~> 1.0)
|
105
|
+
rack (~> 1.0)
|
106
|
+
tilt (~> 1.1, != 1.3.0)
|
107
|
+
sqlite3 (1.3.8)
|
108
|
+
thor (0.18.1)
|
109
|
+
tilt (1.4.1)
|
110
|
+
treetop (1.4.15)
|
111
|
+
polyglot
|
112
|
+
polyglot (>= 0.3.1)
|
113
|
+
tzinfo (0.3.37)
|
114
|
+
|
115
|
+
PLATFORMS
|
116
|
+
ruby
|
117
|
+
|
118
|
+
DEPENDENCIES
|
119
|
+
appraisal (~> 0.5.2)
|
120
|
+
bundler (~> 1.3)
|
121
|
+
force_format!
|
122
|
+
jquery-rails
|
123
|
+
pry
|
124
|
+
rails (~> 3.2.14)
|
125
|
+
rake (~> 10.1)
|
126
|
+
rspec-rails (~> 2.0)
|
127
|
+
shoulda-matchers (~> 2.4)
|
128
|
+
sqlite3
|
@@ -0,0 +1,123 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /home/marcus/Work/repos/github/force_format
|
3
|
+
specs:
|
4
|
+
force_format (0.0.6)
|
5
|
+
rails (>= 3.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.0.0)
|
11
|
+
actionpack (= 4.0.0)
|
12
|
+
mail (~> 2.5.3)
|
13
|
+
actionpack (4.0.0)
|
14
|
+
activesupport (= 4.0.0)
|
15
|
+
builder (~> 3.1.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
rack (~> 1.5.2)
|
18
|
+
rack-test (~> 0.6.2)
|
19
|
+
activemodel (4.0.0)
|
20
|
+
activesupport (= 4.0.0)
|
21
|
+
builder (~> 3.1.0)
|
22
|
+
activerecord (4.0.0)
|
23
|
+
activemodel (= 4.0.0)
|
24
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
25
|
+
activesupport (= 4.0.0)
|
26
|
+
arel (~> 4.0.0)
|
27
|
+
activerecord-deprecated_finders (1.0.3)
|
28
|
+
activesupport (4.0.0)
|
29
|
+
i18n (~> 0.6, >= 0.6.4)
|
30
|
+
minitest (~> 4.2)
|
31
|
+
multi_json (~> 1.3)
|
32
|
+
thread_safe (~> 0.1)
|
33
|
+
tzinfo (~> 0.3.37)
|
34
|
+
appraisal (0.5.2)
|
35
|
+
bundler
|
36
|
+
rake
|
37
|
+
arel (4.0.0)
|
38
|
+
atomic (1.1.14)
|
39
|
+
builder (3.1.4)
|
40
|
+
coderay (1.0.9)
|
41
|
+
diff-lcs (1.2.4)
|
42
|
+
erubis (2.7.0)
|
43
|
+
hike (1.2.3)
|
44
|
+
i18n (0.6.5)
|
45
|
+
jquery-rails (3.0.4)
|
46
|
+
railties (>= 3.0, < 5.0)
|
47
|
+
thor (>= 0.14, < 2.0)
|
48
|
+
mail (2.5.4)
|
49
|
+
mime-types (~> 1.16)
|
50
|
+
treetop (~> 1.4.8)
|
51
|
+
method_source (0.8.2)
|
52
|
+
mime-types (1.25)
|
53
|
+
minitest (4.7.5)
|
54
|
+
multi_json (1.8.0)
|
55
|
+
polyglot (0.3.3)
|
56
|
+
pry (0.9.12.2)
|
57
|
+
coderay (~> 1.0.5)
|
58
|
+
method_source (~> 0.8)
|
59
|
+
slop (~> 3.4)
|
60
|
+
rack (1.5.2)
|
61
|
+
rack-test (0.6.2)
|
62
|
+
rack (>= 1.0)
|
63
|
+
rails (4.0.0)
|
64
|
+
actionmailer (= 4.0.0)
|
65
|
+
actionpack (= 4.0.0)
|
66
|
+
activerecord (= 4.0.0)
|
67
|
+
activesupport (= 4.0.0)
|
68
|
+
bundler (>= 1.3.0, < 2.0)
|
69
|
+
railties (= 4.0.0)
|
70
|
+
sprockets-rails (~> 2.0.0)
|
71
|
+
railties (4.0.0)
|
72
|
+
actionpack (= 4.0.0)
|
73
|
+
activesupport (= 4.0.0)
|
74
|
+
rake (>= 0.8.7)
|
75
|
+
thor (>= 0.18.1, < 2.0)
|
76
|
+
rake (10.1.0)
|
77
|
+
rspec-core (2.14.5)
|
78
|
+
rspec-expectations (2.14.3)
|
79
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
80
|
+
rspec-mocks (2.14.3)
|
81
|
+
rspec-rails (2.14.0)
|
82
|
+
actionpack (>= 3.0)
|
83
|
+
activesupport (>= 3.0)
|
84
|
+
railties (>= 3.0)
|
85
|
+
rspec-core (~> 2.14.0)
|
86
|
+
rspec-expectations (~> 2.14.0)
|
87
|
+
rspec-mocks (~> 2.14.0)
|
88
|
+
shoulda-matchers (2.4.0)
|
89
|
+
activesupport (>= 3.0.0)
|
90
|
+
slop (3.4.6)
|
91
|
+
sprockets (2.10.0)
|
92
|
+
hike (~> 1.2)
|
93
|
+
multi_json (~> 1.0)
|
94
|
+
rack (~> 1.0)
|
95
|
+
tilt (~> 1.1, != 1.3.0)
|
96
|
+
sprockets-rails (2.0.0)
|
97
|
+
actionpack (>= 3.0)
|
98
|
+
activesupport (>= 3.0)
|
99
|
+
sprockets (~> 2.8)
|
100
|
+
sqlite3 (1.3.8)
|
101
|
+
thor (0.18.1)
|
102
|
+
thread_safe (0.1.3)
|
103
|
+
atomic
|
104
|
+
tilt (1.4.1)
|
105
|
+
treetop (1.4.15)
|
106
|
+
polyglot
|
107
|
+
polyglot (>= 0.3.1)
|
108
|
+
tzinfo (0.3.37)
|
109
|
+
|
110
|
+
PLATFORMS
|
111
|
+
ruby
|
112
|
+
|
113
|
+
DEPENDENCIES
|
114
|
+
appraisal (~> 0.5.2)
|
115
|
+
bundler (~> 1.3)
|
116
|
+
force_format!
|
117
|
+
jquery-rails
|
118
|
+
pry
|
119
|
+
rails (~> 4.0.0)
|
120
|
+
rake (~> 10.1)
|
121
|
+
rspec-rails (~> 2.0)
|
122
|
+
shoulda-matchers (~> 2.4)
|
123
|
+
sqlite3
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require_relative "errors"
|
2
2
|
|
3
3
|
module ForceFormat
|
4
|
-
module
|
4
|
+
module Controller
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
FORCE_FORMAT_TYPES = [:html, :js, :json, :pdf, :csv, :zip, :xml]
|
7
7
|
FORCE_FORMAT_DEFAULT_TYPES = [:html]
|
8
|
-
FORCE_FORMAT_EXCEPTION = lambda { |o| raise(
|
8
|
+
FORCE_FORMAT_EXCEPTION = lambda { |o| raise(UnknownFormat.new(o)) }
|
9
9
|
FORCE_FORMAT_WILDCARD = "*/*"
|
10
10
|
|
11
|
+
|
11
12
|
module ClassMethods
|
12
13
|
include ForceFormat::Errors
|
13
14
|
|
@@ -29,7 +30,7 @@ module ForceFormat
|
|
29
30
|
force_formats = force_format_extract_formats
|
30
31
|
return unless force_formats
|
31
32
|
unsupported = force_formats - FORCE_FORMAT_TYPES
|
32
|
-
raise
|
33
|
+
raise UnsupportedFormat.new("There is no support for #{unsupported} format") if unsupported.any?
|
33
34
|
|
34
35
|
if request.format.to_s == FORCE_FORMAT_WILDCARD and not force_format_skip_wildcard_rewrite?
|
35
36
|
request.format = :html
|
data/lib/force_format/errors.rb
CHANGED
data/lib/force_format/railtie.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require_relative "
|
2
|
-
require_relative "
|
1
|
+
require_relative "controller"
|
2
|
+
require_relative "view"
|
3
3
|
|
4
4
|
module ForceFormat
|
5
5
|
|
@@ -7,13 +7,13 @@ module ForceFormat
|
|
7
7
|
|
8
8
|
initializer "force_format.controller" do
|
9
9
|
ActiveSupport.on_load :action_controller do
|
10
|
-
include
|
10
|
+
include Controller
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
initializer "force_format.view" do
|
15
15
|
ActiveSupport.on_load :action_view do
|
16
|
-
include
|
16
|
+
include View
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/force_format/version.rb
CHANGED