README.markdown in divining_rod-0.3.1 vs README.markdown in divining_rod-0.4.0
- old
+ new
@@ -3,24 +3,47 @@
A tool to help format your sites mobile pages.
## Installation
gem install divining_rod
+
+## Example
+
+ Using the example configuration (found in [example_config.rb](http://github.com/markpercival/divining_rod/blob/master/example_config.rb)])
+
+ # For a request with the user agent
+ # "Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20"
+ profile = DiviningRod::Profile.new(request)
+ profile.iphone? #=> true
+ profile.name #=> 'iPhone'
+ profile.youtube_capable? #=> true
+ profile.format #=> :webkit
+
+
## Usage
_initializers/divining\_rod.rb_
- DiviningRod::Matchers.define do |map|
- # map.ua /user_agent_regex/, :format, :tags => []
- map.ua /iPhone/, :webkit, :tags => [:iphone, :youtube_capable]
- map.ua /Android/, :webkit, :tags => [:android, :youtube_capable, :google_gears]
- map.subdomain /wap/, :wap, :tags => [:crappy_old_phone]
+ DiviningRod::Mappings.define do |map|
+ # Android based phones
+ map.ua /Android/, :format => :webkit, :name => 'Android', :tags => [:android, :youtube_capable, :google_gears]
+
+ # Apple iPhone OS
+ map.ua /Apple.*Mobile.*Safari/, :format => :webkit, :tags => [:apple, :iphone_os, :youtube_capable] do |iphone|
+ iphone.ua /iPad/, :tags => :ipad, :name => 'iPad'
+ iphone.ua /iPod/, :tags => :ipod, :name => 'iPod Touch'
+ iphone.ua /iPhone/, :tags => [:iphone], :name => 'iPhone'
+ end
+
+ #Blackberry, needs more detail here
+ map.ua /BlackBerry/, :tags => :blackberry, :name => 'BlackBerry'
+ map.subdomain /wap/, :format => :wap, :tags => [:crappy_old_phone]
# Enable this to forces a default format if unmatched
# otherwise it will return the request.format
- # map.default :html
+ # map.default :format => :html
end
_initializers/mime\_types.rb_
Mime::Type.register_alias "text/html", :webkit
@@ -51,13 +74,13 @@
<% end %>
## Note on the development
-This is still very much in beta, but we are using it in production. As such we plan
-to do our best to keep the API the same.
+Tags always merge, while all other hash keys get overridden. Tags also will always allow you to call them as
+booleans. Ex @profile.iphone?
-The user agent definitions will be updated here later this week.
+If the :format key isn't available we default to request.format.
## Todo
### Copyright