sinatra-iphone-views 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +21 -0
- data/Readme.txt +30 -0
- data/VERSION +1 -0
- data/lib/sinatra/iphone_views.rb +16 -0
- data/spec/dummy.rb +9 -0
- data/spec/iphone_views_spec.rb +26 -0
- data/spec/views/iphone/test.haml +2 -0
- data/spec/views/test.haml +2 -0
- metadata +102 -0
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "sinatra-iphone-views"
|
8
|
+
gem.summary = "Detects an iPhone/iPod browser and renders templates in views/iphone automatically."
|
9
|
+
gem.description = "Detects an iPhone/iPod browser and renders templates in views/iphone automatically."
|
10
|
+
gem.email = 'julio.ody@gmail.com'
|
11
|
+
gem.homepage = 'http://github.com/juliocesar/sinatra-iphone-views'
|
12
|
+
gem.authors = ['Julio Cesar']
|
13
|
+
gem.add_dependency 'sinatra', '>= 1.0.a'
|
14
|
+
gem.add_development_dependency 'rspec', '>= 1.3.0'
|
15
|
+
gem.add_development_dependency 'rack-test', '>= 0.5.3'
|
16
|
+
gem.add_development_dependency 'haml', '2.2.17'
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
21
|
+
end
|
data/Readme.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# sinatra-iphone-views
|
2
|
+
|
3
|
+
Detects an iPhone/iPod browser and renders templates in views/iphone automatically.
|
4
|
+
|
5
|
+
Why is that cool? Because iPhone-enabled routes look exactly like any other route. Like so:
|
6
|
+
|
7
|
+
get '/test' do
|
8
|
+
haml :test
|
9
|
+
end
|
10
|
+
|
11
|
+
The above will render views/iphone/test.haml from an iPhone, and views/test.haml
|
12
|
+
from anywhere else.
|
13
|
+
|
14
|
+
Now why that is NOT cool? Because it relies on disabling template caching, and will
|
15
|
+
have a performance impact that may or may not be acceptable for your application. Quite
|
16
|
+
frankly, I haven't benchmarked any differences, but I'm inclined to believe it's
|
17
|
+
not significant not even to a medium sized app.
|
18
|
+
|
19
|
+
# Installation
|
20
|
+
|
21
|
+
Make sure you got http://gemcutter.org in your gem sources. Then simply
|
22
|
+
|
23
|
+
$ sudo gem install sinatra-iphone-views
|
24
|
+
|
25
|
+
# Specs
|
26
|
+
|
27
|
+
Just run
|
28
|
+
|
29
|
+
$ spec spec/iphone_views_spec.rb
|
30
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module IPhoneViews
|
3
|
+
def self.registered(app)
|
4
|
+
app.enable :reload_templates
|
5
|
+
app.set :original_views, Sinatra::Application.views
|
6
|
+
app.set :iphone_views, File.join(Sinatra::Application.views, 'iphone')
|
7
|
+
app.before do
|
8
|
+
# http://lachstock.com.au/code/mobile-pages-in-sinatra/
|
9
|
+
iphone = [/AppleWebKit.*Mobile/, /Android.*AppleWebKit/].any? { |r| request.env['HTTP_USER_AGENT'] =~ r }
|
10
|
+
options.views = iphone ? Sinatra::Application.iphone_views : Sinatra::Application.original_views
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
register IPhoneViews
|
15
|
+
end
|
16
|
+
|
data/spec/dummy.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'dummy')
|
2
|
+
gem 'rspec', '1.3.0'; require 'spec'
|
3
|
+
gem 'rack-test', '0.5.3'; require 'rack/test'
|
4
|
+
require 'spec/interop/test'
|
5
|
+
|
6
|
+
set :environment, :test
|
7
|
+
set :run, :false
|
8
|
+
set :logging, false
|
9
|
+
|
10
|
+
def app
|
11
|
+
@app ||= Sinatra::Application
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'a Sinatra app' do
|
15
|
+
include Rack::Test::Methods
|
16
|
+
it 'should render views/iphone/test.haml when an iPhone accesses the page' do
|
17
|
+
get '/test', {}, 'HTTP_USER_AGENT' => 'AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3'
|
18
|
+
last_response.body.should =~ /In ur iPhone/
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should let views/test.haml render normally when NOT accessed from an iPhone' do
|
22
|
+
get '/test'
|
23
|
+
last_response.body.should =~ /In ur browser/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-iphone-views
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julio Cesar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-09 00:00:00 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sinatra
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.a
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack-test
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.5.3
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: haml
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.2.17
|
54
|
+
version:
|
55
|
+
description: Detects an iPhone/iPod browser and renders templates in views/iphone automatically.
|
56
|
+
email: julio.ody@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
files:
|
64
|
+
- Rakefile
|
65
|
+
- Readme.txt
|
66
|
+
- VERSION
|
67
|
+
- lib/sinatra/iphone_views.rb
|
68
|
+
- spec/dummy.rb
|
69
|
+
- spec/iphone_views_spec.rb
|
70
|
+
- spec/views/iphone/test.haml
|
71
|
+
- spec/views/test.haml
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/juliocesar/sinatra-iphone-views
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --charset=UTF-8
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Detects an iPhone/iPod browser and renders templates in views/iphone automatically.
|
100
|
+
test_files:
|
101
|
+
- spec/dummy.rb
|
102
|
+
- spec/iphone_views_spec.rb
|