separate_views 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/Rakefile +7 -0
- data/lib/separate_views/base.rb +32 -0
- data/lib/separate_views/railtie.rb +9 -0
- data/lib/separate_views/version.rb +3 -0
- data/lib/separate_views.rb +6 -0
- data/separate_views.gemspec +20 -0
- data/spec/controllers/separate_views_spec.rb +42 -0
- data/spec/dummy/app/views/pages/show.html+phone.erb +1 -0
- data/spec/dummy/app/views/pages/show.html+tablet.erb +1 -0
- data/spec/dummy/app/views/pages/show.html.erb +1 -0
- data/spec/dummy/application.rb +29 -0
- data/spec/dummy/bin/rails +5 -0
- data/spec/dummy/config.ru +1 -0
- data/spec/fixtures/user_agents.yml +8 -0
- data/spec/spec_helper.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f13f9bfb9ba20628c8e03a076bd50597d73616f
|
4
|
+
data.tar.gz: 92a2ba97dfeb887dac8fc5cd8bab99c2df6e2e1a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47dabd00465e71ba2b0a2a237817c8e52d513099e6ef7a8c207170170b74d536a79c1f82d12096cd686d6f23b39233a7ba0dbb48d010914f7a6cfebbcec69350
|
7
|
+
data.tar.gz: 964a211dea91b7ce3a8241b452f2078f3292d65d35528d6f1e81f3976928d98f5f2e388baf2220bed2a0e1f2a2689fee46ff02f119b14f5514ed43ddee848167
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 kami
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# separate_views
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/kami30k/separate_views.svg)](https://travis-ci.org/kami30k/separate_views)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/separate_views.svg)](http://badge.fury.io/rb/separate_views)
|
5
|
+
|
6
|
+
separate_views renders separate views depending on the user device type for Rails.
|
7
|
+
This feature is realized by Action Pack Variants.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'separate_views'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Once you added to Gemfile, you can use specific views depending on the user device type, such as `phone`, `tablet`, and `desktop`.
|
26
|
+
|
27
|
+
The relation between user device type and file name is as follows:
|
28
|
+
|
29
|
+
| User Device Type | File Name Example | Device Example |
|
30
|
+
| --- | --- | --- |
|
31
|
+
| Phone | show.html+phone.erb | iPhone, Android |
|
32
|
+
| Tablet | show.html+tablet.erb | iPad, Android Tablet |
|
33
|
+
| Desktop | show.html+desktop.erb | PC |
|
34
|
+
| (Default) | show.html.erb | - |
|
35
|
+
|
36
|
+
If you don't prepare specific view, Rails application renders default view (e.g. `show.html.erb`).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/kami30k/separate_views/fork )
|
41
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
42
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
43
|
+
4. Push to the branch (git push origin my-new-feature)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module SeparateViews
|
2
|
+
module Base
|
3
|
+
class << self
|
4
|
+
def included(base)
|
5
|
+
base.send :before_action, :set_variant
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def set_variant
|
12
|
+
request.variant = variant
|
13
|
+
end
|
14
|
+
|
15
|
+
def variant
|
16
|
+
case request.user_agent
|
17
|
+
when /iPhone/i
|
18
|
+
:phone
|
19
|
+
when /iPad/i
|
20
|
+
:tablet
|
21
|
+
when /Android/i && /mobile/i
|
22
|
+
:phone
|
23
|
+
when /Android/i
|
24
|
+
:tablet
|
25
|
+
when /Windows Phone/i
|
26
|
+
:phone
|
27
|
+
else
|
28
|
+
:desktop
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'separate_views/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'separate_views'
|
7
|
+
s.version = SeparateViews::VERSION
|
8
|
+
s.authors = 'kami'
|
9
|
+
s.email = 'kami30k@gmail.com'
|
10
|
+
s.homepage = 'https://github.com/kami30k/separate_views'
|
11
|
+
s.summary = 'Render separate views depending on the user device type for Rails.'
|
12
|
+
s.description = 'Render separate views depending on the user device type for Rails.'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files -z`.split("\x0")
|
16
|
+
|
17
|
+
s.add_dependency 'rails', '>= 4.1.0'
|
18
|
+
|
19
|
+
s.add_development_dependency 'rspec-rails'
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagesController, type: :controller do
|
4
|
+
render_views
|
5
|
+
|
6
|
+
let(:fixture) { YAML.load_file('spec/fixtures/user_agents.yml') }
|
7
|
+
|
8
|
+
shared_examples_for 'separate view' do
|
9
|
+
it 'should render separate view' do
|
10
|
+
user_agents.each do |user_agent|
|
11
|
+
request.env['HTTP_USER_AGENT'] = user_agent
|
12
|
+
|
13
|
+
get :show
|
14
|
+
|
15
|
+
expect(response.body).to match Regexp.escape(content)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'GET #show' do
|
21
|
+
context 'when accessed from phone' do
|
22
|
+
it_behaves_like 'separate view' do
|
23
|
+
let(:user_agents) { fixture['phone'] }
|
24
|
+
let(:content) { 'show.html+phone.erb' }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when accessed from tablet' do
|
29
|
+
it_behaves_like 'separate view' do
|
30
|
+
let(:user_agents) { fixture['tablet'] }
|
31
|
+
let(:content) { 'show.html+tablet.erb' }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when accessed from desktop' do
|
36
|
+
it_behaves_like 'separate view' do
|
37
|
+
let(:user_agents) { fixture['desktop'] }
|
38
|
+
let(:content) { 'show.html.erb' }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
show.html+phone.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
show.html+tablet.erb
|
@@ -0,0 +1 @@
|
|
1
|
+
show.html.erb
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require 'action_view/railtie'
|
5
|
+
|
6
|
+
require 'separate_views'
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
config.secret_token = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
11
|
+
config.session_store :cookie_store, key: '_dummy_session'
|
12
|
+
config.eager_load = false
|
13
|
+
config.active_support.deprecation = :log
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Dummy::Application.initialize!
|
18
|
+
|
19
|
+
Dummy::Application.routes.draw do
|
20
|
+
root 'pages#show'
|
21
|
+
end
|
22
|
+
|
23
|
+
class ApplicationController < ActionController::Base
|
24
|
+
end
|
25
|
+
|
26
|
+
class PagesController < ApplicationController
|
27
|
+
def show
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
run Rails.application
|
@@ -0,0 +1,8 @@
|
|
1
|
+
phone:
|
2
|
+
- Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4
|
3
|
+
- Mozilla/5.0 (Linux; Android 5.1; Nexus 5 Build/LMY47I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36
|
4
|
+
tablet:
|
5
|
+
- Mozilla/5.0 (iPad; CPU OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F69 Safari/600.1.4
|
6
|
+
- Mozilla/5.0 (Linux; Android 5.1; Nexus 7 Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Safari/537.36
|
7
|
+
desktop:
|
8
|
+
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/600.5.17 (KHTML, like Gecko) Version/8.0.5 Safari/600.5.17
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: separate_views
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kami
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Render separate views depending on the user device type for Rails.
|
42
|
+
email: kami30k@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- Gemfile
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/separate_views.rb
|
53
|
+
- lib/separate_views/base.rb
|
54
|
+
- lib/separate_views/railtie.rb
|
55
|
+
- lib/separate_views/version.rb
|
56
|
+
- separate_views.gemspec
|
57
|
+
- spec/controllers/separate_views_spec.rb
|
58
|
+
- spec/dummy/app/views/pages/show.html+phone.erb
|
59
|
+
- spec/dummy/app/views/pages/show.html+tablet.erb
|
60
|
+
- spec/dummy/app/views/pages/show.html.erb
|
61
|
+
- spec/dummy/application.rb
|
62
|
+
- spec/dummy/bin/rails
|
63
|
+
- spec/dummy/config.ru
|
64
|
+
- spec/fixtures/user_agents.yml
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/kami30k/separate_views
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.4.5
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Render separate views depending on the user device type for Rails.
|
90
|
+
test_files: []
|