Skip to content
Browse files

[config] adding density and state attributes

  • Loading branch information...
1 parent 51079ec commit a97bbceb548d8a90fa0579d7a2ee0c8356c140ca @hardeep hardeep committed Apr 25, 2012
View
8 lib/confetti/config.rb
@@ -169,11 +169,15 @@ def find_best_fit_img images, opts = {}
opts['width'] ||= nil
opts['height'] ||= nil
opts['role'] ||= nil
+ opts['density'] ||= nil
+ opts['state'] ||= nil
opts['platform'] ||= nil
# filters to look through sets for
filters = [
{'height' => opts['height'], 'width' => opts['width']},
+ {'platform' => opts['platform'], 'density' => opts['density']},
+ {'platform' => opts['platform'], 'state' => opts['state']},
{'platform' => opts['platform'], 'role' => opts['role']},
{'platform' => opts['platform']}
]
@@ -193,14 +197,14 @@ def find_best_fit_img images, opts = {}
def default_icon
@icon_set.each do |icon|
- return icon unless !File.basename(icon.src).match(/icon\.png$/i)
+ return icon if icon.src.match /^icon\.png$/i
end
nil
end
def default_splash
@splash_set.each do |splash|
- return splash unless !File.basename(splash.src).match(/splash\.png$/i)
+ return splash if splash.src.match /^splash\.png$/i
end
nil
end
View
5 lib/confetti/config/image.rb
@@ -1,7 +1,8 @@
module Confetti
class Config
class Image
- attr_accessor :src, :width, :height, :extras, :role, :platform, :main
+ attr_accessor :src, :width, :height, :extras,
+ :role, :platform, :main, :density, :state
def initialize *args
@src = args.shift
@@ -15,6 +16,8 @@ def initialize *args
@role = @extras['role']
@platform = @extras['platform']
@main = @extras['main']
+ @density = @extras['density']
+ @state = @extras['state']
end
end
end
View
30 spec/config_spec.rb
@@ -542,7 +542,7 @@
end
end
- describe "platform and role helpers" do
+ describe "icon and splash helpers" do
before do
file = "#{fixture_dir}/config-icons-custom-attribs-extended.xml"
@config = Confetti::Config.new file
@@ -553,11 +553,11 @@
@config.icon_set,
{
'platform' => 'blackberry',
- 'role' => 'hover'
+ 'state' => 'hover'
}
)
match.length.should == 1
- match.first.src.should == 'icons/icon_hover.png'
+ match.first.src.should == 'icons/bb/icon_hover.png'
end
it "should return all icons" do
@@ -570,10 +570,10 @@
@config.icon_set,
{
'platform' => 'blackberry',
- 'role' => 'hover'
+ 'state' => 'hover'
}
)
- match.src.should == "icons/icon_hover.png"
+ match.src.should == "icons/bb/icon_hover.png"
end
it "should find the best fit icon for winphone" do
@@ -582,13 +582,11 @@
match = @config.find_best_fit_img(
@config.send(:icon_set),
{
- 'height' => '54',
- 'width' => '54',
'platform' => 'winphone',
- 'role' => 'default'
+ 'role' => 'background'
}
)
- match.src.should == "icons/icon-68.png"
+ match.src.should == "icons/winphone/tileicon.png"
end
it "should find the best fit splash for android" do
@@ -597,31 +595,29 @@
match = @config.find_best_fit_img(
@config.send(:splash_set),
{
- 'height' => '54',
- 'width' => '54',
'platform' => 'android',
- 'role' => 'default'
+ 'density' => 'ldpi'
}
)
- match.src.should == "splashes/splash-android.png"
+ match.src.should == "splash/android/ldpi.png"
end
it "should return the default icon: icon.png" do
- @config.default_icon.src.should == "icons/icon.png"
+ @config.default_icon.src.should == "icon.png"
end
it "should fail to return the default icon: icon.png" do
@config = Confetti::Config.new
- @config.default_icon.should != nil
+ @config.default_icon.should == nil
end
it "should return the default splash: splash.png" do
- @config.default_splash.src.should == "splashes/splash.png"
+ @config.default_splash.src.should == "splash.png"
end
it "should fail to return the default splash: splash.png" do
@config = Confetti::Config.new
- @config.default_splash.should != nil
+ @config.default_splash.should == nil
end
end
View
77 spec/fixtures/config-icons-custom-attribs-extended.xml
@@ -1,38 +1,43 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<widget xmlns = "http://www.w3.org/ns/widgets"
- xmlns:gap = "http://phonegap.com/ns/1.0"
- id = "com.alunny.confetti"
- version = "1.0.0">
+<?xml version="1.0" encoding="UTF-8" ?>
+<widget xmlns = "http://www.w3.org/ns/widgets"
+ xmlns:gap = "http://phonegap.com/ns/1.0"
+ id = "com.phonegap.example"
+ version = "1.0.0">
+
+<name>Icon and Splash Demo</name>
+
+<description>
+Basic application to test and demonstrate icons and splash screens.
+</description>
+
+<author href="https://build.phonegap.com" email="shardeep@adobe.com">
+Hardeep Shoker
+</author>
+
+<!-- Icons -->
+
+<icon src="icon.png" />
+<icon src="icons/ios/icon.png" width="57" height="57" />
+<icon src="icons/ios/icon-72.png" gap:platform="ios" width="72" height="72" />
+<icon src="icons/ios/icon_at_2x.png" width="114" height="114" />
+<icon src="icons/android/ldpi.png" gap:platform="android" gap:density="ldpi" />
+<icon src="icons/android/mdpi.png" gap:platform="android" gap:density="mdpi" />
+<icon src="icons/android/hdpi.png" gap:platform="android" gap:density="hdpi" />
+<icon src="icons/bb/icon.png" gap:platform="blackberry" />
+<icon src="icons/bb/icon_hover.png" gap:platform="blackberry" gap:state="hover"/>
+<icon src="icons/winphone/icon.png" gap:platform="winphone" />
+<icon src="icons/winphone/tileicon.png" gap:platform="winphone" gap:role="background"/>
+
+<!-- Splash Screens -->
+<gap:splash src="splash.png" />
+<gap:splash src="splash/ios/Default-Landscape.png" width="1024" height="786"/>
+<gap:splash src="splash/ios/Default-Portrait.png" width="786" height="1024" />
+<gap:splash src="splash/ios/Default.png" width="320" height="480" />
+<gap:splash src="splash/ios/Default_at_2x.png" width="640" height="960" />
+<gap:splash src="splash/android/ldpi.png" gap:platform="android" gap:density="ldpi" />
+<gap:splash src="splash/android/mdpi.png" gap:platform="android" gap:density="mdpi" />
+<gap:splash src="splash/android/hdpi.png" gap:platform="android" gap:density="hdpi" />
+<gap:splash src="splash/bb/splash.png" gap:platform="blackberry" />
+<gap:splash src="splash/winphone/splash.png" gap:platform="winphone" />
- <name>Confetti Sample App</name>
-
- <description>
- This is a sample config.xml for integration testing with Confetti
- </description>
-
- <author href="http://alunny.github.com"
- email="hardeep.shoker@nitobi.com">
- Hardeep Shoker
- </author>
-
- <icon src="icons/icon.png" />
- <gap:splash src="splashes/splash.png" />
-
- <icon src="icons/icon.png" gap:platform="blackberry" />
- <icon src="icons/icon_hover.png" gap:platform="blackberry" gap:role="hover"/>
-
- <icon src="icons/icon-57.png" width="57" height="57"/>
- <icon src="icons/icon-iphone-72.png" height="72" width="72" gap:platform="ios"/>
- <icon src="icons/icon-114.png" width="114" height="114"/>
-
- <icon src="icons/icon-36.png" width="36" height="36"/>
- <icon src="icons/icon-48.png" width="48" height="48"/>
- <icon src="icons/icon-android-72.png" height="72" width="72" gap:platform="android"/>
- <gap:splash src="splashes/splash-android.png" gap:platform="android"/>
-
- <icon src="icons/icon-173.png" width="173" height="173"/>
- <icon src="icons/icon-68.png" gap:platform="winphone"/>
-
- <feature name="http://api.phonegap.com/1.0/geolocation"/>
- <feature name="http://api.phonegap.com/1.0/network"/>
</widget>

0 comments on commit a97bbce

Please sign in to comment.
Something went wrong with that request. Please try again.