Permalink
Browse files

Improved viewport attributes handler.

  • Loading branch information...
1 parent e748f48 commit e7ba7ecea8a49184beda9c43b51164f92f246360 Anton Lindqvist committed Aug 30, 2010
Showing with 3 additions and 7 deletions.
  1. +2 −6 lib/iphone_helpers.rb
  2. +1 −1 test/iphone_helpers_test.rb
@@ -36,13 +36,9 @@ def iphone_status_bar(options)
end
def iphone_viewport(options)
- translate = {:initial_scale => :'initial-scale', :maximum_scale => :'maximum-scale', :minimum_scale => :'minimum-scale', :user_scalable => :'user-scalable'}
+ options.each { |k,v| options[k.to_s.gsub('_', '-').to_sym] = v if options.delete(k) }
defaults = {:'initial-scale' => 1, :'maximum-scale' => 1, :width => 'device-width'}
- content = options.each do |k,v|
- k = (translate.key?(k) && options.delete(k) && translate[k]) || k
- options[k] = v
- end
- content = defaults.merge(content).collect { |k,v| "#{k}=#{v}" }.join('; ')
+ content = defaults.merge(options).collect { |k,v| "#{k}=#{v}" }.join('; ')
options = {:content => content, :name => 'viewport'}
[:meta, options]
end
@@ -36,6 +36,6 @@ class IphoneHelpersTest < ActionView::TestCase
end
test 'viewport with custom attributes' do
- assert_equal iphone(:viewport, :width => 320, :height => 480, :initial_scale => 2.5, :minimum_scale => 0.5, :maximum_scale => 3, :user_scalable => 'no'), '<meta content="width=320; height=480; initial-scale=2.5; maximum-scale=3; minimum-scale=0.5; user-scalable=no" name="viewport" />'
+ assert_equal iphone(:viewport, :width => 320, :height => 480, :initial_scale => 2.5, :minimum_scale => 0.5, :maximum_scale => 3, :user_scalable => 'no'), '<meta content="width=320; user-scalable=no; height=480; minimum-scale=0.5; initial-scale=2.5; maximum-scale=3" name="viewport" />'
end
end

0 comments on commit e7ba7ec

Please sign in to comment.