mobile-fu-1.3.1/0000755000004100000410000000000012271542544013431 5ustar www-datawww-datamobile-fu-1.3.1/Rakefile0000644000004100000410000000235512271542544015103 0ustar www-datawww-datarequire 'bundler/gem_tasks' require 'rake/testtask' require 'json' require 'httparty' MOBILE_DETECT_JSON = 'https://raw.github.com/serbanghita/Mobile-Detect/master/Mobile_Detect.json' TABLET_FILE = 'lib/mobile-fu/tablet.rb' task :default => [:test] Rake::TestTask.new do |t| t.libs.push 'lib' t.test_files = FileList['spec/*_spec.rb', 'spec/mobile-fu/*_spec.rb'] t.verbose = true end desc "Pull in data from Mobile Detect" task :pull_mobile_detect_data do # call out to Mobile Detect to get the data content = HTTParty.get(MOBILE_DETECT_JSON).body # build a new tablet regex data = JSON.parse content regexes = data['uaMatch']['tablets'].each.map { |_, v| v } new_regex = regexes.join('|').downcase # rewrite the tablet regex in our file new_content = File.read(TABLET_FILE).gsub!(/TABLET_USER_AGENTS = \/.*\//, "TABLET_USER_AGENTS = \/#{new_regex}\/") File.open(TABLET_FILE, 'w') { |f| f.write new_content } end # desc 'Generate documentation for the mobile_fu plugin.' # Rake::RDocTask.new(:rdoc) do |rdoc| # rdoc.rdoc_dir = 'rdoc' # rdoc.title = 'MobileFu' # rdoc.options << '--line-numbers' << '--inline-source' # rdoc.rdoc_files.include('README') # rdoc.rdoc_files.include('lib/**/*.rb') # end mobile-fu-1.3.1/Gemfile.lock0000644000004100000410000000422712271542544015660 0ustar www-datawww-dataPATH remote: . specs: mobile-fu (1.3.1) rack-mobile-detect rails GEM remote: http://rubygems.org/ specs: actionmailer (4.0.2) actionpack (= 4.0.2) mail (~> 2.5.4) actionpack (4.0.2) activesupport (= 4.0.2) builder (~> 3.1.0) erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) activemodel (4.0.2) activesupport (= 4.0.2) builder (~> 3.1.0) activerecord (4.0.2) activemodel (= 4.0.2) activerecord-deprecated_finders (~> 1.0.2) activesupport (= 4.0.2) arel (~> 4.0.0) activerecord-deprecated_finders (1.0.3) activesupport (4.0.2) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) arel (4.0.1) atomic (1.1.14) builder (3.1.4) erubis (2.7.0) hike (1.2.3) httparty (0.11.0) multi_json (~> 1.0) multi_xml (>= 0.5.2) i18n (0.6.9) json (1.6.4) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.2) mime-types (1.25.1) minitest (4.7.5) mocha (1.0.0) metaclass (~> 0.0.1) multi_json (1.8.4) multi_xml (0.5.5) polyglot (0.3.3) rack (1.5.2) rack-mobile-detect (0.4.0) rack rack-test (0.6.2) rack (>= 1.0) rails (4.0.2) actionmailer (= 4.0.2) actionpack (= 4.0.2) activerecord (= 4.0.2) activesupport (= 4.0.2) bundler (>= 1.3.0, < 2.0) railties (= 4.0.2) sprockets-rails (~> 2.0.0) railties (4.0.2) actionpack (= 4.0.2) activesupport (= 4.0.2) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.1.1) rdoc (3.12) json (~> 1.4) sprockets (2.10.1) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sprockets-rails (2.0.1) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) thor (0.18.1) thread_safe (0.1.3) atomic tilt (1.4.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) tzinfo (0.3.38) PLATFORMS ruby DEPENDENCIES httparty mobile-fu! mocha rdoc mobile-fu-1.3.1/CHANGELOG0000644000004100000410000000661312271542544014651 0ustar www-datawww-datacommit 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 mobile-fu-1.3.1/Gemfile0000644000004100000410000000013512271542544014723 0ustar www-datawww-datasource "http://rubygems.org" # Specify your gem's dependencies in mobile-fu.gemspec gemspec mobile-fu-1.3.1/MIT-LICENSE0000644000004100000410000000206212271542544015065 0ustar www-datawww-dataCopyright (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. mobile-fu-1.3.1/lib/0000755000004100000410000000000012271542544014177 5ustar www-datawww-datamobile-fu-1.3.1/lib/mobile-fu/0000755000004100000410000000000012271542544016056 5ustar www-datawww-datamobile-fu-1.3.1/lib/mobile-fu/helper.rb0000644000004100000410000000345212271542544017666 0ustar www-datawww-datamodule MobileFu module Helper JS_ENABLED_DEVICES = %w{iphone ipod ipad mobileexplorer android zune} def js_enabled_mobile_device? JS_ENABLED_DEVICES.find { |device| is_device? device } 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 mobile-fu-1.3.1/lib/mobile-fu/version.rb0000644000004100000410000000005012271542544020063 0ustar www-datawww-datamodule MobileFu VERSION = "1.3.1" end mobile-fu-1.3.1/lib/mobile-fu/tablet.rb0000644000004100000410000001734012271542544017663 0ustar www-datawww-datamodule MobileFu module Tablet TABLET_USER_AGENTS = /ipad|ipad.*mobile|^.*android.*nexus(((?:(?!mobile))|(?:(\s(7|10).+))).)*$|samsung.*tablet|galaxy.*tab|sc-01c|gt-p1000|gt-p1003|gt-p1010|gt-p3105|gt-p6210|gt-p6800|gt-p6810|gt-p7100|gt-p7300|gt-p7310|gt-p7500|gt-p7510|sch-i800|sch-i815|sch-i905|sgh-i957|sgh-i987|sgh-t849|sgh-t859|sgh-t869|sph-p100|gt-p3100|gt-p3108|gt-p3110|gt-p5100|gt-p5110|gt-p6200|gt-p7320|gt-p7511|gt-n8000|gt-p8510|sgh-i497|sph-p500|sgh-t779|sch-i705|sch-i915|gt-n8013|gt-p3113|gt-p5113|gt-p8110|gt-n8010|gt-n8005|gt-n8020|gt-p1013|gt-p6201|gt-p7501|gt-n5100|gt-n5110|shv-e140k|shv-e140l|shv-e140s|shv-e150s|shv-e230k|shv-e230l|shv-e230s|shw-m180k|shw-m180l|shw-m180s|shw-m180w|shw-m300w|shw-m305w|shw-m380k|shw-m380s|shw-m380w|shw-m430w|shw-m480k|shw-m480s|shw-m480w|shw-m485w|shw-m486w|shw-m500w|gt-i9228|sch-p739|sch-i925|gt-i9200|gt-i9205|gt-p5200|gt-p5210|sm-t311|sm-t310|sm-t210|sm-t210r|sm-t211|sm-p600|sm-p601|sm-p605|sm-p900|sm-t217|sm-t217a|sm-t217s|sm-p6000|sm-t3100|sgh-i467|xe500|kindle|silk.*accelerated|android.*\b(kfot|kftt|kfjwi|kfjwa|kfote|kfsowi|kfthwi|kfthwa|kfapwi|kfapwa|wfjwae)\b|windows nt [0-9.]+; arm;|hp slate 7|hp elitepad 900|hp-tablet|elitebook.*touch|^.*padfone((?!mobile).)*$|transformer|tf101|tf101g|tf300t|tf300tg|tf300tl|tf700t|tf700kl|tf701t|tf810c|me171|me301t|me302c|me371mg|me370t|me372mg|me172v|me173x|me400c|slider sl101|playbook|rim tablet|htc flyer|htc jetstream|htc-p715a|htc evo view 4g|pg41200|xoom|sholest|mz615|mz605|mz505|mz601|mz602|mz603|mz604|mz606|mz607|mz608|mz609|mz615|mz616|mz617|android.*nook|nookcolor|nook browser|bnrv200|bnrv200a|bntv250|bntv250a|bntv400|bntv600|logicpd zoom2|android.*; \b(a100|a101|a110|a200|a210|a211|a500|a501|a510|a511|a700|a701|w500|w500p|w501|w501p|w510|w511|w700|g100|g100w|b1-a71|b1-710|b1-711|a1-810)\b|w3-810|android.*(at100|at105|at200|at205|at270|at275|at300|at305|at1s5|at500|at570|at700|at830)|toshiba.*folio|\bl-06c|lg-v900|lg-v909\b|android.*\b(f-01d|f-05e|f-10d|m532|q572)\b|pmp3170b|pmp3270b|pmp3470b|pmp7170b|pmp3370b|pmp3570c|pmp5870c|pmp3670b|pmp5570c|pmp5770d|pmp3970b|pmp3870c|pmp5580c|pmp5880d|pmp5780d|pmp5588c|pmp7280c|pmp7280|pmp7880d|pmp5597d|pmp5597|pmp7100d|per3464|per3274|per3574|per3884|per5274|per5474|pmp5097cpro|pmp5097|pmp7380d|pmp5297c|pmp5297c_quad|ideatab|s2110|s6000|k3011|a3000|a1000|a2107|a2109|a1107|thinkpad([ ]+)?tablet|android.*(tab210|tab211|tab224|tab250|tab260|tab264|tab310|tab360|tab364|tab410|tab411|tab420|tab424|tab450|tab460|tab461|tab464|tab465|tab467|tab468)|android.*\boyo\b|life.*(p9212|p9514|p9516|s9512)|lifetab|an10g2|an7bg3|an7fg3|an8g3|an8cg3|an7g3|an9g3|an7dg3|an7dg3st|an7dg3childpad|an10bg3|an10bg3dt|m702pro|megafon v9|\bzte v9\b|e-boda (supreme|impresspeed|izzycomm|essential)|allview.*(viva|alldro|city|speed|all tv|frenzy|quasar|shine|tx1|ax1|ax2)|\b(101g9|80g9|a101it)\b|qilive 97r|novo7|novo8|novo10|novo7aurora|novo7basic|novo7paladin|novo9-spark|sony.*tablet|xperia tablet|sony tablet s|so-03e|sgpt12|sgpt13|sgpt114|sgpt121|sgpt122|sgpt123|sgpt111|sgpt112|sgpt113|sgpt131|sgpt132|sgpt133|sgpt211|sgpt212|sgpt213|sgp311|sgp312|sgp321|ebrd1101|ebrd1102|ebrd1201|android.*(k8gt|u9gt|u10gt|u16gt|u17gt|u18gt|u19gt|u20gt|u23gt|u30gt)|cube u8gt|mid1042|mid1045|mid1125|mid1126|mid7012|mid7014|mid7015|mid7034|mid7035|mid7036|mid7042|mid7048|mid7127|mid8042|mid8048|mid8127|mid9042|mid9740|mid9742|mid7022|mid7010|m9701|m9000|m9100|m806|m1052|m806|t703|mid701|mid713|mid710|mid727|mid760|mid830|mid728|mid933|mid125|mid810|mid732|mid120|mid930|mid800|mid731|mid900|mid100|mid820|mid735|mid980|mid130|mid833|mid737|mid960|mid135|mid860|mid736|mid140|mid930|mid835|mid733|android.*(\bmid\b|mid-560|mtv-t1200|mtv-pnd531|mtv-p1101|mtv-pnd530)|android.*(rk2818|rk2808a|rk2918|rk3066)|rk2738|rk2808a|iq310|fly vision|bq.*(elcano|curie|edison|maxwell|kepler|pascal|tesla|hypatia|platon|newton|livingstone|cervantes|avant)|maxwell.*lite|maxwell.*plus|mediapad|ideos s7|s7-201c|s7-202u|s7-101|s7-103|s7-104|s7-105|s7-106|s7-201|s7-slim|\bn-06d|\bn-08d|pantech.*p4100|broncho.*(n701|n708|n802|a710)|touchpad.*[78910]|\btouchtab\b|z1000|z99 2g|z99|z930|z999|z990|z909|z919|z900|tb07sta|tb10sta|tb07fta|tb10fta|android.*\bnabi|kobo touch|\bk080\b|\bvox\b build|\barc\b build|dslide.*\b(700|701r|702|703r|704|802|970|971|972|973|974|1010|1012)\b|navipad|tb-772a|tm-7045|tm-7055|tm-9750|tm-7016|tm-7024|tm-7026|tm-7041|tm-7043|tm-7047|tm-8041|tm-9741|tm-9747|tm-9748|tm-9751|tm-7022|tm-7021|tm-7020|tm-7011|tm-7010|tm-7023|tm-7025|tm-7037w|tm-7038w|tm-7027w|tm-9720|tm-9725|tm-9737w|tm-1020|tm-9738w|tm-9740|tm-9743w|tb-807a|tb-771a|tb-727a|tb-725a|tb-719a|tb-823a|tb-805a|tb-723a|tb-715a|tb-707a|tb-705a|tb-709a|tb-711a|tb-890hd|tb-880hd|tb-790hd|tb-780hd|tb-770hd|tb-721hd|tb-710hd|tb-434hd|tb-860hd|tb-840hd|tb-760hd|tb-750hd|tb-740hd|tb-730hd|tb-722hd|tb-720hd|tb-700hd|tb-500hd|tb-470hd|tb-431hd|tb-430hd|tb-506|tb-504|tb-446|tb-436|tb-416|tb-146se|tb-126se|playstation.*(portable|vita)|android.*\bg1\b|funbook|micromax.*\b(p250|p560|p360|p362|p600|p300|p350|p500|p275)\b|android.*\b(a39|a37|a34|st8|st10|st7|smart tab3|smart tab2)\b|fine7 genius|fine7 shine|fine7 air|fine8 style|fine9 more|fine10 joy|fine11 wide|\b(pem63|plt1023g|plt1041|plt1044|plt1044g|plt1091|plt4311|plt4311pl|plt4315|plt7030|plt7033|plt7033d|plt7035|plt7035d|plt7044k|plt7045k|plt7045kb|plt7071kg|plt7072|plt7223g|plt7225g|plt7777g|plt7810k|plt7849g|plt7851g|plt7852g|plt8015|plt8031|plt8034|plt8036|plt8080k|plt8082|plt8088|plt8223g|plt8234g|plt8235g|plt8816k|plt9011|plt9045k|plt9233g|plt9735|plt9760g|plt9770g)\b|bq1078|bc1003|bc1077|rk9702|bc9730|bc9001|it9001|bc7008|bc7010|bc708|bc728|bc7012|bc7030|bc7027|bc7026|tpc7102|tpc7103|tpc7105|tpc7106|tpc7107|tpc7201|tpc7203|tpc7205|tpc7210|tpc7708|tpc7709|tpc7712|tpc7110|tpc8101|tpc8103|tpc8105|tpc8106|tpc8203|tpc8205|tpc8503|tpc9106|tpc9701|tpc97101|tpc97103|tpc97105|tpc97106|tpc97111|tpc97113|tpc97203|tpc97603|tpc97809|tpc97205|tpc10101|tpc10103|tpc10106|tpc10111|tpc10203|tpc10205|tpc10503|tx-a1301|tx-m9002|q702|tab-p506|tab-navi-7-3g-m|tab-p517|tab-p-527|tab-p701|tab-p703|tab-p721|tab-p731n|tab-p741|tab-p825|tab-p905|tab-p925|tab-pr945|tab-pl1015|tab-p1025|tab-pi1045|tab-p1325|tab-protab[0-9]+|tab-protab25|tab-protab26|tab-protab27|tab-protab26xl|tab-protab2-ips9|tab-protab30-ips9|tab-protab25xxl|tab-protab26-ips10|tab-protab30-ips10|ov-(steelcore|newbase|basecore|baseone|exellen|quattor|edutab|solution|action|basictab|teddytab|magictab|stream|tb-08|tb-09)|hcl.*tablet|connect-3g-2.0|connect-2g-2.0|me tablet u1|me tablet u2|me tablet g1|me tablet x1|me tablet y2|me tablet sync|dps dream 9|dps dual 7|v97 hd|i75 3g|visture v4( hd)?|visture v5( hd)?|visture v10|ctp(-)?810|ctp(-)?818|ctp(-)?828|ctp(-)?838|ctp(-)?888|ctp(-)?978|ctp(-)?980|ctp(-)?987|ctp(-)?988|ctp(-)?989|\bmt8125|mt8389|mt8135|mt8377\b|concorde([ ]+)?tab|concorde readman|goclever tab|a7goclever|m1042|m7841|m742|r1042bk|r1041|tab a975|tab a7842|tab a741|tab a741l|tab m723g|tab m721|tab a1021|tab i921|tab r721|tab i720|tab t76|tab r70|tab r76.2|tab r106|tab r83.2|tab m813g|tab i721|gcta722|tab i70|tab i71|tab s73|tab r73|tab r74|tab r93|tab r75|tab r76.1|tab a73|tab a93|tab a93.2|tab t72|tab r83|tab r974|tab r973|tab a101|tab a103|tab a104|tab a104.2|r105bk|m713g|a972bk|tab a971|tab r974.2|tab r104|tab r83.3|tab a1042|freetab 9000|freetab 7.4|freetab 7004|freetab 7800|freetab 2096|freetab 7.5|freetab 1014|freetab 1001 |freetab 8001|freetab 9706|freetab 9702|freetab 7003|freetab 7002|freetab 1002|freetab 7801|freetab 1331|freetab 1004|freetab 8002|freetab 8014|freetab 9704|freetab 1003|hudl ht7s3|t-hub2|android.*\b97d\b|tablet(?!.*pc)|viewpad7|bntv250a|mid-wcdma|logicpd zoom2|\ba7eb\b|catnova8|a1_07|ct704|ct1002|\bm721\b|rk30sdk|\bevotab\b|smarttabii10|smarttab10|m758a|et904/.freeze def self.is_a_tablet_device? user_agent !!(user_agent.to_s.downcase =~ TABLET_USER_AGENTS) end end end mobile-fu-1.3.1/lib/mobile-fu.rb0000644000004100000410000001445112271542544016410 0ustar www-datawww-datarequire 'mobile-fu/tablet' require '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 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 # Add this to your controllers to only let those actions use the mobile format # this method has priority over the #has_no_mobile_fu_for # class AwesomeController < ApplicationController # has_mobile_fu_for :index # # def index # # Mobile format will be set as normal here if user is on a mobile device # end # # def show # # Mobile format will not be set, even if user is on a mobile device # end # end def has_mobile_fu_for(*actions) @mobile_include_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 request.format.html? && mobile_action? && is_mobile_device? && !request.xhr? request.format = :mobile unless session[:mobile_view] == false session[:mobile_view] = true if session[:mobile_view].nil? elsif request.format.html? && mobile_action? && 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? ::MobileFu::Tablet.is_a_tablet_device? request.user_agent 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 is supposed to use mobile format # See #has_mobile_fu_for def mobile_action? if self.class.instance_variable_get("@mobile_include_actions").nil? #Now we know we dont have any includes, maybe excludes? return !mobile_exempt? else self.class.instance_variable_get("@mobile_include_actions").try(:include?, params[:action].try(:to_sym)) end 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].try(: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 mobile-fu-1.3.1/metadata.yml0000644000004100000410000000624612271542544015744 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: mobile-fu version: !ruby/object:Gem::Version version: 1.3.1 platform: ruby authors: - Brendan Lim - Ben Langfeld autorequire: bindir: bin cert_chain: [] date: 2014-01-15 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rails requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rack-mobile-detect requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: mocha requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rdoc requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: httparty requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement 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 - Gemfile - Gemfile.lock - MIT-LICENSE - README.md - Rakefile - lib/mobile-fu.rb - lib/mobile-fu/helper.rb - lib/mobile-fu/tablet.rb - lib/mobile-fu/version.rb homepage: https://github.com/benlangfeld/mobile-fu licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: mobile-fu rubygems_version: 2.2.0 signing_key: specification_version: 4 summary: Automatically detect mobile requests from mobile devices in your Rails application. test_files: [] mobile-fu-1.3.1/checksums.yaml.gz0000444000004100000410000000041512271542544016717 0ustar www-datawww-datauRe=NA 9\`m297M d'+y^wY`u bv;R[XV<w@@wAZu5 n ^-n@B}2OX93>m)*\)jfyYϸd *ekJTY~HQ7l{س˹qzQsV ו3ԵPP`mS (%] y+Άĺ}'<mobile-fu-1.3.1/README.md0000644000004100000410000001131512271542544014711 0ustar www-datawww-dataMobile 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 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 ``` If you dont want to have all the methods respond to :mobile and :tablet, you can opt-in this actions using the following class method: `has_mobile_fu_for :action` Example: ```ruby class YourAwesomeClass < ActionController::Base has_mobile_fu has_mobile_fu_for :index def index # Mobile format will be set as normal here if user is on a mobile device end def another_method # Mobile format will not be set, even if user is on a mobile device 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 ``` If you want to use the default response templates, like index.html.erb, instead of the index.tablet.erb you can exclude the tablet rendering from beeing used: you can create a `before_filter` and put it before the has_mobile_fu call ```ruby before_filter :force_tablet_html has_mobile_fu def force_tablet_html session[:tablet_view] = false end ``` Same will work for mobile, just change the `tablet` values to `mobile` 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