alfred-workflow 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2013-03-21
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/alfred.rb
6
+ lib/alfred/version.rb
@@ -0,0 +1,64 @@
1
+ = alfred-workflow
2
+
3
+ * https://github.com/zhaocai/alfred-workflow
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ruby Gem helper for building Alfred workflow (http://www.alfredapp.com).
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Functions for finding your bundle ID, cache and storage paths, and query arguments.
12
+ * Functions for reading and writing plist files.
13
+ * Shows exceptions and debug output in the Mac OS X Console
14
+ * A class to simplify generating feedback XML for Alfred.
15
+ * Adds ruby gems repositories to the workflow bundle so you can package gems with your workflow.
16
+ * A class to simplify saving and retrieving settings.
17
+
18
+
19
+ == SYNOPSIS:
20
+
21
+
22
+ == REQUIREMENTS:
23
+
24
+
25
+ == INSTALL:
26
+
27
+ * gem install alfred-workflow
28
+
29
+ == USAGE:
30
+
31
+
32
+ == DEVELOPERS:
33
+
34
+ After checking out the source, run:
35
+
36
+ $ rake newb
37
+
38
+ This task will install any missing dependencies, run the tests/specs,
39
+ and generate the RDoc.
40
+
41
+ == LICENSE:
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2013, Zhao Cai
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
64
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ # Hoe.plugin :bundler
7
+ # Hoe.plugin :compiler
8
+ # Hoe.plugin :email
9
+ # Hoe.plugin :gem_prelude_sucks
10
+ Hoe.plugin :gemspec
11
+ Hoe.plugin :git
12
+ # Hoe.plugin :inline
13
+ # Hoe.plugin :manualgen
14
+ # Hoe.plugin :minitest
15
+ # Hoe.plugin :perforce
16
+ # Hoe.plugin :racc
17
+ # Hoe.plugin :rcov
18
+ # Hoe.plugin :rubyforge
19
+ # Hoe.plugin :rubygems
20
+ # Hoe.plugin :seattlerb
21
+
22
+ Hoe.spec 'alfred-workflow' do
23
+
24
+ developer('Zhao Cai', 'caizhaoff@gmail.com')
25
+
26
+ extra_deps << ['plist', '~> 3.1.0']
27
+ extra_deps << ['logging', '~> 1.8.0']
28
+ end
29
+
30
+ # vim: syntax=ruby
@@ -0,0 +1,200 @@
1
+ require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
2
+
3
+ require 'plist'
4
+ require 'fileutils'
5
+ require 'logging'
6
+ require "rexml/document"
7
+
8
+ require 'alfred/version'
9
+
10
+ module Alfred
11
+
12
+ class AlfredError < RuntimeError
13
+ def self.status_code(code)
14
+ define_method(:status_code) { code }
15
+ end
16
+ end
17
+
18
+ class ObjCError < AlfredError; status_code(1) ; end
19
+ class NoBundleIDError < AlfredError; status_code(2) ; end
20
+ class NoMethodError < AlfredError; status_code(13) ; end
21
+ class PathError < AlfredError; status_code(14) ; end
22
+
23
+ class << self
24
+
25
+ def with_friendly_error(alfred = Alfred::Core.new, &blk)
26
+ begin
27
+ yield alfred
28
+ rescue AlfredError => e
29
+ alfred.ui.error e.message
30
+ alfred.ui.debug e.backtrace.join("\n")
31
+ exit e.status_code
32
+ rescue Interrupt => e
33
+ alfred.ui.error "\nQuitting..."
34
+ alfred.ui.debug e.backtrace.join("\n")
35
+ exit 1
36
+ rescue SystemExit => e
37
+ exit e.status
38
+ rescue Exception => e
39
+ alfred.ui.error(
40
+ "Unfortunately, a fatal error has occurred. Please seek help in the Alfred Forum or raise an issue in \n" \
41
+ "github. Thanks!\n #{e.inspect} #{e.backtrace.join("\n")}\n")
42
+ raise e
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+ class Core
49
+ attr_reader :query
50
+
51
+ def initialize
52
+ end
53
+
54
+ def ui
55
+ raise NoBundleIDError unless bundle_id
56
+ @ui ||= Logger.new(bundle_id)
57
+ end
58
+
59
+ def feedback
60
+ raise NoBundleIDError unless bundle_id
61
+ @feedback ||= Feedback.new
62
+ end
63
+
64
+ def info_plist_path
65
+ path = File.join(File.dirname(__FILE__), '../info.plist')
66
+ raise PathError unless File.exist?(path)
67
+ path
68
+ end
69
+
70
+ def info_plist
71
+ @info_plist ||= Plist::parse_xml(info_plist_path)
72
+ end
73
+
74
+ # Returns nil if not set.
75
+ def bundle_id
76
+ info_plist['bundleid'] unless info_plist['bundleid'].empty?
77
+ end
78
+
79
+ def volatile_storage_path
80
+ raise NoBundleIDError unless bundle_id
81
+ path = "#{ENV['HOME']}/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/#{bundle_id}"
82
+ unless Dir.exist?(path)
83
+ FileUtils.makdir_p(path)
84
+ end
85
+ path
86
+ end
87
+
88
+ # Non-volatile storage directory for this bundle
89
+ def storage_path
90
+ raise NoBundleIDError unless bundle_id
91
+ path = "#{ENV['HOME']}/Library/Application Support/Alfred 2/Workflow Data/#{bundle_id}"
92
+ unless Dir.exist?(path)
93
+ FileUtils.makdir_p(path)
94
+ end
95
+ path
96
+ end
97
+
98
+ end
99
+
100
+
101
+
102
+
103
+
104
+
105
+ class Logger
106
+ def initialize(id)
107
+ @id = id
108
+ end
109
+
110
+ def info(msg)
111
+ logger.info msg
112
+ end
113
+ def warn(msg)
114
+ logger.warn msg
115
+ end
116
+ def debug(msg)
117
+ logger.debug msg
118
+ end
119
+ def error(msg)
120
+ logger.error msg
121
+ end
122
+ def fatal(msg)
123
+ logger.fatal msg
124
+ end
125
+
126
+ def logger
127
+ @logger ||= init_log
128
+ end
129
+
130
+ private
131
+
132
+ def init_log
133
+ @logger = Logging.logger[@id]
134
+ logger_file = File.expand_path("~/Library/Logs/Alfred-Workflow.log")
135
+ @logger.level = :debug
136
+ @logger.add_appenders(
137
+ Logging.appenders.file(logger_file)
138
+ )
139
+ @logger
140
+ end
141
+ end
142
+
143
+
144
+
145
+
146
+
147
+
148
+ class Feedback
149
+ attr_accessor :items
150
+
151
+ def initialize
152
+ @items = []
153
+ end
154
+
155
+ def add_item(opts = {})
156
+ opts[:subtitle] ||= ""
157
+ opts[:icon] ||= {:type => "default", :name => "icon.png"}
158
+ if opts[:uid].nil?
159
+ opts[:uid] = ''
160
+ end
161
+ opts[:arg] ||= opts[:title]
162
+ opts[:valid] ||= "yes"
163
+ opts[:autocomplete] ||= opts[:title]
164
+ opts[:type] ||= "default"
165
+
166
+ @items << opts unless opts[:title].nil?
167
+ end
168
+
169
+ def to_xml(items = @items)
170
+ document = REXML::Element.new("items")
171
+ items.each do |item|
172
+ new_item = REXML::Element.new('item')
173
+ new_item.add_attributes({
174
+ 'uid' => item[:uid],
175
+ 'arg' => item[:arg],
176
+ 'valid' => item[:valid],
177
+ 'autocomplete' => item[:autocomplete]
178
+ })
179
+ new_item.add_attributes('type' => 'file') if item[:type] == "file"
180
+
181
+ REXML::Element.new("title", new_item).text = item[:title]
182
+ REXML::Element.new("subtitle", new_item).text = item[:subtitle]
183
+
184
+ icon = REXML::Element.new("icon", new_item)
185
+ icon.text = item[:icon][:name]
186
+ icon.add_attributes('type' => 'fileicon') if item[:icon][:type] == "fileicon"
187
+
188
+ document << new_item
189
+ end
190
+
191
+ document.to_s
192
+ end
193
+ end
194
+
195
+
196
+
197
+
198
+
199
+ end
200
+
@@ -0,0 +1,3 @@
1
+ module Alfred
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alfred-workflow
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zhao Cai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: plist
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: logging
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.8.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.10'
62
+ - !ruby/object:Gem::Dependency
63
+ name: hoe
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.3'
78
+ description: Ruby Gem helper for building Alfred workflow (http://www.alfredapp.com).
79
+ email:
80
+ - caizhaoff@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files:
84
+ - History.txt
85
+ - Manifest.txt
86
+ - README.txt
87
+ files:
88
+ - History.txt
89
+ - Manifest.txt
90
+ - README.txt
91
+ - Rakefile
92
+ - lib/alfred.rb
93
+ - lib/alfred/version.rb
94
+ - .gemtest
95
+ homepage: https://github.com/zhaocai/alfred-workflow
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --main
100
+ - README.txt
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project: alfred-workflow
117
+ rubygems_version: 1.8.24
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Ruby Gem helper for building Alfred workflow (http://www.alfredapp.com).
121
+ test_files: []