confetti 0.7.3 → 0.7.4

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- confetti (0.7.3)
4
+ confetti (0.7.4)
5
5
  mustache (~> 0.11.2)
6
6
 
7
7
  GEM
data/lib/confetti.rb CHANGED
@@ -39,3 +39,4 @@ require 'confetti/template_helper'
39
39
 
40
40
  require 'confetti/config'
41
41
  require 'confetti/config/feature'
42
+ require 'confetti/config/image'
@@ -37,7 +37,6 @@ module Confetti
37
37
  Name = Class.new Struct.new(:name, :shortname)
38
38
  License = Class.new Struct.new(:text, :href)
39
39
  Content = Class.new Struct.new(:src, :type, :encoding)
40
- Image = Class.new Struct.new(:src, :height, :width, :extras)
41
40
  Feature = Class.new Struct.new(:name, :required)
42
41
  Preference = Class.new Struct.new(:name, :value, :readonly)
43
42
  Access = Class.new Struct.new(:origin, :subdomains)
@@ -96,8 +95,7 @@ module Confetti
96
95
  when "description"
97
96
  @description = ele.text.nil? ? "" : ele.text.strip
98
97
  when "icon"
99
- extras = grab_extras attr
100
- @icon_set << Image.new(attr["src"], attr["height"], attr["width"], extras)
98
+ @icon_set << Image.new(attr["src"], attr["height"], attr["width"], attr)
101
99
  # used for the info.plist file
102
100
  @plist_icon_set << attr["src"]
103
101
  when "feature"
@@ -117,8 +115,7 @@ module Confetti
117
115
  case ele.name
118
116
  when "splash"
119
117
  next if attr["src"].nil? or attr["src"].empty?
120
- extras = grab_extras attr
121
- @splash_set << Image.new(attr["src"], attr["height"], attr["width"], extras)
118
+ @splash_set << Image.new(attr["src"], attr["height"], attr["width"], attr)
122
119
  end
123
120
  end
124
121
  end
@@ -149,14 +146,6 @@ module Confetti
149
146
  end
150
147
  end
151
148
 
152
- def grab_extras(attributes)
153
- extras = attributes.keys.inject({}) do |hash, key|
154
- hash[key] = attributes[key] unless Image.public_instance_methods.include? key
155
- hash
156
- end
157
- extras
158
- end
159
-
160
149
  # helper to retrieve a preference's value
161
150
  # returns nil if the preference doesn't exist
162
151
  def preference name
@@ -175,5 +164,58 @@ module Confetti
175
164
  def full_access?
176
165
  @access_set.detect { |a| a.origin == '*' }
177
166
  end
167
+
168
+ def find_best_fit_img images, opts = {}
169
+ opts['width'] ||= nil
170
+ opts['height'] ||= nil
171
+ opts['role'] ||= nil
172
+ opts['platform'] ||= nil
173
+
174
+ # filters to look through sets for
175
+ filters = [
176
+ {'height' => opts['height'], 'width' => opts['width']},
177
+ {'platform' => opts['platform'], 'role' => opts['role']},
178
+ {'platform' => opts['platform']}
179
+ ]
180
+
181
+ matches = nil
182
+
183
+ filters.each do |filter|
184
+ matches = filter_images(images, filter)
185
+
186
+ if matches.length == 1
187
+ break
188
+ end
189
+ end
190
+
191
+ matches.first unless matches.empty?
192
+ end
193
+
194
+ def default_icon
195
+ @icon_set.each do |icon|
196
+ return icon unless !File.basename(icon.src).match(/icon\.png$/i)
197
+ end
198
+ nil
199
+ end
200
+
201
+ def default_splash
202
+ @splash_set.each do |splash|
203
+ return splash unless !File.basename(splash.src).match(/splash\.png$/i)
204
+ end
205
+ nil
206
+ end
207
+
208
+ def filter_images images, filter
209
+ imgs = images.clone
210
+
211
+ # filter can have multiple criteria
212
+ filter.each_pair do |name, value|
213
+ imgs = imgs.reject do |img|
214
+ !img.respond_to?(name) || img.send(name) != value
215
+ end
216
+ end
217
+
218
+ imgs
219
+ end
178
220
  end
