Skip to content

Adding WinPhone 8 platform to Confetti #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/confetti.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
require 'confetti/templates/symbian_wrt_info'
require 'confetti/templates/webos_appinfo'
require 'confetti/templates/windows_phone7_manifest'
require 'confetti/templates/windows_phone8_manifest'

require 'confetti/template_helper'

Expand Down
2 changes: 1 addition & 1 deletion lib/confetti/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Config
generate_and_write :android_manifest, :android_strings,
:webos_appinfo, :ios_info, :symbian_wrt_info,
:blackberry_widgets_config, :ios_remote_plist,
:windows_phone7_manifest
:windows_phone7_manifest, :windows_phone8_manifest

# handle bad generate/write calls
def method_missing(method_name, *args)
Expand Down
39 changes: 39 additions & 0 deletions lib/confetti/templates/windows_phone8_manifest.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2012/deployment" AppPlatformVersion="8.0">
<DefaultLanguage code="en-US" xmlns="" />
<Languages xmlns="">
<Language code="en-US" />
</Languages>
<App xmlns="" PublisherID="{{producerguid}}" ProductID="{{guid}}" Title="{{ title }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change producerguid to publisherid

RuntimeType="Silverlight" Version="{{version}}" Genre="apps.normal"
Author="{{ author }}"
Description="{{ description }}"
Publisher="{{ author }}">

<IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
<Capabilities>
{{#capabilities}}
<Capability Name="{{name}}" />
{{/capabilities}}
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
</Capabilities>

<Tasks>
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
</Tasks>
<Tokens>
<PrimaryToken TokenID="Cordova_1._5._0_Starter1Token" TaskName="_default">
<TemplateType5>
<BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
<Count>0</Count>
<Title>Cordova_1._5._0_Starter1</Title>
</TemplateType5>
</PrimaryToken>
</Tokens>
<ScreenResolutions>
<ScreenResolution Name="ID_RESOLUTION_WVGA" />
<ScreenResolution Name="ID_RESOLUTION_WXGA" />
<ScreenResolution Name="ID_RESOLUTION_HD720P" />
</ScreenResolutions>
</App>
</Deployment>
91 changes: 91 additions & 0 deletions lib/confetti/templates/windows_phone8_manifest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module Confetti
module Template
class WindowsPhone8Manifest < Base
include VersionHelper

GAP_PERMISSIONS_MAP = {
'camera' => %w{ID_CAP_ISV_CAMERA},
'contacts' => %w{ID_CAP_CONTACTS},
'device' => %w{ID_CAP_IDENTITY_DEVICE},
'geolocation' => %w{ID_CAP_LOCATION},
'network' => %w{ID_CAP_NETWORKING},
'media' => %w{ID_CAP_MICROPHONE},
}

def title
@config.name.name
end

def author
@config.author.name ? @config.author.name[0..49] : ""
end

def guid
package = @config.package
package ||= 'com.example.app'
guid = Digest::MD5.hexdigest package
res = "{#{ guid[0..7] }-#{ guid[8..11] }-"
res << "#{ guid[12..15] }-#{ guid[16..19] }-"
res << "#{ guid[20,guid.length-1]}}"
end

def producerguid
package = @config.package
package ||= 'com.example.app'
package = "#{package}" + "second";
guid = Digest::MD5.hexdigest package
res = "{#{ guid[0..7] }-#{ guid[8..11] }-"
res << "#{ guid[12..15] }-#{ guid[16..19] }-"
res << "#{ guid[20,guid.length-1]}}"
end

def description
if @config.description && @config.description.length >= 250
"#{ @config.description[0..245] }..."
else
@config.description
end
end

def version
v = normalize_version(@config.version_string).split('.')

# after the first one, each segment can only have one character
"#{ v[0] }.#{ v[1][0..0] }.#{ v[2][0..0] }.0"
end

def capabilities
default_permissions = %w{camera contacts device geolocation
network media}
permissions = []
capabilities = []
phonegap_api = /http\:\/\/api.phonegap.com\/1[.]0\/(\w+)/
filtered_features = @config.feature_set.clone

filtered_features.each { |f|
next if f.name.nil?
matches = f.name.match(phonegap_api)
next if matches.nil? or matches.length < 1
next unless GAP_PERMISSIONS_MAP.has_key?(matches[1])
permissions << matches[1]
}

if @config.feature_set.empty? and
@config.preference(:permissions) != :none
permissions = default_permissions
end

permissions.each { |p|
capabilities.concat(GAP_PERMISSIONS_MAP[p])
}

capabilities.sort!
capabilities.map { |f| { :name => f } }
end

def output_filename
"WMAppManifest.xml"
end
end
end
end
184 changes: 184 additions & 0 deletions spec/templates/windows_phone8_manifest_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
require 'spec_helper'

describe Confetti::Template::WindowsPhone8Manifest do
include HelpfulPaths

before :all do
@template_class = Confetti::Template::WindowsPhone8Manifest
end

it "should have the base class of Confetti::Template" do
@template_class.superclass.should == Confetti::Template::Base
end

it "should have a valid WMAppManifest mustace template" do
@template_class.template_file.should == "#{ templates_dir }/windows_phone8_manifest.mustache"
end

describe "attributes" do
subject { @template = @template_class.new }

it { should respond_to :title }
it { should respond_to :author }
it { should respond_to :guid }
it { should respond_to :description }
it { should respond_to :version }
it { should respond_to :capabilities }
end

it "should provide a 128 bit guid" do
@config = Confetti::Config.new
@config.package = "com.example.www"
@template = @template_class.new @config
@template.guid.should == "{1005a3fc-23ab-99bd-bdd1-9e83f3d7b989}"
end

describe "with a bad config object" do

describe "on rendering" do

it "should generate a dummy uuid if non provided" do
@config = Confetti::Config.new
@config.package = "com.example.app"
@template = @template_class.new @config
@template.guid.should == "{a163ec9b-9996-caee-009d-cdac1b7e0722}"
end

it "should not fail when a bad feature is found" do
@config = Confetti::Config.new
bad_feature = Confetti::Config::Feature.new(
"http://api.phonegap.com/1.0/badfeature",
"true"
)
good_feature = Confetti::Config::Feature.new(
"http://api.phonegap.com/1.0/network",
"true"
)
@config.feature_set << bad_feature
@config.feature_set << good_feature
@template = @template_class.new @config
@template.capabilities.should == [{:name => "ID_CAP_NETWORKING"}]
end
end
end

describe "with a good config object" do

describe "on rendering" do

it "should render a valid wp7 manifest" do
@config = Confetti::Config.new "#{fixture_dir}/config.xml"
@template = @template_class.new @config
@template.render.should == File.read(
"#{fixture_dir}/windowsphone8/WMAppManifest.xml"
)
end

it "should add a feature when a valid on is found" do
@config = Confetti::Config.new
feature = Confetti::Config::Feature.new(
"http://api.phonegap.com/1.0/geolocation",
"true"
)
@config.feature_set << feature
@template = @template_class.new @config
@template.capabilities.should == [{:name=>"ID_CAP_LOCATION"}]
end

it "should add default capabilities when none are specified" do
@config = Confetti::Config.new
@template = @template_class.new @config
@template.capabilities.should == [
{:name => "ID_CAP_CONTACTS"},
{:name => "ID_CAP_IDENTITY_DEVICE"},
{:name => "ID_CAP_ISV_CAMERA"},
{:name => "ID_CAP_LOCATION"},
{:name => "ID_CAP_MICROPHONE"},
{:name => "ID_CAP_NETWORKING"},
]
end

it "should no add any capabilities when preference permissions is none" do
@config = Confetti::Config.new
@template = @template_class.new @config
@config.preference_set <<
Confetti::Config::Preference.new("permissions", "none")
@template.capabilities.should == []
end
end
end

describe "should write a valid manifest file" do

it "should write the file" do
@config = Confetti::Config.new
@config.feature_set <<
Confetti::Config::Feature.new(
"http://plugins.phonegap.com/ChildBrowser/2.0.1",
'true'
)
@config.feature_set <<
Confetti::Config::Feature.new(
"http://api.phonegap.com/1.0/geolocation",
'true'
)
@template = @template_class.new @config
@template.capabilities.should == [
{:name => "ID_CAP_LOCATION"},
]
lambda { @template.render }.should_not raise_error
end
end

describe "description" do
before do
@config = Confetti::Config.new "#{fixture_dir}/config-long-desc.xml"
@template = @template_class.new(@config)
end

it "should truncate the description to < 250 characters" do
@template.description.length.should be < 250
end
end

describe "version" do
before do
@config = Confetti::Config.new
@template = @template_class.new(@config)
end

it "should normalize the version to four parts" do
@config.version_string = "1.0.0"
@template.version.should == "1.0.0.0"
end

it "should ensure the non-initial numbers are one digit" do
# THIS IS STUPID
@config.version_string = "2012.05.20"
@template.version.should == "2012.0.2.0"
end

it "should ensure letters are converted to numbers" do
@config.version_string = "1.3.a"
@template.version.should == "1.3.0.0"
end
end

describe "author" do
before do
@config = Confetti::Config.new "spec/fixtures/config.xml"
@template = @template_class.new(@config)
end

it "should return the Confetti Author name in the normal case" do
@template.author.should == "Andrew Lunny"
end

it "should truncate the field to 50 chars or less" do
me = "Andrew John Lunny, son of William and Vivian, brother of Hugo"
short = "Andrew John Lunny, son of William and Vivian, brot"
@config.author.name = me
@template.author.should == short
end
end
end