Permalink
Browse files

first import

  • Loading branch information...
0 parents commit 4197be3629826187707eebcec61683c1d2bf28f7 Willem van Kerkhof committed Nov 28, 2008
Showing with 5,348 additions and 0 deletions.
  1. +3 −0 CHANGELOG
  2. BIN Dynamime-0.9.0.gem
  3. +21 −0 MIT-LICENSE
  4. +115 −0 README
  5. +23 −0 Rakefile
  6. +16 −0 gemspec
  7. +3 −0 init.rb
  8. 0 install.rb
  9. +366 −0 lib/dynamime.rb
  10. +61 −0 lib/wurfl_device.rb
  11. +96 −0 lib/wurfl_importer.rb
  12. +11 −0 rdoc/classes/.svn/all-wcprops
  13. +68 −0 rdoc/classes/.svn/entries
  14. +1 −0 rdoc/classes/.svn/format
  15. +133 −0 rdoc/classes/.svn/text-base/Dynamime.html.svn-base
  16. +5 −0 rdoc/classes/ActionController/.svn/all-wcprops
  17. +34 −0 rdoc/classes/ActionController/.svn/entries
  18. +1 −0 rdoc/classes/ActionController/.svn/format
  19. +11 −0 rdoc/classes/ActionController/Layout/.svn/all-wcprops
  20. +62 −0 rdoc/classes/ActionController/Layout/.svn/entries
  21. +1 −0 rdoc/classes/ActionController/Layout/.svn/format
  22. +112 −0 rdoc/classes/ActionController/Layout/.svn/text-base/ClassMethods.html.svn-base
  23. +112 −0 rdoc/classes/ActionController/Layout/ClassMethods.html
  24. +11 −0 rdoc/classes/ActionController/MimeResponds/.svn/all-wcprops
  25. +62 −0 rdoc/classes/ActionController/MimeResponds/.svn/entries
  26. +1 −0 rdoc/classes/ActionController/MimeResponds/.svn/format
  27. +270 −0 rdoc/classes/ActionController/MimeResponds/.svn/text-base/Responder.html.svn-base
  28. +270 −0 rdoc/classes/ActionController/MimeResponds/Responder.html
  29. +133 −0 rdoc/classes/Dynamime.html
  30. +23 −0 rdoc/classes/Dynamime/.svn/all-wcprops
  31. +130 −0 rdoc/classes/Dynamime/.svn/entries
  32. +1 −0 rdoc/classes/Dynamime/.svn/format
  33. +168 −0 rdoc/classes/Dynamime/.svn/text-base/ClassMethods.html.svn-base
  34. +346 −0 rdoc/classes/Dynamime/.svn/text-base/InstanceMethods.html.svn-base
  35. +404 −0 rdoc/classes/Dynamime/.svn/text-base/Type.html.svn-base
  36. +168 −0 rdoc/classes/Dynamime/ClassMethods.html
  37. +346 −0 rdoc/classes/Dynamime/InstanceMethods.html
  38. +404 −0 rdoc/classes/Dynamime/Type.html
  39. +1 −0 rdoc/created.rid
  40. +11 −0 rdoc/files/.svn/all-wcprops
  41. +65 −0 rdoc/files/.svn/entries
  42. +1 −0 rdoc/files/.svn/format
  43. +248 −0 rdoc/files/.svn/text-base/README.html.svn-base
  44. +248 −0 rdoc/files/README.html
  45. +11 −0 rdoc/files/lib/.svn/all-wcprops
  46. +62 −0 rdoc/files/lib/.svn/entries
  47. +1 −0 rdoc/files/lib/.svn/format
  48. +137 −0 rdoc/files/lib/.svn/text-base/dynamime_rb.html.svn-base
  49. +137 −0 rdoc/files/lib/dynamime_rb.html
  50. +32 −0 rdoc/fr_class_index.html
  51. +28 −0 rdoc/fr_file_index.html
  52. +47 −0 rdoc/fr_method_index.html
  53. +24 −0 rdoc/index.html
  54. +208 −0 rdoc/rdoc-style.css
  55. +95 −0 test/dynamime_test.rb
  56. 0 uninstall.rb