179
221
  end
@@ -0,0 +1,22 @@
1
+ module Confetti
2
+ class Config
3
+ class Image
4
+ attr_accessor :src, :width, :height, :extras, :role, :platform, :main
5
+
6
+ def initialize *args
7
+ @src = args.shift
8
+ @height = args.shift
9
+ @width = args.shift
10
+
11
+ @extras = (args.shift || {}).reject do |name, val|
12
+ %w{src height width}.include?(name)
13
+ end
14
+
15
+ @role = @extras['role']
16
+ @platform = @extras['platform']
17
+ @main = @extras['main']
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -1,3 +1,3 @@
1
1
  module Confetti
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -265,10 +265,13 @@ describe Confetti::Config do
265
265
  describe "with custom splash screen attributes" do
266
266
  before do
267
267
  @config = Confetti::Config.new
268
- @config.populate_from_xml(fixture_dir + "/config-icons-custom-attribs.xml")
268
+ @config.populate_from_xml(
269
+ fixture_dir + "/config-icons-custom-attribs.xml"
270
+ )
269
271
  end
270
272
 
271
273
  it "should populate splash screen non-standards attributes to extras field" do
274
+ p @config.splash_set
272
275
  @config.splash_set.size.should be 1
273
276
  @config.splash_set.first.extras.should_not == nil
274
277
  @config.splash_set.first.extras.length.should be 1
@@ -531,4 +534,87 @@ describe Confetti::Config do
531
534
  @config.full_access?.should be_false
532
535
  end
533
536
  end
537
+
538
+ describe "platform and role helpers" do
539
+ before do
540
+ file = "#{fixture_dir}/config-icons-custom-attribs-extended.xml"
541
+ @config = Confetti::Config.new file
542
+ end
543
+
544
+ it "should return all blackberry icons with hover" do
545
+ match = @config.filter_images(
546
+ @config.icon_set,
547
+ {
548
+ 'platform' => 'blackberry',
549
+ 'role' => 'hover'
550
+ }
551
+ )
552
+ match.length.should == 1
553
+ match.first.src.should == 'icons/icon_hover.png'
554
+ end
555
+
556
+ it "should return all icons" do
557
+ match = @config.filter_images(@config.icon_set,{})
558
+ match.length.should == 11
559
+ end
560
+
561
+ it "should find the best fit image for bb" do
562
+ match = @config.find_best_fit_img(
563
+ @config.icon_set,
564
+ {
565
+ 'platform' => 'blackberry',
566
+ 'role' => 'hover'
567
+ }
568
+ )
569
+ match.src.should == "icons/icon_hover.png"
570
+ end
571
+
572
+ it "should find the best fit icon for winphone" do
573
+ # we will find a 68pixel image as it fits out platform
574
+ # specification
575
+ match = @config.find_best_fit_img(
576
+ @config.send(:icon_set),
577
+ {
578
+ 'height' => '54',
579
+ 'width' => '54',
580
+ 'platform' => 'winphone',
581
+ 'role' => 'default'
582
+ }
583
+ )
584
+ match.src.should == "icons/icon-68.png"
585
+ end
586
+
587
+ it "should find the best fit splash for android" do
588
+ # we will find a 68pixel image as it fits out platform
589
+ # specification
590
+ match = @config.find_best_fit_img(
591
+ @config.send(:splash_set),
592
+ {
593
+ 'height' => '54',
594
+ 'width' => '54',
595
+ 'platform' => 'android',
596
+ 'role' => 'default'
597
+ }
598
+ )
599
+ match.src.should == "splashes/splash-android.png"
600
+ end
601
+
602
+ it "should return the default icon: icon.png" do
603
+ @config.default_icon.src.should == "icons/icon.png"
604
+ end
605
+
606
+ it "should fail to return the default icon: icon.png" do
607
+ @config = Confetti::Config.new
608
+ @config.default_icon.should != nil
609
+ end
610
+
611
+ it "should return the default splash: splash.png" do
612
+ @config.default_splash.src.should == "splashes/splash.png"
613
+ end
614
+
615
+ it "should fail to return the default splash: splash.png" do
616
+ @config = Confetti::Config.new
617
+ @config.default_splash.should != nil
618
+ end
619
+ end
534
620
  end
