alfred-workflow 1.4.0 → 1.5.0
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.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/alfred.rb +4 -1
- data/lib/alfred/feedback.rb +34 -4
- data/lib/alfred/version.rb +1 -1
- data/spec/feedback_spec.rb +2 -13
- data/spec/spec_helper.rb +27 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
SHA1:
|
|
3
|
-
metadata.gz: 8b3c5fffe416e05c99f4baad880f92456cc10fd8
|
|
4
|
-
data.tar.gz: 55a135c15ccf8448be4ffdd421537dfd05d6f6c9
|
|
5
2
|
SHA512:
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
data.tar.gz: 23623140489e12203cca05b87d40364423b37f3e01ade13d1df9909566feaf9a5304e1e3d5803228787791114ba1402f0e8b5654e5e4cb4f9ea14f59059fe844
|
|
4
|
+
metadata.gz: 32d00acc1222bc5d87b257a8304e3055a3e2b87bfa1ed6bb150cc8c6ad5e48c51ae92bae30625cf7c59c90e3b87656b3fcb78d9580e568217ed2b3eabcbbfcc4
|
|
5
|
+
SHA1:
|
|
6
|
+
data.tar.gz: eefe1cd9415f97fa9130ec19d2fa22776a432ca4
|
|
7
|
+
metadata.gz: 51f3ad55e83b3a4e16f90ec9f956b0391bf8267c
|
data/README.md
CHANGED
|
@@ -15,13 +15,13 @@ alfred-workflow is a ruby Gem helper for building [Alfred](http://www.alfredapp.
|
|
|
15
15
|
|
|
16
16
|
* Use standard [bundler][gembundler] to easily package, manage, and update ruby gems in the workflow.
|
|
17
17
|
* Friendly exception and debug output to the Mac OS X Console.
|
|
18
|
+
* Automate saving and loading cached feedback
|
|
18
19
|
* Automate rescue feedback items to alfred when something goes wrong.
|
|
19
20
|
* Functions to easily load and save user configuration (in YAML)
|
|
20
21
|
* Functions for smart case query filter of feedback results.
|
|
21
22
|
* Functions for finding the bundle ID, cache and storage paths, and query arguments.
|
|
22
23
|
* Functions for reading and writing plist files.
|
|
23
24
|
* Functions to simplify generating feedback XML for Alfred.
|
|
24
|
-
* Functions to simplify saving and retrieving settings.
|
|
25
25
|
|
|
26
26
|
## SYNOPSIS:
|
|
27
27
|
|
data/lib/alfred.rb
CHANGED
|
@@ -81,6 +81,10 @@ module Alfred
|
|
|
81
81
|
@setting ||= Setting.new(self)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
+
def with_cached_feedback(&blk)
|
|
85
|
+
@feedback = CachedFeedback.new(self, &blk)
|
|
86
|
+
end
|
|
87
|
+
|
|
84
88
|
def feedback
|
|
85
89
|
raise NoBundleIDError unless bundle_id
|
|
86
90
|
@feedback ||= Feedback.new
|
|
@@ -115,7 +119,6 @@ module Alfred
|
|
|
115
119
|
end
|
|
116
120
|
|
|
117
121
|
|
|
118
|
-
|
|
119
122
|
def rescue_feedback(opts = {})
|
|
120
123
|
default_opts = {
|
|
121
124
|
:title => "Failed Query!",
|
data/lib/alfred/feedback.rb
CHANGED
|
@@ -33,15 +33,45 @@ module Alfred
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
# serialize
|
|
36
|
-
def dump(
|
|
37
|
-
File.open(
|
|
36
|
+
def dump(to_file)
|
|
37
|
+
File.open(to_file, "wb") { |f| Marshal.dump(self, f) }
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
class << self
|
|
41
|
-
def load(
|
|
42
|
-
File.open(
|
|
41
|
+
def load(from_file)
|
|
42
|
+
File.open(from_file, "rb") { |f| Marshal.load(f) }
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
|
|
48
|
+
class CachedFeedback < Feedback
|
|
49
|
+
def initialize(alfred, &blk)
|
|
50
|
+
super()
|
|
51
|
+
@core = alfred
|
|
52
|
+
|
|
53
|
+
instance_eval(&blk) if block_given?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def use_cache_file(opts = {})
|
|
57
|
+
@cf_file = opts[:file] if opts[:file]
|
|
58
|
+
@cf_file_valid_time = opts[:expire] if opts[:expire]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def cache_file
|
|
62
|
+
@cf_file ||= File.join(@core.volatile_storage_path, "cached_feedback")
|
|
63
|
+
end
|
|
64
|
+
def get_cached_feedback
|
|
65
|
+
return nil unless File.exist?(cache_file)
|
|
66
|
+
if @cf_file_valid_time
|
|
67
|
+
return nil if Time.now - File.ctime(cache_file) > @cf_file_valid_time
|
|
68
|
+
end
|
|
69
|
+
Feedback.load(@cf_file)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def put_cached_feedback
|
|
73
|
+
dump(cache_file)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
47
77
|
end
|
data/lib/alfred/version.rb
CHANGED
data/spec/feedback_spec.rb
CHANGED
|
@@ -8,6 +8,7 @@ describe "Feedback" do
|
|
|
8
8
|
@item_elements = %w{title subtitle icon}
|
|
9
9
|
@item_attributes = %w{uid arg autocomplete}
|
|
10
10
|
end
|
|
11
|
+
|
|
11
12
|
it "should create a basic XML response" do
|
|
12
13
|
@feedback.add_item(:uid => "uid" ,
|
|
13
14
|
:arg => "arg" ,
|
|
@@ -26,19 +27,7 @@ describe "Feedback" do
|
|
|
26
27
|
</items>
|
|
27
28
|
END
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
feedback_xml = REXML::Document.new(@feedback.to_xml)
|
|
31
|
-
|
|
32
|
-
expected_item = expected_xml.get_elements('/items/item')[0]
|
|
33
|
-
feedback_item = feedback_xml.get_elements('/items/item')[0]
|
|
34
|
-
|
|
35
|
-
@item_elements.each { |i|
|
|
36
|
-
expected_item.elements[i].text.should == feedback_item.elements[i].text
|
|
37
|
-
}
|
|
38
|
-
@item_attributes.each { |i|
|
|
39
|
-
expected_item.attributes[i].should == feedback_item.attributes[i]
|
|
40
|
-
}
|
|
41
|
-
|
|
30
|
+
compare_xml(xml_data, @feedback.to_xml).should == true
|
|
42
31
|
end
|
|
43
32
|
|
|
44
33
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
|
2
2
|
|
|
3
3
|
require "rspec"
|
|
4
|
+
require 'awesome_print'
|
|
5
|
+
require 'zucker/debug'
|
|
6
|
+
|
|
4
7
|
require "alfred"
|
|
5
8
|
|
|
6
9
|
RSpec.configure do |c|
|
|
@@ -20,3 +23,27 @@ class String
|
|
|
20
23
|
gsub(/^[ \t]{#{indent}}/, '')
|
|
21
24
|
end
|
|
22
25
|
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def compare_xml(expected_xml_data, feedback_xml_data)
|
|
29
|
+
item_elements = %w{title subtitle icon}
|
|
30
|
+
item_attributes = %w{uid arg autocomplete}
|
|
31
|
+
|
|
32
|
+
expected_xml = REXML::Document.new(expected_xml_data)
|
|
33
|
+
feedback_xml = REXML::Document.new(feedback_xml_data)
|
|
34
|
+
|
|
35
|
+
expected_item = expected_xml.get_elements('/items/item')[0]
|
|
36
|
+
feedback_item = feedback_xml.get_elements('/items/item')[0]
|
|
37
|
+
|
|
38
|
+
item_elements.each { |i|
|
|
39
|
+
unless expected_item.elements[i].text.eql? feedback_item.elements[i].text
|
|
40
|
+
return false
|
|
41
|
+
end
|
|
42
|
+
}
|
|
43
|
+
item_attributes.each { |i|
|
|
44
|
+
unless expected_item.attributes[i].eql? feedback_item.attributes[i]
|
|
45
|
+
return false
|
|
46
|
+
end
|
|
47
|
+
}
|
|
48
|
+
true
|
|
49
|
+
end
|