@@ -0,0 +1,3 @@
+[2008-08-12, wvk]
+
+Released 1st version of dynamime
Binary file not shown.
@@ -0,0 +1,21 @@
+Author: Willem van Kerkhof for Vodafone
+Copyright (c) 2008.
+
+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.
115 README
@@ -0,0 +1,115 @@
+= Dynamime
+
+Rails allows the creation of MIME type aliases to render different versions of HTML
+templates for different client devices. Dynamime extends this by adding automatic
+device detection using the client browser's user agent string (inspired by Brendan
+Lim's Mobile Fu plugin) and the possibility to build a use cascading "tree" of device
+types.
+If e.g. a subset of mobile devices has special needs regarding some aspects of a view,
+one can create special views for those devices while using more generic views for
+other mobile devices. It is however not required to define views for every device type,
+since Dynamime will try to render a more generic template if a specific one is
+not found.
+
+== Usage
+
+Add this this line to the controller.
+
+ class ApplicationController < ActionController::Base
+ use_device_dependent_views
+ end
+
+Requests coming from devices that are recognized as being special in some way
+(i.e. there is a user agent string in the database that unambiuously identifies
+the browser) the request format is set to whatever the view_mime_type of that
+user agent is set to.
+
+You can register allowed Dynamime types just as you register ordinary Mime types.
+However, Dynamime uses a cascading tree structure with fallback views for its
+types. This means that you only have to specify views for special devices if they
+really need an own view. If Dynamime detects e.g a mobile device that only uses
+a special view for one view, the other views are still rendered with its "parent"
+type, usually 'Mime::HTML'.
+
+Consider the following line in config/initializers/mime_types.rb:
+
+ Dynamime::Type.register :mobile, :html, 'application/vnd.wap.xhtml+xml'
+
+If a mobile device is detected (see below) an it requests e.g. /users/1,
+Dynamime will now look for a view template called /app/views/users/show.mobile.erb
+and render it. If that template is not found, it will try to render
+/app/views/users/show.html.erb before failing, if that one isn't found either.
+
+You can cascade this tree further like in the following example:
+
+ Dynamime::Type.register :mobile, :html, 'application/xhtml+xml'
+ Dynamime::Type.register :nokia_s60, :mobile
+ Dynamime::Type.register :nokia_n95, :nokia_s60
+
+The MIME type string (will bes sent as "Content-Type:" in the response header)
+is inherited from the "parent" type of a Dynamime::Type if not specified.
+
+Dynamime works just as well with `respond_to` as with explicit `render`
+methods.
+
+ # in UsersController
+ def show
+ # ... your app logic
+ respond_to do |format|
+ format.mobile
+ format.nokia_s60
+ format.nokia_n95
+ end
+ end
+
+Since it would be potentially tedious to explicitely list all supported device
+dependent format.<device>-lines, dynamime does what it is expected to do when
+simply using a `format.html` statement. It then creates a responder for all
+"subtypes" of the "html" type, e.g:
+
+ # in UsersController
+ def show
+ # ... your app logic
+ respond_to do |format|
+ format.nokia_n95 {...} # special behaviour for this device
+ format.html # simple render for *all* other devices
+ end
+ end
+
+When using an explicit `render` statement (for actions, partials and the whole
+other zoo), Dynamime also looks for <template name>.<detected device>.erb and
+uses the same cascading.
+
+== Setting up Dynamime
+
+After installing, you first have to create some models/tables needed by Dynamime.
+You can do that by running
+
+ ruby script/generate dynamime_migration
+ rake db:migrate
+
+The Entities being created are:
+
+* +Browser+
+* +HardwarePlatform+
+* +UserAgent+
+
+This also creates a set of corresponding migrations in /db/migrate and
+some database fixtures in /db/fixtures. These fixtures represent a sensible
+minimum of working data, so it's probably best if you run
+
+ rake db:fixture:load FIXTURES=browsers,hardware_platforms,user_agents
+
+after that. Of course, you are free to add many more entries. One possibility
+is to use the included WURFL extractor rails task that reads WURFL compatible
+XML files into the database. See documentation on WurflImporter for that.
+
+== Testing dynamimed Views
+
+Just as usual if you want to force Rails into using a special format,
+simply append the format to the url like /users/1.opera_mobile
+Dynamime will not try to determine the client's user agent for requests
+with an enforced format.
+
+Written by Willem van Kerkhof for Vodafone Global Services
+released under the MIT license
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the dynamime plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the dynamime plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Dynamime'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
16 gemspec
@@ -0,0 +1,16 @@
+require 'rubygems'
+
+SPEC = Gem::Specification.new do |s|
+ s.name = 'Dynamime'
+ s.version = '0.9.0'
+ s.author = 'Willem van Kerkhof'
+ s.email = 'willem.van-kerkhof@innoq.com'
+ s.homepage = ''
+ s.platform = Gem::Platform::RUBY
+ s.summary = 'Rails plugin that implements sophisticated user agent dependend template rendering'
+ s.files = Dir['./*'] + Dir['*/**']
+ s.test_file = 'test/dynamime_test.rb'
+ s.has_rdoc = true
+ s.require_path = 'lib'
+ s.extra_rdoc_files = ['README']
+end
@@ -0,0 +1,3 @@
+# require File.dirname(__FILE__) + '/lib/dynamimed_styles'
+require File.dirname(__FILE__) + '/lib/dynamime'
+
No changes.
Oops, something went wrong.

0 comments on commit 4197be3

Please sign in to comment.