Permalink
Browse files

Initial import.

  • Loading branch information...
0 parents commit 1227b6e68621ec73a169a3435c9bf6736975f355 Anton Lindqvist committed Aug 30, 2010
Showing with 168 additions and 0 deletions.
  1. +59 −0 README.md
  2. +23 −0 Rakefile
  3. +1 −0 init.rb
  4. +43 −0 lib/iphone_helpers.rb
  5. +37 −0 test/iphone_helpers_test.rb
  6. +5 −0 test/test_helper.rb
@@ -0,0 +1,59 @@
+iPhone helpers
+============
+
+Rails plugin providing helpers used to generate iPhone specific html tags.
+
+Example
+=======
+
+viewport
+--------
+ <%= iphone :viewport %>
+
+apple touch icon
+----------------
+ <%= iphone :icon, :href => "iphone.png" %>
+
+apple touch icon precomposed
+----------------------------
+ <%= iphone :icon, :href => "iphone.png", :precomposed => true %>
+
+apple touch startup image
+-------------------------
+ <%= iphone :splash, :href => "splash.png" %>
+
+apple mobile web app status bar style
+-------------------------------------
+ <% iphone :status_bar %>
+
+apple mobile web app status bar style black
+-------------------------------------------
+ <% iphone :status_bar, :color => "black" %>
+
+apple mobile web app status bar style black translucent
+-------------------------------------------
+ <% iphone :status_bar, :color => "black-translucent" %>
+
+License
+=======
+
+Copyright (c) 2010 [Anton Lindqvist](http://qvister.se), released under the MIT license.
+
+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.
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the iphone_helpers plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the iphone_helpers plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'IphoneHelpers'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1 @@
+require 'iphone_helpers'
@@ -0,0 +1,43 @@
+module ::ActionView::Helpers::TagHelper
+ def iphone(key, *options)
+ options = options.extract_options!
+ tagname, attributes = send("iphone_#{key}", options)
+
+ tag(tagname, attributes)
+ end
+
+ protected
+
+ def iphone_fullscreen(options)
+ options[:name] = 'apple-mobile-web-app-capable'
+ options[:content] = 'yes'
+ [:meta, options]
+ end
+
+ def iphone_icon(options)
+ options[:rel] = 'apple-touch-icon'
+ options[:rel] += '-precomposed' if options[:precomposed]
+ options[:precomposed] = nil if options[:precomposed]
+ options[:href] = image_path(options[:href])
+ [:link, options]
+ end
+
+ def iphone_splash(options)
+ options[:rel] = 'apple-touch-startup-image'
+ options[:href] = image_path(options[:href])
+ [:link, options]
+ end
+
+ def iphone_status_bar(options)
+ options[:name] = 'apple-mobile-web-app-status-bar-style'
+ options[:content] = (%w[black black-translucent].include?(options[:color]) && options[:color]) || 'default'
+ options[:color] = nil if options[:color]
+ [:meta, options]
+ end
+
+ def iphone_viewport(options)
+ options[:name] = 'viewport'
+ options[:content] = 'width=device-width; initial-scale=1.0; maximum-scale=1.0;'
+ [:meta, options]
+ end
+end
@@ -0,0 +1,37 @@
+require 'test_helper'
+
+class IphoneHelpersTest < ActionView::TestCase
+ ActionController::Base.assets_dir = '/' # required in order to use image_path outside rails.
+
+ test 'apple mobile web app capable' do
+ assert_equal iphone(:fullscreen), '<meta content="yes" name="apple-mobile-web-app-capable" />'
+ end
+
+ test 'apple touch icon' do
+ assert_equal iphone(:icon, :href => 'iphone.png'), '<link href="/images/iphone.png" rel="apple-touch-icon" />'
+ end
+
+ test 'apple touch icon precomposed' do
+ assert_equal iphone(:icon, :href => 'iphone.png', :precomposed => true), '<link href="/images/iphone.png" rel="apple-touch-icon-precomposed" />'
+ end
+
+ test 'apple touch startup image' do
+ assert_equal iphone(:splash, :href => 'splash.png'), '<link href="/images/splash.png" rel="apple-touch-startup-image" />'
+ end
+
+ test 'apple mobile web app status bar style' do
+ assert_equal iphone(:status_bar), '<meta content="default" name="apple-mobile-web-app-status-bar-style" />'
+ end
+
+ test 'apple mobile web app status bar style black' do
+ assert_equal iphone(:status_bar, :color => 'black'), '<meta content="black" name="apple-mobile-web-app-status-bar-style" />'
+ end
+
+ test 'apple mobile web app status bar style black translucent' do
+ assert_equal iphone(:status_bar, :color => 'black-translucent'), '<meta content="black-translucent" name="apple-mobile-web-app-status-bar-style" />'
+ end
+
+ test 'viewport' do
+ assert_equal iphone(:viewport), '<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" name="viewport" />'
+ end
+end
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'test/unit'
+require 'active_support'
+require 'action_view'
+require File.join(File.dirname(__FILE__), '../lib/iphone_helpers')

0 comments on commit 1227b6e

Please sign in to comment.