Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails for Mobile Devices @ Conferencia Rails 2011

Rails for Mobile Devices @ Conferencia Rails 2011

The slides from my talk "Rails for Mobile Devices" at Conferencia Rails 2011.

Alberto Perdomo

January 03, 2012
Tweet

More Decks by Alberto Perdomo

Other Decks in Programming

Transcript

  1. Small font size, little space between links No hover Gestures

    events vs. mouse events Touch interfaces
  2. @media screen and (min-width: 900px) { // styles for bigger

    displays } block for > 900px Examples <link rel="stylesheet" media="screen and (max-width: 600px)" href="small.css" /> or separate CSS file <link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css"> tablets
  3. demos.Forms = new Ext.TabPanel({ items: [{ title: 'Basic', xtype: 'form',

    id: 'basicform', scroll: 'vertical', items: [{ xtype: 'fieldset', title: 'Personal Info', instructions: 'Please enter the information above.', defaults: { // labelAlign: 'right' labelWidth: '35%' }, items: [{ xtype: 'textfield', name: 'name', label: 'Name', placeHolder: 'Tom Roy', autoCapitalize : true, required: true, useClearIcon: true }, { // ...
  4. <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> ... </body>

    </html> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
  5. Example: Single Page <body> <div data-role="page"> <div data-role="header"> <h1>Page Title</h1>

    </div><!-- /header --> <div data-role="content"> <p>Page content goes here.</p> </div><!-- /content --> <div data-role="footer"> <h4>Page Footer</h4> </div><!-- /footer --> </div><!-- /page -->
  6. Example: local linked pages <div data-role="page" > <div data-role="header"> <h1>Foo</h1>

    </div><!-- /header --> <div data-role="content"> <p>I'm first in the source order so I'm shown as the page.</p> </div><!-- /content --> <div data-role="footer"> <h4>Page Footer</h4> </div><!-- /footer --> </div> <div data-role="page" > ... </div> <p>View internal page called <a href="#bar">bar</a></p> id="foo" id="bar" When loading the HTML page the first page is autom. shown and the rest hidden When following a link to a local linked page, there is an animated transition
  7. Other stuff Components: Lists, Buttons, Dialogs, Grid, ... Hijax /

    Ajax Page transitions / Animations Theming Dual license: MIT or GPL version 2
  8. At its simplest, an offline web application is a list

    of URLs — HTML, CSS, JavaScript, images, or any other kind of resource. http://diveintohtml5.org/offline.html#divingin
  9. Basic example /index.html <!DOCTYPE HTML> <html > <body> ... /offline.appcache

    CACHE MANIFEST /screen.css /application.js /logo.png manifest="/offline.appcache" Content type: text/cache-manifest !!!
  10. <name>.appcache Anatomy of a manifest CACHE MANIFEST List of files

    to fall back in case not available FALLBACK / /offline.html /images/avatars/ /offline_avatar.png Online whitelist, never cached NETWORK /track.cgi CACHE /css/screen.css /css/offline.css /images/logo.png http://example.com/code.js List of files to cache
  11. Cache what? Read messages Browse articles Read news Place purchase

    orders Send messages Offline & online Online only All pages must be included Reference to manifest in each of them The page that triggers the download of the manifest file does not to be included
  12. A more complex example CACHE MANIFEST Allow to browse other

    pages when online NETWORK * FALLBACK / /offline.html Fallback for offline pages All pages
  13. Manifest: DOM & Events window.applicationCache object checking downloading progress cached

    noupdate updateready events window.applicationCache.swapCache() reload new cache after updateready
  14. Manifest: DOM & Events manifest attr in <html> first time?

    Event: checking no yes Event: downloading Download Event: progress Event: cached Finished changed? Event: noupdate no yes Event: downloading Download Event: progress Event: updateready
  15. Automated Mobile::Application.routes.draw do match "/application.manifest" => Rails::Offline Automatically caches all

    JS, CSS & HTML in public In development: include SHA based on timestamp to force reload In production: include SHA based on underlying assets
  16. Custom manifest Mobile::Application.routes.draw do offline = Rack::Offline.configure do cache [

    "http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css", "http://code.jquery.com/mobile/1.0b1/images/icons-18-white.png", "http://code.jquery.com/mobile/1.0b1/images/ajax-loader.png", "http://code.jquery.com/jquery-1.6.1.min.js", "http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js", "favicon.ico"] network "*" end match "/offline.appcache" => offline # ...
  17. Local Storage Implemented natively in the browsers Key/Value store Persistence

    Never sent to server (unlike cookies) Supported in common browsers, even IE > 8.0
  18. Details 5MB by default acessible through localStorage object key: String,

    value: Any JS supported type Use parseInt, parseFloat, ... to retrieve objects Synchronous API
  19. Examples Read/Write var foo = localStorage["bar"]; localStorage["bar"] = foo; Clear

    key Empty storage localStorage.removeItem("bar"); localStorage.clear();
  20. Competitors: WebSQL SQL database in the browser SQLite Implemented by

    some browsers: Safari, Chrome, Webkit Asynchronous API Requires more code but is also more powerful
  21. Benefits of Web Apps Interoperability & cross platform Installation &

    deployment options URLs Shorter Time to Market Deploy instantly, no approval process Your skills
  22. Creative Commons Title Author URL iPad vs iPhone Julien GONG

    Min http://www.flickr.com/photos/bfishadow/4604166391/ No worries http://www.flickr.com/photos/uggboy/5382476400/ Just Care Baby John Martinez Pavliga http://www.flickr.com/photos/virtualsugar/4590816785/ godzilla-anatomy Joe Wu http://www.flickr.com/photos/ozzywu1974/5143458938/ Manifest of Alien Passengers SS Ultonia Southampton(Apr.22, 1913) - Quebec (May 8, 1913) 1 of 2 Brent http://www.flickr.com/photos/stupiddingo/3728417282/ Pain Nathan Phillips http://www.flickr.com/photos/npphoto/4383990220/ Storage Karl Baron http://www.flickr.com/photos/kalleboo/3277120428/ Jocelyn Foye - Sumo - Face Off - Gateway Japan @ Torrance Art Museum (small) http://www.flickr.com/photos/lifeontheedge/5565245900/ box wrenches S. Diddy http://www.flickr.com/photos/spence_sir/2292721218/