acts-as-mobile 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_WITHOUT: ""
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ *.gem
21
+
22
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://gemcutter.org"
2
+
3
+ group :test do
4
+ gem 'shoulda'
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eric Saxby
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,40 @@
1
+ = acts-as-mobile
2
+
3
+ Adds mobile-specific methods to ActionController and ActionView.
4
+
5
+ iPhone requests should reroute to format :mobile. iPad requests will remain :html,
6
+ but can be tested for using the ipad? helper method
7
+
8
+ == Usage
9
+
10
+ Gemfile
11
+
12
+ gem 'acts-as-mobile', :require => 'acts_as_mobile'
13
+
14
+ Controller
15
+
16
+ class MyController < ActionController::Base
17
+ acts_as_mobile
18
+
19
+ def index
20
+ puts "rendering mobile" if mobile?
21
+ puts "rendering ipad" if ipad?
22
+
23
+ respond_to do |format|
24
+ format.html
25
+ format.mobile
26
+ end
27
+ end
28
+ end
29
+
30
+ View
31
+
32
+ <html>
33
+ <body>
34
+ <div><%= "Rendered from iPad" if ipad? %></div>
35
+ </body>
36
+ </html>
37
+
38
+ == Copyright
39
+
40
+ Copyright (c) 2010 Eric Saxby. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "acts-as-mobile"
8
+ gem.summary = %Q{Adds acts_as_mobile_controller to ActionController}
9
+ gem.description = %Q{Adds functionality to ActionPack to allow quick addition of mobile views.}
10
+ gem.email = "sax@litp.org"
11
+ gem.homepage = "http://github.com/sax/acts-as-mobile"
12
+ gem.authors = ["Eric Saxby"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "acts-as-mobile #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{acts-as-mobile}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Saxby"]
12
+ s.date = %q{2010-04-09}
13
+ s.description = %q{Adds functionality to ActionPack to allow quick addition of mobile views.}
14
+ s.email = %q{sax@litp.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".bundle/config",
21
+ ".document",
22
+ ".gitignore",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "acts-as-mobile.gemspec",
29
+ "init.rb",
30
+ "lib/acts-as-mobile.rb",
31
+ "lib/acts_as_mobile/railtie.rb",
32
+ "rails/init.rb",
33
+ "test/helper.rb",
34
+ "test/test_acts-as-mobile.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/sax/acts-as-mobile}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.6}
40
+ s.summary = %q{Adds acts_as_mobile_controller to ActionController}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_acts-as-mobile.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ end
58
+ end
59
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ puts "ActsAsMobile only works within Rails 3 applications"
@@ -0,0 +1,42 @@
1
+ module ActsAsMobile
2
+ require 'acts_as_mobile/railtie' if defined?(Rails)
3
+ end
4
+
5
+ module ActionController
6
+ class Base
7
+ class << self
8
+ def acts_as_mobile_controller(options = {})
9
+ @@mobile_options = options
10
+ before_filter :set_mobile_format
11
+ helper_method :mobile?, :ipad?
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def set_mobile_format
18
+ set_mobile
19
+ set_ipad
20
+ end
21
+
22
+ def set_mobile
23
+ request.format = :mobile if reroutable? && mobile? && !ipad?
24
+ end
25
+
26
+ def set_ipad
27
+ request.format = :html if reroutable? && ipad?
28
+ end
29
+
30
+ def mobile?
31
+ @mobile ||= request.user_agent =~ /(Mobile\/.+Safari)/
32
+ end
33
+
34
+ def ipad?
35
+ @ipad ||= request.user_agent =~ /(iPad)/
36
+ end
37
+
38
+ def reroutable?
39
+ !request.headers['Accept'].include?("text/javascript") && !request.xhr?
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ require 'acts-as-mobile'
2
+
3
+ module ActsAsMobile
4
+ class Railtie < Rails::Railtie
5
+ initializer "railtie.configure_rails_initialization" do
6
+ Mime::Type.register_alias 'text/html', :mobile
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ $:.push "rails/activesupport/lib"
2
+ $:.push "rails/actionpack/lib"
3
+
4
+ require 'action_controller'
5
+ require 'acts-as-mobile'
6
+ require 'acts_as_mobile/railtie'
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'acts-as-mobile'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestActsAsMobile < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts-as-mobile
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Eric Saxby
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-09 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: Adds functionality to ActionPack to allow quick addition of mobile views.
33
+ email: sax@litp.org
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .bundle/config
43
+ - .document
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - acts-as-mobile.gemspec
51
+ - init.rb
52
+ - lib/acts-as-mobile.rb
53
+ - lib/acts_as_mobile/railtie.rb
54
+ - rails/init.rb
55
+ - test/helper.rb
56
+ - test/test_acts-as-mobile.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/sax/acts-as-mobile
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.6
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Adds acts_as_mobile_controller to ActionController
87
+ test_files:
88
+ - test/helper.rb
89
+ - test/test_acts-as-mobile.rb