iphone_helpers 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/iphone_helpers/version.rb +3 -0
- data/lib/iphone_helpers.rb +66 -0
- data/test/iphone_helpers_test.rb +47 -0
- metadata +95 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
3
|
+
module IphoneHelpers
|
4
|
+
def iphone(key, options = {})
|
5
|
+
tagname, attributes = send(key, options)
|
6
|
+
|
7
|
+
tag(tagname, attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def format_detection(options)
|
13
|
+
options[:name] = 'format-detection'
|
14
|
+
options[:content] = "telephone=#{(options[:telephone] && 'yes') || 'no'}"
|
15
|
+
options[:telephone] = nil
|
16
|
+
|
17
|
+
[:meta, options]
|
18
|
+
end
|
19
|
+
|
20
|
+
def fullscreen(options)
|
21
|
+
options[:name] = 'apple-mobile-web-app-capable'
|
22
|
+
options[:content] = 'yes'
|
23
|
+
|
24
|
+
[:meta, options]
|
25
|
+
end
|
26
|
+
|
27
|
+
def icon(options)
|
28
|
+
options[:rel] = 'apple-touch-icon'
|
29
|
+
options[:rel] += '-precomposed' if options[:precomposed]
|
30
|
+
options[:precomposed] = nil if options[:precomposed]
|
31
|
+
|
32
|
+
[:link, options]
|
33
|
+
end
|
34
|
+
|
35
|
+
def splash(options)
|
36
|
+
options[:rel] = 'apple-touch-startup-image'
|
37
|
+
|
38
|
+
[:link, options]
|
39
|
+
end
|
40
|
+
|
41
|
+
def status_bar(options)
|
42
|
+
options[:name] = 'apple-mobile-web-app-status-bar-style'
|
43
|
+
options[:content] = (%w[black black-translucent].include?(options[:color]) && options[:color]) || 'default'
|
44
|
+
options[:color] = nil if options[:color]
|
45
|
+
|
46
|
+
[:meta, options]
|
47
|
+
end
|
48
|
+
|
49
|
+
def viewport(options)
|
50
|
+
options = options.map do |key, value|
|
51
|
+
key = key.to_s.gsub('_', '-').to_sym
|
52
|
+
|
53
|
+
[key, value]
|
54
|
+
end
|
55
|
+
options = Hash[options]
|
56
|
+
defaults = {:'initial-scale' => 1, :'maximum-scale' => 1, :width => 'device-width'}
|
57
|
+
content = defaults.merge(options).stringify_keys.sort.collect { |k,v| "#{k}=#{v}" }.join(', ')
|
58
|
+
options = {:content => content, :name => 'viewport'}
|
59
|
+
|
60
|
+
[:meta, options]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module ::ActionView::Helpers::TagHelper
|
65
|
+
include IphoneHelpers
|
66
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class IphoneHelpersTest < MiniTest::Unit::TestCase
|
2
|
+
include ActionView::Helpers::TagHelper
|
3
|
+
|
4
|
+
def test_apple_mobile_web_app_capable
|
5
|
+
assert_tag iphone(:fullscreen), :meta, name: 'apple-mobile-web-app-capable', content: 'yes'
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_apple_mobile_web_app_status_bar_style
|
9
|
+
assert_tag iphone(:status_bar), :meta, name: 'apple-mobile-web-app-status-bar-style', content: 'default'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_apple_mobile_web_app_status_bar_style_black
|
13
|
+
assert_tag iphone(:status_bar, color: 'black'), :meta, name: 'apple-mobile-web-app-status-bar-style', content: 'black'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_apple_mobile_web_app_status_bar_style_black_translucent
|
17
|
+
assert_tag iphone(:status_bar, color: 'black-translucent'), :meta, name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_apple_touch_icon
|
21
|
+
assert_tag iphone(:icon, href: '/assets/iphone.png'), :link, rel: 'apple-touch-icon', href: '/assets/iphone.png'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_apple_touch_icon_precomposed
|
25
|
+
assert_tag iphone(:icon, href: '/assets/iphone.png', precomposed: true), :link, rel: 'apple-touch-icon-precomposed', href: '/assets/iphone.png'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_apple_touch_startup_image
|
29
|
+
assert_tag iphone(:splash, href: '/assets/splash.png'), :link, rel: 'apple-touch-startup-image', href: '/assets/splash.png'
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_format_detection_disable_telephone
|
33
|
+
assert_tag iphone(:format_detection, telephone: false), :meta, name: 'format-detection', content: 'telephone=no'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_format_detection_enable_telephone
|
37
|
+
assert_tag iphone(:format_detection, telephone: true), :meta, name: 'format-detection', content: 'telephone=yes'
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_viewport
|
41
|
+
assert_tag iphone(:viewport), :meta, name: 'viewport', content: 'initial-scale=1, maximum-scale=1, width=device-width'
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_viewport_with_custom_attributes
|
45
|
+
assert_tag iphone(:viewport, width: 320, height: 480, initial_scale: 2.5, minimum_scale: 0.5, maximum_scale: 3, user_scalable: 'no'), :meta, name: 'viewport', content: 'height=480, initial-scale=2.5, maximum-scale=3, minimum-scale=0.5, user-scalable=no, width=320'
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iphone_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anton Lindqvist
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: &70254874009800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70254874009800
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: awesome_print
|
27
|
+
requirement: &70254874009240 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70254874009240
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: minitest
|
38
|
+
requirement: &70254874008780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.4.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70254874008780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70254874008320 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 10.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70254874008320
|
58
|
+
description: iPhone specific HTML tags helper
|
59
|
+
email:
|
60
|
+
- anton@qvister.se
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- lib/iphone_helpers/version.rb
|
66
|
+
- lib/iphone_helpers.rb
|
67
|
+
- test/iphone_helpers_test.rb
|
68
|
+
homepage: http://github.com/mptre/rails-iphone-helpers
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Tailor made gem for Ruby on Rails providing helpers used to generate iPhone
|
92
|
+
specific HTML tags.
|
93
|
+
test_files:
|
94
|
+
- test/iphone_helpers_test.rb
|
95
|
+
has_rdoc:
|