pax_global_header00006660000000000000000000000064121217000600014477gustar00rootroot0000000000000052 comment=b7a4401258bb4a9d6c319c706f5ac9699ad2a3f7 ruby-mobile-fu-1.1.1/000077500000000000000000000000001212170006000143355ustar00rootroot00000000000000ruby-mobile-fu-1.1.1/CHANGELOG000066400000000000000000000066131212170006000155550ustar00rootroot00000000000000commit a46e0d5ff0a95407bbd8f3437a372ced53d90c9b Author: Brendan G. Lim Date: Sat Dec 20 20:59:49 2008 -0500 Added a helper method to determine if a device is JavaScript enabled and one to output the XHTML Mobile 1.0 doctype commit f4b29b2e2c68a79b8904dddb7a91efd4341540ee Author: Brendan G. Lim Date: Sun Sep 21 21:39:10 2008 -0400 Fixes issue with 'in_mobile_view' instead of 'is_mobile_view' helper method commit 29e8e8b407dd3dc8d5f3248183223d11c6a78843 Author: Brendan G. Lim Date: Wed Sep 10 12:51:12 2008 -0400 Updating CHANGELOG commit 0aac5bd7f0d2f71e6af7b144a04a18dad9f5aca5 Author: Brendan G. Lim Date: Wed Sep 10 12:50:50 2008 -0400 Styling overrides for iPods commit f30c97c794ba74e737856aa9226328469c8395b6 Author: Brendan G. Lim Date: Mon Sep 8 00:07:27 2008 -0400 Adding in some comments to the latest changes commit 78dae861e46d383356d7e4d6dfdaefbf60072e27 Author: Brendan G. Lim Date: Mon Sep 8 00:06:16 2008 -0400 Updating README commit 1a66ccd2142e387f6d3138acb688a58df4687fcd Author: Brendan G. Lim Date: Mon Sep 8 00:05:48 2008 -0400 Adding in a helper method to check for a specific mobile device and adding in 'ipod' to the list of mobile user agents commit cbb26fff3287e16a757ee2aed2dcc8e98cbfb369 Author: Brendan G. Lim Date: Fri Aug 22 22:16:19 2008 -0400 Updating the CHANGELOG commit ee49945b593b1c55bf546da1d595a0941d071f94 Author: Brendan G. Lim Date: Fri Aug 22 22:16:00 2008 -0400 Updating README commit 02c12a8563466f7cef6aba8e53915dc2efec908c Author: Brendan G. Lim Date: Mon Aug 18 16:08:51 2008 -0400 Adding in support for Android commit 2dffa5958905c0419288d03a0650127a0734b41a Author: Brendan G. Lim Date: Sat Jul 26 14:08:56 2008 -0400 Adding in other phone user agents, including some Japanese and French manufacturers commit e8f9f1a9c2e668d639690f4f1beb4f701f742cfa Author: Brendan G. Lim Date: Fri Jul 18 11:15:52 2008 -0400 Adding in CHANGELOG commit a3122b40c0c722b2942e9cb5341614d0e0d834a5 Author: Brendan G. Lim Date: Fri Jul 18 11:14:35 2008 -0400 Changes to README commit 64a24e36b6a770757963eb2d961262fb8a14ec1b Author: Brendan G. Lim Date: Fri Jul 18 11:10:40 2008 -0400 Quick fix commit 116fa5b7c1168471cf56cb9961b98f0b73fc3308 Author: Brendan G. Lim Date: Fri Jul 18 10:04:41 2008 -0400 Fixed issue with mobile view session variable getting set incorrectly, when forcing mobile format commit d172665c9d0458801fd672076e269a3c0ee9d80d Author: Brendan G. Lim Date: Fri Jul 18 01:04:19 2008 -0400 Adding in more MIT license goodness commit a6c947d684d2d9abdbe354dc1ea757f23cd5a633 Author: Brendan G. Lim Date: Fri Jul 18 01:00:55 2008 -0400 Change to the README commit dad4f4db1f3cb816283069a91c01982c953ff8a5 Author: Brendan G. Lim Date: Fri Jul 18 01:00:16 2008 -0400 Change to the README commit c5ec9de6ef19e48a66917d8f6f3a59771295765b Author: Brendan G. Lim Date: Fri Jul 18 00:59:36 2008 -0400 Releasing Mobile Fu to the world ruby-mobile-fu-1.1.1/MIT-LICENSE000066400000000000000000000020621212170006000157710ustar00rootroot00000000000000Copyright (c) 2008 Brendan G. Lim, Intridea, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-mobile-fu-1.1.1/README.md000066400000000000000000000075171212170006000156260ustar00rootroot00000000000000Mobile Fu ========= Want to automatically detect mobile devices that access your Rails application? Mobile Fu allows you to do just that. People can access your site from a Palm, Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile or :tablet. Installation ------------ Simply add `gem 'mobile-fu'` to your Gemfile and run bundle install. Usage ----- Add this this one line to the controller. ```ruby class ApplicationController < ActionController::Base has_mobile_fu end ``` Once this is in place, any request that comes from a mobile device will be be set as :mobile format. It is up to you to determine how you want to handle these requests. It is also up to you to create the .mobile.erb versions of your views that are to be requested. If you do not want to set the format to :mobile or :tablet and only use the helper functions, pass false as an argument. ```ruby class ApplicationController < ActionController::Base has_mobile_fu false end ``` Mobile Fu automatically adds a new `:mobile` and `:tablet` to `text/html` mime type alias for Rails apps. If you already have a custom `:mobile` alias registered in `config/initializers/mime_types.rb`, you can remove that. I recommend that you setup a before_filter that will redirect to a specific page depending on whether or not it is a mobile request. How can you check this? ```ruby is_mobile_device? # => Returns true or false depending on the device or is_tablet_device? # => Returns true if the device is a tablet ``` You can also determine which format is currently set in by calling the following: ```ruby in_mobile_view? # => Returns true or false depending on current req. format or in_tablet_view? # => Returns true if the current req. format is for tablet view ``` Also, if you want the ability to allow a user to switch between 'mobile' and 'standard' format (:html), you can just adjust the mobile_view session variable in a custom controller action. ```ruby session[:mobile_view] # => Set to true if request format is :mobile and false if set to :html session[:tablet_view] # => Set to true if request format is :tablet and false if set to :html ``` So, different devices need different styling. Don't worry, we've got this baked in to Mobile Fu. If you are including a css or sass file via `stylesheet_link_tag`, all you have to do is add _device to the name of one of your files to override your styling for a certain device. The stylesheet that is loaded is dependant on which device is making the request. e.g., Accessing a page from a Blackberry. ```ruby stylesheet_link_tag 'mobile.css' ``` This loads mobile.css, and mobile_blackberry.css if the file exists. Supported stylesheet override device extensions at the moment are: * blackberry * iphone (iphone,ipod) * ipad * android * mobileexplorer * nokia * palm The stylesheet awesomeness was derived from [Michael Bleigh's browserized styles](http://www.intridea.com/2007/12/9/announcing-browserized-styles) Inspiration for Mobile Fu came from [Noel Rappin's rails_iui](http://blogs.pathf.com/agileajax/2008/05/rails-developme.html) Hopefully this should help you create some awesome mobile applications. Testing Mobile Interface ------------------------ If you want to force the mobile interface for testing, you can either use a mobile device emulator, or you can call `force_mobile_format` in a before filter. ```ruby class ApplicationController < ActionController::Base has_mobile_fu before_filter :force_mobile_format end ``` You can also force the tablet view by calling `force_tablet_format` instead ```ruby class ApplicationController < ActionController::Base has_mobile_fu before_filter :force_tablet_format end ``` Copyright (c) 2008 Brendan G. Lim, Intridea, Inc., released under the MIT license ruby-mobile-fu-1.1.1/lib/000077500000000000000000000000001212170006000151035ustar00rootroot00000000000000ruby-mobile-fu-1.1.1/lib/mobile-fu.rb000066400000000000000000000126671212170006000173230ustar00rootroot00000000000000require 'rails' require 'rack/mobile-detect' module MobileFu autoload :Helper, 'mobile-fu/helper' class Railtie < Rails::Railtie initializer "mobile-fu.configure" do |app| app.config.middleware.use Rack::MobileDetect end if Rails::VERSION::MAJOR >= 3 initializer "mobile-fu.action_controller" do |app| ActiveSupport.on_load :action_controller do include ActionController::MobileFu end end initializer "mobile-fu.action_view" do |app| ActiveSupport.on_load :action_view do include MobileFu::Helper alias_method_chain :stylesheet_link_tag, :mobilization end end end Mime::Type.register_alias "text/html", :mobile Mime::Type.register_alias "text/html", :tablet end end module ActionController module MobileFu # These are various strings that can be found in tablet devices. Please feel free # to add on to this list. TABLET_USER_AGENTS = 'ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle|honeycomb' def self.included(base) base.extend ClassMethods end module ClassMethods # Add this to one of your controllers to use MobileFu. # # class ApplicationController < ActionController::Base # has_mobile_fu # end # # If you don't want mobile_fu to set the request format automatically, # you can pass false here. # # class ApplicationController < ActionController::Base # has_mobile_fu false # end # def has_mobile_fu(set_request_format = true) include ActionController::MobileFu::InstanceMethods before_filter :set_request_format if set_request_format helper_method :is_mobile_device? helper_method :is_tablet_device? helper_method :in_mobile_view? helper_method :in_tablet_view? helper_method :is_device? helper_method :mobile_device end # Add this to your controllers to prevent the mobile format from being set for specific actions # class AwesomeController < ApplicationController # has_no_mobile_fu_for :index # # def index # # Mobile format will not be set, even if user is on a mobile device # end # # def show # # Mobile format will be set as normal here if user is on a mobile device # end # end def has_no_mobile_fu_for(*actions) @mobile_exempt_actions = actions end end module InstanceMethods def set_request_format(force_mobile = false) force_mobile ? force_mobile_format : set_mobile_format end alias :set_device_type :set_request_format # Forces the request format to be :mobile def force_mobile_format unless request.xhr? request.format = :mobile session[:mobile_view] = true if session[:mobile_view].nil? end end # Forces the request format to be :tablet def force_tablet_format unless request.xhr? request.format = :tablet session[:tablet_view] = true if session[:tablet_view].nil? end end # Determines the request format based on whether the device is mobile or if # the user has opted to use either the 'Standard' view or 'Mobile' view or # 'Tablet' view. def set_mobile_format if !mobile_exempt? && is_mobile_device? && !request.xhr? request.format = :mobile unless session[:mobile_view] == false session[:mobile_view] = true if session[:mobile_view].nil? elsif !mobile_exempt? && is_tablet_device? && !request.xhr? request.format = :tablet unless session[:tablet_view] == false session[:tablet_view] = true if session[:tablet_view].nil? end end # Returns either true or false depending on whether or not the format of the # request is either :mobile or not. def in_mobile_view? return false unless request.format request.format.to_sym == :mobile end # Returns either true or false depending on whether or not the format of the # request is either :tablet or not. def in_tablet_view? return false unless request.format request.format.to_sym == :tablet end # Returns either true or false depending on whether or not the user agent of # the device making the request is matched to a device in our regex. def is_tablet_device? !!(request.user_agent.to_s.downcase =~ Regexp.new(ActionController::MobileFu::TABLET_USER_AGENTS)) end def is_mobile_device? !is_tablet_device? && !!mobile_device end def mobile_device request.headers['X_MOBILE_DEVICE'] end # Can check for a specific user agent # e.g., is_device?('iphone') or is_device?('mobileexplorer') def is_device?(type) request.user_agent.to_s.downcase.include? type.to_s.downcase end # Returns true if current action isn't supposed to use mobile format # See #has_no_mobile_fu_for def mobile_exempt? self.class.instance_variable_get("@mobile_exempt_actions").try(:include?, params[:action].to_sym) end end end end if Rails::VERSION::MAJOR < 3 ActionController::Base.send :include, ActionController::MobileFu ActionView::Base.send :include, MobileFu::Helper ActionView::Base.send :alias_method_chain, :stylesheet_link_tag, :mobilization end ruby-mobile-fu-1.1.1/lib/mobile-fu/000077500000000000000000000000001212170006000167625ustar00rootroot00000000000000ruby-mobile-fu-1.1.1/lib/mobile-fu/helper.rb000066400000000000000000000034421212170006000205710ustar00rootroot00000000000000module MobileFu module Helper def js_enabled_mobile_device? is_device?('iphone') || is_device?('ipod') || is_device?('ipad') || is_device?('mobileexplorer') || is_device?('android') end def stylesheet_link_tag_with_mobilization(*sources) mobilized_sources = Array.new # Figure out where stylesheets live, which differs depending if the asset # pipeline is used or not. stylesheets_dir = config.stylesheets_dir # Rails.root/public/stylesheets # Look for mobilized stylesheets in the app/assets path if asset pipeline # is enabled, because public/stylesheets will be missing in development # mode without precompiling assets first, and may also contain multiple # stylesheets with similar names because of checksumming during # precompilation. if Rails.application.config.respond_to?(:assets) # don't break pre-rails3.1 if Rails.application.config.assets.enabled stylesheets_dir = File.join(Rails.root, 'app/assets/stylesheets/') end end device_names = respond_to?(:is_mobile_device?) && is_mobile_device? ? ['mobile', mobile_device.downcase] : [] sources.each do |source| mobilized_sources << source device_names.compact.each do |device_name| # support ERB and/or SCSS extensions (e.g., mobile.css.erb, mobile.css.scss.erb) possible_source = source.to_s.sub(/\.css.*$/, '') + "_#{device_name}" mobilized_files = Dir.glob(File.join(stylesheets_dir, "#{possible_source}.css*")).map { |f| f.sub(stylesheets_dir, '') } mobilized_sources += mobilized_files.map { |f| f.sub(/\.css.*/, '') } end end stylesheet_link_tag_without_mobilization *mobilized_sources end end end ruby-mobile-fu-1.1.1/lib/mobile-fu/version.rb000066400000000000000000000000501212170006000207670ustar00rootroot00000000000000module MobileFu VERSION = "1.1.1" end ruby-mobile-fu-1.1.1/metadata.yml000066400000000000000000000062201212170006000166400ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: mobile-fu version: !ruby/object:Gem::Version version: 1.1.1 prerelease: platform: ruby authors: - Brendan Lim - Ben Langfeld autorequire: bindir: bin cert_chain: [] date: 2012-11-15 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rack-mobile-detect requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rdoc requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: Want to automatically detect mobile devices that access your Rails application? Mobile Fu allows you to do just that. People can access your site from a Palm, Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile. email: - brendangl@gmail.com, ben@langfeld.me executables: [] extensions: [] extra_rdoc_files: [] files: - CHANGELOG - MIT-LICENSE - README.md - lib/mobile-fu.rb - lib/mobile-fu/helper.rb - lib/mobile-fu/version.rb - spec/mobilized_styles_spec.rb - spec/spec_helper.rb homepage: https://github.com/benlangfeld/mobile-fu licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: -851634981796251436 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: -851634981796251436 requirements: [] rubyforge_project: mobile-fu rubygems_version: 1.8.24 signing_key: specification_version: 3 summary: Automatically detect mobile requests from mobile devices in your Rails application. test_files: - spec/mobilized_styles_spec.rb - spec/spec_helper.rb ruby-mobile-fu-1.1.1/spec/000077500000000000000000000000001212170006000152675ustar00rootroot00000000000000ruby-mobile-fu-1.1.1/spec/mobilized_styles_spec.rb000066400000000000000000000020311212170006000222030ustar00rootroot00000000000000require 'spec_helper' describe MobileFu::MobilizedStyles do before(:each) do @view = mock :ActionView @request = mock :ActionRequest @view.extend MobileFu::MobilizedStyles @view.stub!(:request).and_return @request @request.stub! :user_agent end def ua(str) @request.stub!(:user_agent).and_return str end it "will include a mobilized css file if it recognizes a string in the user agent" do ua "iphone" File.should_receive(:exist?).with("stylesheets/style_iphone.css").and_return true @view.should_receive(:stylesheet_link_tag).with "style", "style_iphone" @view.stylesheet_link_tag_with_mobilization "style" end it "includes mobiziled css files whether or not the original call to stylesheet_link_tag used a file extension" do ua "blackberry" File.should_receive(:exist?).with("stylesheets/style_blackberry.css").and_return true @view.should_receive(:stylesheet_link_tag).with "style.css", "style_blackberry" @view.stylesheet_link_tag_with_mobilization "style.css" end endruby-mobile-fu-1.1.1/spec/spec_helper.rb000066400000000000000000000000241212170006000201010ustar00rootroot00000000000000require 'mobile-fu'