separation 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc6c669081f61a11b900aa4d003b084bd1e1a8af
4
+ data.tar.gz: 2e7e14ddd6d96d024b577f4e9f72c8493135be78
5
+ SHA512:
6
+ metadata.gz: 2f68347ca806212ca21512b78b477be13d1f94cc4e703ba176c8ef43138cb397e0ab9edce10ffeeb4538ec54e600b45662c1c9b7cc8a41b1b724a6d3f202701a
7
+ data.tar.gz: 22b370cddc98e1840304ec73cd7832b8d56d7cf7282e98644d98239fba0a54fb2edafcf8cb00f16a789351feaf267b0331d9db93b68cd23fb30a1cfc7a1cfb09
@@ -0,0 +1,6 @@
1
+ .bundle/
2
+ pkg/
3
+ spec/dummy/log/
4
+ spec/dummy/tmp/
5
+ vendor/
6
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -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.
@@ -0,0 +1,44 @@
1
+ # Separation
2
+
3
+ [![Build Status](https://travis-ci.org/kami-zh/separation.svg)](https://travis-ci.org/kami-zh/separation)
4
+ [![Gem Version](https://badge.fury.io/rb/separation.svg)](http://badge.fury.io/rb/separation)
5
+
6
+ Separation 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 'separation'
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/kami-zh/separation/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
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ require 'separation/version'
2
+ require 'separation/base'
3
+ require 'separation/railtie' if defined?(Rails)
@@ -0,0 +1,32 @@
1
+ module Separation
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,9 @@
1
+ module Separation
2
+ class Railtie < Rails::Railtie
3
+ initializer 'separation' do
4
+ ActiveSupport.on_load :action_controller do
5
+ ActionController::Base.send :include, Separation::Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Separation
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'separation/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'separation'
7
+ s.version = Separation::VERSION
8
+ s.authors = 'kami'
9
+ s.email = 'hiroki.zenigami@gmail.com'
10
+ s.homepage = 'https://github.com/kami-zh/separation'
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,28 @@
1
+ $:.unshift File.expand_path('../../../lib', __FILE__)
2
+
3
+ require 'action_controller/railtie'
4
+ require 'action_view/railtie'
5
+ require 'separation'
6
+
7
+ module Dummy
8
+ class Application < Rails::Application
9
+ config.secret_token = 'abcdefghijklmnopqrstuvwxyz0123456789'
10
+ config.session_store :cookie_store, key: '_dummy_session'
11
+ config.eager_load = false
12
+ config.active_support.deprecation = :log
13
+ end
14
+ end
15
+
16
+ Dummy::Application.initialize!
17
+
18
+ Dummy::Application.routes.draw do
19
+ root 'pages#show'
20
+ end
21
+
22
+ class ApplicationController < ActionController::Base
23
+ end
24
+
25
+ class PagesController < ApplicationController
26
+ def show
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ APP_PATH = File.expand_path('../../application', __FILE__)
4
+
5
+ require 'rails/commands'
@@ -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
@@ -0,0 +1,2 @@
1
+ require 'dummy/application'
2
+ require 'rspec/rails'
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: separation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - kami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-17 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: hiroki.zenigami@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/separation.rb
53
+ - lib/separation/base.rb
54
+ - lib/separation/railtie.rb
55
+ - lib/separation/version.rb
56
+ - separation.gemspec
57
+ - spec/controllers/separation_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/kami-zh/separation
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.5.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Render separate views depending on the user device type for Rails.
90
+ test_files: []