@@ -0,0 +1,38 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <widget xmlns = "http://www.w3.org/ns/widgets"
3
+ xmlns:gap = "http://phonegap.com/ns/1.0"
4
+ id = "com.alunny.confetti"
5
+ version = "1.0.0">
6
+
7
+ <name>Confetti Sample App</name>
8
+
9
+ <description>
10
+ This is a sample config.xml for integration testing with Confetti
11
+ </description>
12
+
13
+ <author href="http://alunny.github.com"
14
+ email="hardeep.shoker@nitobi.com">
15
+ Hardeep Shoker
16
+ </author>
17
+
18
+ <icon src="icons/icon.png" />
19
+ <gap:splash src="splashes/splash.png" />
20
+
21
+ <icon src="icons/icon.png" gap:platform="blackberry" />
22
+ <icon src="icons/icon_hover.png" gap:platform="blackberry" gap:role="hover"/>
23
+
24
+ <icon src="icons/icon-57.png" width="57" height="57"/>
25
+ <icon src="icons/icon-iphone-72.png" height="72" width="72" gap:platform="ios"/>
26
+ <icon src="icons/icon-114.png" width="114" height="114"/>
27
+
28
+ <icon src="icons/icon-36.png" width="36" height="36"/>
29
+ <icon src="icons/icon-48.png" width="48" height="48"/>
30
+ <icon src="icons/icon-android-72.png" height="72" width="72" gap:platform="android"/>
31
+ <gap:splash src="splashes/splash-android.png" gap:platform="android"/>
32
+
33
+ <icon src="icons/icon-173.png" width="173" height="173"/>
34
+ <icon src="icons/icon-68.png" gap:platform="winphone"/>
35
+
36
+ <feature name="http://api.phonegap.com/1.0/geolocation"/>
37
+ <feature name="http://api.phonegap.com/1.0/network"/>
38
+ </widget>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 3
9
- version: 0.7.3
8
+ - 4
9
+ version: 0.7.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Lunny
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-03-29 00:00:00 -07:00
19
+ date: 2012-04-10 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,7 @@ files:
67
67
  - lib/confetti.rb
68
68
  - lib/confetti/config.rb
69
69
  - lib/confetti/config/feature.rb
70
+ - lib/confetti/config/image.rb
70
71
  - lib/confetti/error.rb
71
72
  - lib/confetti/helpers.rb
72
73
  - lib/confetti/phonegap.rb
@@ -115,6 +116,7 @@ files:
115
116
  - spec/fixtures/blackberry/blackberry_widget_config_no_version_or_id.xml
116
117
  - spec/fixtures/blackberry/blackberry_widget_config_spec.xml
117
118
  - spec/fixtures/blackberry/blackberry_widget_config_spec_with_expected_orientation.xml
119
+ - spec/fixtures/config-icons-custom-attribs-extended.xml
118
120
  - spec/fixtures/config-icons-custom-attribs.xml
119
121
  - spec/fixtures/config-icons.xml
120
122
  - spec/fixtures/config.xml
@@ -204,6 +206,7 @@ test_files:
204
206
  - spec/fixtures/blackberry/blackberry_widget_config_no_version_or_id.xml
205
207
  - spec/fixtures/blackberry/blackberry_widget_config_spec.xml
206
208
  - spec/fixtures/blackberry/blackberry_widget_config_spec_with_expected_orientation.xml
209
+ - spec/fixtures/config-icons-custom-attribs-extended.xml
207
210
  - spec/fixtures/config-icons-custom-attribs.xml
208
211
  - spec/fixtures/config-icons.xml
209
212
  - spec/fixtures/config.xml