Permalink
Browse files

finishing up generate

  • Loading branch information...
1 parent a479945 commit e59d575f963a7d16ce2c9aff79c11b35f5cc20e0 @lgleasain lgleasain committed May 20, 2013
View
1 bin/pk
@@ -5,6 +5,7 @@ require 'terminal-table'
$:.push File.expand_path("../../lib", __FILE__)
require 'passbook'
+require 'utils/command_utils'
HighLine.track_eof = false # Fix for built-in Ruby
Signal.trap("INT") {} # Suppress backtrace when exiting command
View
@@ -54,13 +54,6 @@
alias_command :archive, :build
alias_command :b, :build
-# this was added for testability because I couldn't figure out something better.
-class CommandUtils
- def get_assets(directory)
- Dir[File.join(directory, '*')]
- end
-end
-
private
def validate_output_filepath!
View
@@ -3,6 +3,8 @@
require 'commands/build'
require 'commands/generate'
#require 'commands/serve'
+# this was added for testability because I couldn't figure out something better.
+
private
def determine_directory!
@@ -24,3 +26,6 @@ def validate_directory!
def validate_certificate!
say_error "Missing or invalid certificate file" and abort if @certificate.nil? or not File.exist?(@certificate)
end
+
+
+
View
@@ -11,17 +11,16 @@
c.action do |args, options|
@directory = args.first
@directory ||= ask "Enter a passbook name: "
-
say_error "Missing pass name" and abort if @directory.nil? or @directory.empty?
say_error "Directory #{@directory} already exists" and abort if File.directory?(@directory)
say_error "File exists at #{@directory}" and abort if File.exist?(@directory)
@type = options.type
- #determine_type! unless @type
- #validate_type!
+ determine_type! unless @type
+ validate_type!
FileUtils.mkdir_p @directory
- FileUtils.cp File.join(File.dirname(__FILE__), '..', 'templates', "#{@type}.json"), File.join(@directory, 'pass.json')
+ FileUtils.cp File.join(CommandUtils.get_current_directory, '..', 'templates', "#{@type}.json"), File.join(@directory, 'pass.json')
['icon.png', 'icon@2x.png'].each do |file|
FileUtils.touch File.join(@directory, file)
end
@@ -36,10 +35,10 @@
private
def determine_type!
- @type ||= choose "Select a pass type", *Dubai::Passbook::Pass::TYPES
+ @type ||= choose "Select a pass type", *Passbook::PKPass::TYPES
end
def validate_type!
- say_error %{Invalid type: "#{@type}", expected one of: [#{Dubai::Passbook::Pass::TYPES.join(', ')}]} unless Dubai::Passbook::Pass::TYPES.include?(@type)
+ say_error %{Invalid type: "#{@type}", expected one of: [#{Passbook::PKPass::TYPES.join(', ')}]} and abort unless Passbook::PKPass::TYPES.include?(@type)
end
@@ -11,13 +11,13 @@
"primaryFields" : [
{
"key" : "origin",
- "label" : "San Francisco",
- "value" : "SFO"
+ "label" : "Atlanta",
+ "value" : "ATL"
},
{
"key" : "destination",
- "label" : "London",
- "value" : "LHR"
+ "label" : "Johannesburg",
+ "value" : "JNB"
}
],
"secondaryFields" : [
@@ -36,20 +36,20 @@
{
"key" : "passenger-name",
"label" : "Passenger",
- "value" : "John Appleseed"
+ "value" : "Honey Badger"
}
],
"transitType" : "PKTransitTypeAir",
"barcode" : {
- "message" : "ABC123",
+ "message" : "DL123",
"format" : "PKBarcodeFormatQR",
"messageEncoding" : "iso-8859-1"
},
"backFields" : [
{
"key" : "terms",
"label" : "Terms and Conditions",
- "value" : "Lorem ipsum dolar sit amet"
+ "value" : "Valid for date of travel only"
}
]
}
@@ -0,0 +1,33 @@
+{
+ "formatVersion" : 1,
+ "passTypeIdentifier" : "pass.com.example.coupon",
+ "description" : "Example Coupon",
+ "teamIdentifier": "Example",
+ "organizationName": "Example",
+ "serialNumber" : "123456",
+ "foregroundColor": "#FFFFFF",
+ "backgroundColor": "#C799FF",
+ "generic" : {
+ "primaryFields" : [
+
+ ],
+ "secondaryFields" : [
+
+ ],
+ "auxiliaryFields" : [
+
+ ],
+ "barcode" : {
+ "message" : "ABCD 123 EFGH 456 IJKL 789 MNOP",
+ "format" : "PKBarcodeFormatPDF417",
+ "messageEncoding" : "iso-8859-1"
+ },
+ "backFields" : [
+ {
+ "key" : "terms",
+ "label" : "Terms and Conditions",
+ "value" : "T's and C's Apply"
+ }
+ ]
+ }
+}
@@ -0,0 +1,33 @@
+{
+ "formatVersion" : 1,
+ "passTypeIdentifier" : "pass.com.example.event-ticket",
+ "description" : "Example Event Ticket",
+ "teamIdentifier": "Example",
+ "organizationName": "Example",
+ "serialNumber" : "123456",
+ "foregroundColor": "#FFFFFF",
+ "backgroundColor": "#FF5453",
+ "generic" : {
+ "primaryFields" : [
+
+ ],
+ "secondaryFields" : [
+
+ ],
+ "auxiliaryFields" : [
+
+ ],
+ "barcode" : {
+ "message" : "ABCD 123 EFGH 456 IJKL 789 MNOP",
+ "format" : "PKBarcodeFormatPDF417",
+ "messageEncoding" : "iso-8859-1"
+ },
+ "backFields" : [
+ {
+ "key" : "terms",
+ "label" : "Terms and Conditions",
+ "value" : "T's and C's apply"
+ }
+ ]
+ }
+}
@@ -0,0 +1,33 @@
+{
+ "formatVersion" : 1,
+ "passTypeIdentifier" : "pass.com.example.generic",
+ "description" : "Example Generic Pass",
+ "teamIdentifier": "Example",
+ "organizationName": "Example",
+ "serialNumber" : "123456",
+ "foregroundColor": "#FFFFFF",
+ "backgroundColor": "#444444",
+ "generic" : {
+ "primaryFields" : [
+
+ ],
+ "secondaryFields" : [
+
+ ],
+ "auxiliaryFields" : [
+
+ ],
+ "barcode" : {
+ "message" : "ABCD 123 EFGH 456 IJKL 789 MNOP",
+ "format" : "PKBarcodeFormatPDF417",
+ "messageEncoding" : "iso-8859-1"
+ },
+ "backFields" : [
+ {
+ "key" : "terms",
+ "label" : "Terms and Conditions",
+ "value" : "Put your terms here"
+ }
+ ]
+ }
+}
@@ -0,0 +1,33 @@
+{
+ "formatVersion" : 1,
+ "passTypeIdentifier" : "pass.com.example.store-card",
+ "description" : "Example Store Card",
+ "teamIdentifier": "Example",
+ "organizationName": "Example",
+ "serialNumber" : "123456",
+ "foregroundColor": "#FFFFFF",
+ "backgroundColor": "#AFC1E3",
+ "generic" : {
+ "primaryFields" : [
+
+ ],
+ "secondaryFields" : [
+
+ ],
+ "auxiliaryFields" : [
+
+ ],
+ "barcode" : {
+ "message" : "ABCD 123 EFGH 456 IJKL 789 MNOP",
+ "format" : "PKBarcodeFormatPDF417",
+ "messageEncoding" : "iso-8859-1"
+ },
+ "backFields" : [
+ {
+ "key" : "terms",
+ "label" : "Terms and Conditions",
+ "value" : "T's and C's apply"
+ }
+ ]
+ }
+}
View
@@ -7,6 +7,8 @@ module Passbook
class PKPass
attr_accessor :pass, :manifest_files
+ TYPES = ['boarding-pass', 'coupon', 'event-ticket', 'store-card', 'generic']
+
def initialize pass
@pass = pass
@manifest_files = []
View
@@ -0,0 +1,12 @@
+# this was added for testability because I couldn't figure out something better.
+class CommandUtils
+ def self.get_assets(directory)
+ Dir[File.join(directory, '*')]
+ end
+
+ def self.get_current_directory
+ File.dirname(__FILE__)
+ end
+end
+
+
@@ -10,12 +10,7 @@
context 'command' do
specify 'missing directory' do
- begin
- lambda {
- run 'build'
- }.should raise_error(SystemExit, ' ')
-
- rescue
+ run_command 'build' do
@output.string.should eq "\e[31mMissing argument\e[0m\n"
end
end
@@ -29,12 +24,8 @@
end
specify 'no certificate file' do
- begin
- lambda {
- run('build', 'scraps')
- }.should raise_error(SystemExit, ' ')
- rescue
- @output.string.should eq "\e[31mMissing or invalid certificate file\e[0m\n"
+ run_command 'build', 'scraps' do
+ @output.string.should eq "\e[31mMissing or invalid certificate file\e[0m\n"
end
end
@@ -98,17 +89,4 @@
end
end
- def run_raw_command(*args)
- lambda{
- run(*args)
- }.should raise_error(SystemExit, ' ')
- end
-
- def run_command(*args, &block)
- begin
- run_raw_command *args
- rescue
- yield
- end
- end
end
@@ -1,6 +1,7 @@
require 'spec_helper'
require 'terminal-table'
require 'commander/import'
+require 'utils/command_utils'
def load_commands
Dir['lib/commands/**/*.rb'].each {|f|
@@ -53,3 +54,16 @@ def run *args
end
end
+def run_raw_command(*args)
+ lambda{
+ run(*args)
+ }.should raise_error(SystemExit, ' ')
+end
+
+def run_command(*args, &block)
+ begin
+ run_raw_command *args
+ rescue
+ yield
+ end
+end
Oops, something went wrong.

0 comments on commit e59d575

Please sign in to comment.