mobile_fu-rails3 1.0.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.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mobile-fu-rails3.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,108 @@
1
+ = Mobile Fu
2
+
3
+ Want to automatically detect mobile devices that access your Rails application?
4
+ Mobile Fu allows you to do just that. People can access your site from a Palm,
5
+ Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format
6
+ of the request from :html to :mobile.
7
+
8
+ == Rails 3 Compatibility
9
+
10
+ There are already some versions of Mobile Fu that are compatible with Rails 3,
11
+ however they use old conventions for gem initialization. This is a rewrite
12
+ of the plugin using current conventions.
13
+
14
+ == Usage
15
+
16
+ Add this this one line to the controller.
17
+
18
+ class ApplicationController < ActionController::Base
19
+ has_mobile_fu
20
+ end
21
+
22
+ Once this is in place, any request that comes from a mobile device will be be
23
+ set as :mobile format. It is up to you to determine how you want to handle
24
+ these requests. It is also up to you to create the .mobile.erb versions of
25
+ your views that are to be requested.
26
+
27
+ Then add the line below to config/initializers/mime_types.rb
28
+
29
+ Mime::Type.register_alias "text/html", :mobile
30
+
31
+ If you don't want EVERY request to automatically be converted to :mobile if the device
32
+ is mobile, you can enable the plugin with:
33
+
34
+ class ApplicationController < ActionController::Base
35
+ enable_mobile_fu
36
+ end
37
+
38
+ And then in the controller that has mobile views you do:
39
+
40
+ class WhateverController < ApplicationController
41
+ before_filter :set_mobile_format
42
+ end
43
+
44
+ If you want "test mode", or to always see the mobile view use:
45
+
46
+ class WhateverController < ApplicationController
47
+ before_filter :force_mobile_format
48
+ end
49
+
50
+ I recommend that you setup a before_filter that will redirect to a specific page
51
+ depending on whether or not it is a mobile request. How can you check this?
52
+
53
+ is_mobile_device? # => Returns true or false depending on the device
54
+
55
+ You can also determine which format is currently set in by calling the following:
56
+
57
+ in_mobile_view? # => Returns true or false depending on current req. format
58
+
59
+ Also, if you want the ability to allow a user to switch between 'mobile' and
60
+ 'standard' format (:html), you can just adjust the mobile_view session variable
61
+ in a custom controller action.
62
+
63
+ session[:mobile_view] # => Set to true if request format is :mobile and false
64
+ if set to :html
65
+
66
+ So, different devices need different styling. Don't worry, we've got this
67
+ baked in to Mobile Fu.
68
+
69
+ If you are including a css or sass file via stylesheet_link_tag, all you have
70
+ to do is add _device to the name of one of your files to override your styling
71
+ for a certain device. The stylesheet that is loaded is dependant on which device
72
+ is making the request.
73
+
74
+ e.g., Accessing a page from a Blackberry.
75
+
76
+ ... stylesheet_link_tag 'mobile.css' ...
77
+
78
+ This loads mobile.css, and mobile_blackberry.css if the file exists.
79
+
80
+ Supported stylesheet override device extensions at the moment are:
81
+
82
+ blackberry
83
+ iphone (iphone,ipod)
84
+ ipad
85
+ android
86
+ mobileexplorer
87
+ nokia
88
+ palm
89
+
90
+ The stylesheet awesomeness was derived from Michael Bleigh's browserized styles:
91
+ http://www.intridea.com/2007/12/9/announcing-browserized-styles
92
+
93
+ Inspiration for Mobile Fu came from Noel Rappin's rails_iui:
94
+ http://blogs.pathf.com/agileajax/2008/05/rails-developme.html
95
+
96
+ Hopefully this should help you create some awesome mobile applications.
97
+
98
+ == Testing Mobile Interface
99
+
100
+ If you want to force the mobile interface for testing, you can either use a
101
+ mobile device emulator, or you can pass 'true' to has_mobile_fu.
102
+
103
+ class ApplicationController < ActionController::Base
104
+ has_mobile_fu(true)
105
+ end
106
+
107
+
108
+ Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,85 @@
1
+ module MobileFu
2
+ module ActionController
3
+ # These are various strings that can be found in mobile devices. Please feel free
4
+ # to add on to this list.
5
+ MOBILE_USER_AGENTS = "palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|" <<
6
+ "audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|" <<
7
+ "x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|" <<
8
+ "pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|" <<
9
+ "webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|" <<
10
+ "mobile"
11
+
12
+ module ClassMethods
13
+ # Add this to one of your controllers to use MobileFu.
14
+ #
15
+ # class ApplicationController < ActionController::Base
16
+ # has_mobile_fu
17
+ # end
18
+ #
19
+ # You can also force mobile mode by passing in 'true'
20
+ #
21
+ # class ApplicationController < ActionController::Base
22
+ # has_mobile_fu(true)
23
+ # end
24
+ def has_mobile_fu(test_mode = false)
25
+ include InstanceMethods
26
+
27
+ if test_mode
28
+ before_filter :force_mobile_format
29
+ else
30
+ before_filter :set_mobile_format
31
+ end
32
+
33
+ helper_method :is_mobile_device?
34
+ helper_method :in_mobile_view?
35
+ helper_method :is_device?
36
+ end
37
+
38
+ def enable_mobile_fu
39
+ include InstanceMethods
40
+
41
+ helper_method :is_mobile_device?
42
+ helper_method :in_mobile_view?
43
+ helper_method :is_device?
44
+ end
45
+ end
46
+
47
+ module InstanceMethods
48
+ # Forces the request format to be :mobile
49
+ def force_mobile_format
50
+ unless request.xhr?
51
+ session[:mobile_view] ||= true
52
+ request.format = :mobile
53
+ end
54
+ end
55
+
56
+ # Determines the request format based on whether the device is mobile or if
57
+ # the user has opted to use either the 'Standard' view or 'Mobile' view.
58
+ def set_mobile_format
59
+ debugger
60
+ if request.format.html? and is_mobile_device? and not request.xhr?
61
+ session[:mobile_view] ||= true
62
+ request.format = session[:mobile_view] ? :mobile : :html
63
+ end
64
+ end
65
+
66
+ # Returns either true or false depending on whether or not the format of the
67
+ # request is either :mobile or not.
68
+ def in_mobile_view?
69
+ request.format.to_sym == :mobile
70
+ end
71
+
72
+ # Returns either true or false depending on whether or not the user agent of
73
+ # the device making the request is matched to a device in our regex.
74
+ def is_mobile_device?
75
+ !!(request.user_agent.downcase =~ Regexp.new(MobileFu::ActionController::MOBILE_USER_AGENTS))
76
+ end
77
+
78
+ # Can check for a specific user agent
79
+ # e.g., is_device?('iphone') or is_device?(:mobileexplorer)
80
+ def is_device?(type)
81
+ request.user_agent.downcase.include?(type.to_s.downcase)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,26 @@
1
+ module MobileFu
2
+ module ActionView
3
+ module HelperMethods
4
+ ACCEPTABLE_TYPES = [:mobile, :basic]
5
+
6
+ def mobile_xhtml_doctype(type = :mobile, version = '1.0')
7
+ raise Exception.new("MobileFu: XHTML DOCTYPE type must either be ':mobile' or ':basic'") unless ACCEPTABLE_TYPES.include?(type)
8
+ raise Exception.new("MobileFu: XHTML DOCTYPE version must be in the format of '1.0' or '1.1', etc.") unless version.include?('.')
9
+
10
+ doc_type = "<?xml version=\"1.0\" charset=\"UTF-8\" ?>\n"
11
+ doc_type += "<!DOCTYPE html PUBLIC "
12
+ doc_type += case type
13
+ when :mobile
14
+ "\"-//WAPFORUM//DTD XHTML Mobile #{version}//EN\" \"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile#{version.gsub('.','')}.dtd\">"
15
+ when :basic
16
+ "\"-//W3C//DTD XHTML Basic #{version}//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic#{version.gsub('.','')}.dtd\">"
17
+ end
18
+ doc_type
19
+ end
20
+
21
+ def js_enabled_mobile_device?
22
+ is_device?('iphone') or is_device?('ipod') or is_device?('ipad') or is_device?('mobileexplorer') or is_device?('android')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,71 @@
1
+ # Copyright (c) 2008 Brendan G. Lim (brendan@intridea.com)
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.
21
+
22
+ module MobileFu
23
+ module ActionView
24
+ module MobilizedStyles
25
+ # This logic was taken from Michael Bleigh's browserized styles
26
+ # with modification to work for mobile browsers.
27
+ def user_agent_device_name
28
+ @user_agent_device_name ||= begin
29
+ ua = request.user_agent
30
+ return nil if ua.nil?
31
+ ua.downcase!
32
+
33
+ if ua.index('mobileexplorer') or ua.index('windows ce')
34
+ 'mobileexplorer'
35
+ elsif ua.index('blackberry')
36
+ 'blackberry'
37
+ elsif ua.index('iphone') or ua.index('ipod')
38
+ 'iphone'
39
+ elsif ua.index('ipad')
40
+ 'ipad'
41
+ elsif ua.index('android')
42
+ 'android'
43
+ elsif ua.index('nokia')
44
+ 'nokia'
45
+ elsif ua.index('palm')
46
+ 'palm'
47
+ end
48
+ end
49
+ end
50
+
51
+ def stylesheet_link_tag_with_mobilization(*sources)
52
+ mobilized_sources = Array.new
53
+ sources.each do |source|
54
+ subbed_source = source.to_s.gsub('.css', '')
55
+
56
+ possible_sources = ["#{subbed_source.to_s}_#{user_agent_device_name}"]
57
+
58
+ mobilized_sources << source
59
+
60
+ for possible_source in possible_sources
61
+ path = File.join(config.stylesheets_dir,"#{possible_source}.css")
62
+ sass_path = File.join(config.stylesheets_dir,"sass","#{possible_source}.sass")
63
+ mobilized_sources << possible_source if File.exist?(path) || File.exist?(sass_path)
64
+ end
65
+ end
66
+
67
+ stylesheet_link_tag_without_mobilization(*mobilized_sources)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,19 @@
1
+ require 'mobile_fu/controller_methods'
2
+ require 'mobile_fu/helper_methods'
3
+ require 'mobile_fu/mobilized_styles'
4
+
5
+ module MobileFu
6
+ class Railtie < Rails::Railtie
7
+ initializer 'mobile_fu.initialize' do
8
+ ActiveSupport.on_load(:action_controller) do
9
+ extend MobileFu::ActionController::ClassMethods
10
+ end
11
+
12
+ ActiveSupport.on_load(:action_view) do
13
+ include MobileFu::ActionView::HelperMethods
14
+ include MobileFu::ActionView::MobilizedStyles
15
+ alias_method_chain :stylesheet_link_tag, :mobilization
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require 'mobile_fu/railtie.rb'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "mobile_fu-rails3"
6
+ s.version = "1.0.0"
7
+ s.authors = ["Jori Hardman"]
8
+ s.email = ["jorihardman@gmail.com"]
9
+ s.homepage = "https://github.com/jyro215/mobile_fu-rails3"
10
+ s.summary = "Easily handling of mobile requests in action controller."
11
+ s.description = "This is a rewrite of the mobile-fu gem using Rails 3 railsties."
12
+
13
+ s.rubyforge_project = "mobile_fu-rails3"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency("rails", ">= 3.0.0")
21
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobile_fu-rails3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jori Hardman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-23 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &2168726260 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2168726260
26
+ description: This is a rewrite of the mobile-fu gem using Rails 3 railsties.
27
+ email:
28
+ - jorihardman@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .DS_Store
34
+ - .gitignore
35
+ - Gemfile
36
+ - README.rdoc
37
+ - Rakefile
38
+ - lib/.DS_Store
39
+ - lib/mobile_fu-rails3.rb
40
+ - lib/mobile_fu/controller_methods.rb
41
+ - lib/mobile_fu/helper_methods.rb
42
+ - lib/mobile_fu/mobilized_styles.rb
43
+ - lib/mobile_fu/railtie.rb
44
+ - mobile_fu-rails3.gemspec
45
+ has_rdoc: true
46
+ homepage: https://github.com/jyro215/mobile_fu-rails3
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project: mobile_fu-rails3
66
+ rubygems_version: 1.6.2
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Easily handling of mobile requests in action controller.
70
+ test_files: []