alfredo 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +12 -9
- data/lib/alfredo/item.rb +27 -9
- data/lib/alfredo/version.rb +1 -1
- data/spec/item_spec.rb +34 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODdiNzA4YzAzYTgyZTRiNGJiZGQ1NjQ5ZWY0MWIwNmY4ZTU1NWZkMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjBhNGFmODViYTFmZmUzY2MyMmE2YTA3NmRhNWUwN2QyMzE5NThkMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Yjc5YjZjNGY3MDQ1ODc2ZjZjMTc2Yzc0NDhhMWRjNzBlMTY5NzcyODMxYmNj
|
10
|
+
Y2UzY2E0OWYzNGFhNjdiOWY3MDQ2MTVkZDBmYjRjZjEzNDBhY2MxYTQwNzQ1
|
11
|
+
YTMyMmI2NjM0MjljYzMyOTQ5NGM3YzJlOTc1ZTljMTZmOTliYTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODA1ZTk2ODZiYjAxOWNiZWNkMTdhNjEyNTAwNjQ2NDlmM2ZhOGI1NjI0ODFj
|
14
|
+
ZjBkYzdlMjRjYzVkZWNjMDk2MjE4MmI2ZmVlNmIyOWE0NzNiZTcxM2EwOTFk
|
15
|
+
ODViZjZiOWU2NzNlMTMyYzA2N2YxOWEzZjU4ZWIwMzVlNDVmOGI=
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# Alfredo
|
2
2
|
|
3
3
|
Alfredo is wrapper for Alfred 2's new Workflow system. It generates a
|
4
|
-
XML response based on the
|
5
|
-
|
6
|
-
I'm pretty sure Alfredo is not feature complete, so pull requests that
|
7
|
-
fix or add features will be appreciated.
|
4
|
+
XML response based on the information in the [Alfred
|
5
|
+
Forums](http://www.alfredforum.com/topic/5-generating-feedback-in-workflows/).
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -29,13 +27,18 @@ workflow.output!
|
|
29
27
|
|
30
28
|
Parameters available for `Alfredo::Item.new` are:
|
31
29
|
|
32
|
-
*
|
33
|
-
* `subtitle`
|
30
|
+
* `title` (shown in large text in the results)
|
31
|
+
* `subtitle` (shown under the title in smaller text)
|
34
32
|
* `arg` (argument that can be passed on to next steps in the workflow)
|
35
|
-
* `uid`
|
36
|
-
* `icon_path` (path of icon, relative to workflow directory)
|
33
|
+
* `uid` (value that Alfred uses to learn about your usage)
|
34
|
+
* `icon_path` (path of icon or file, relative to workflow directory)
|
37
35
|
* `icon_type`
|
38
|
-
*
|
36
|
+
* `fileicon` (uses the icon associated with a file)
|
37
|
+
* `filetype` (uses the icon associated with the type of a file)
|
38
|
+
* `type` (when `file` allows result action for files)
|
39
|
+
|
40
|
+
More info is available at the [Alfred
|
41
|
+
Forums](http://www.alfredforum.com/topic/5-generating-feedback-in-workflows/).
|
39
42
|
|
40
43
|
## Contributing
|
41
44
|
|
data/lib/alfredo/item.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Alfredo
|
2
2
|
class Item
|
3
|
-
attr_accessor :title, :subtitle, :arg, :uid, :icon_path, :icon_type, :type
|
3
|
+
attr_accessor :title, :subtitle, :arg, :uid, :icon_path, :icon_type, :type, :valid, :autocomplete
|
4
4
|
|
5
5
|
def initialize(attributes = {})
|
6
6
|
attributes.each do |attribute,value|
|
@@ -9,26 +9,44 @@ module Alfredo
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def uid
|
12
|
-
@uid ||
|
12
|
+
@uid || title
|
13
13
|
end
|
14
14
|
|
15
15
|
def icon_type
|
16
|
-
@icon_type
|
16
|
+
@icon_type if %w{fileicon filetype}.include? @icon_type
|
17
17
|
end
|
18
18
|
|
19
|
+
def valid
|
20
|
+
if @valid == false
|
21
|
+
'no'
|
22
|
+
else
|
23
|
+
'yes'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def autocomplete
|
28
|
+
@autocomplete || title
|
29
|
+
end
|
30
|
+
|
19
31
|
def type
|
20
|
-
@type
|
32
|
+
@type if @type == 'file'
|
21
33
|
end
|
22
34
|
|
23
35
|
def build_xml
|
24
36
|
Nokogiri::XML::Builder.new do |xml|
|
25
|
-
xml.item(arg: arg, uid: uid, valid:
|
37
|
+
xml.item(arg: arg, uid: uid, valid: valid, autocomplete: autocomplete) {
|
26
38
|
xml.title title
|
27
39
|
xml.subtitle subtitle
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
40
|
+
if icon_path
|
41
|
+
if icon_type
|
42
|
+
xml.icon(type: icon_type) {
|
43
|
+
xml.text icon_path
|
44
|
+
}
|
45
|
+
else
|
46
|
+
xml.icon icon_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
xml.type type if type
|
32
50
|
}
|
33
51
|
end.doc.children.first
|
34
52
|
end
|
data/lib/alfredo/version.rb
CHANGED
data/spec/item_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'alfredo'
|
|
3
3
|
describe 'Alfredo::Item' do
|
4
4
|
describe '#build_xml' do
|
5
5
|
before do
|
6
|
-
@item = Alfredo::Item.new(title: 'foo', subtitle: 'bar', arg: 'baz', uid: 123, icon_path: 'icon.png', icon_type: 'fileicon', type: 'file')
|
6
|
+
@item = Alfredo::Item.new(title: 'foo', subtitle: 'bar', arg: 'baz', uid: 123, icon_path: 'icon.png', icon_type: 'fileicon', type: 'file', autocomplete: 'moo')
|
7
7
|
|
8
8
|
@xml = @item.build_xml
|
9
9
|
end
|
@@ -24,31 +24,54 @@ describe 'Alfredo::Item' do
|
|
24
24
|
@xml.xpath('/item/@uid').first.text.should eq '123'
|
25
25
|
end
|
26
26
|
|
27
|
-
it 'should
|
27
|
+
it 'should set uid to title when uid not set' do
|
28
28
|
@item.uid = nil
|
29
|
-
@item.build_xml.xpath('/item/@uid').first.text.should
|
29
|
+
@item.build_xml.xpath('/item/@uid').first.text.should eq @item.title
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'should set icon_path' do
|
32
|
+
it 'should set icon to icon_path' do
|
33
33
|
@xml.xpath('/item/icon').first.text.should eq 'icon.png'
|
34
34
|
end
|
35
35
|
|
36
|
-
it 'should set
|
36
|
+
it 'should not set icon when no icon_path not present' do
|
37
|
+
@item.icon_path = nil
|
38
|
+
@item.build_xml.xpath('/item/icon').size.should eq 0
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should set icon_type for fileicon' do
|
37
42
|
@xml.xpath('/item/icon/@type').first.text.should eq 'fileicon'
|
38
43
|
end
|
39
44
|
|
40
|
-
it 'should
|
45
|
+
it 'should set icon_type for filetype' do
|
46
|
+
@item.icon_type = 'filetype'
|
47
|
+
@item.build_xml.xpath('/item/icon/@type').first.text.should eq 'filetype'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should not set icon_type when invalid' do
|
41
51
|
@item.icon_type = nil
|
42
|
-
@item.build_xml.xpath('/item/icon/@type').
|
52
|
+
@item.build_xml.xpath('/item/icon/@type').size.should eq 0
|
43
53
|
end
|
44
54
|
|
45
|
-
it 'should set type' do
|
55
|
+
it 'should set type only when its file' do
|
46
56
|
@xml.xpath('/item/type').first.text.should eq 'file'
|
47
57
|
end
|
48
58
|
|
49
|
-
it 'should
|
50
|
-
@item.type =
|
51
|
-
@item.build_xml.xpath('/item/type').
|
59
|
+
it 'should not set type when its invalid' do
|
60
|
+
@item.type = 'foo'
|
61
|
+
@item.build_xml.xpath('/item/type').size.should eq 0
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should set valid to yes by default' do
|
65
|
+
@xml.xpath('/item/@valid').first.text.should eq 'yes'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should set valid to no if its false' do
|
69
|
+
@item.valid = false
|
70
|
+
@item.build_xml.xpath('/item/@valid').first.text.should eq 'no'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should set autocomplete' do
|
74
|
+
@xml.xpath('/item/@autocomplete').first.text.should eq 'moo'
|
52
75
|
end
|
53
76
|
end
|
54
77
|
end
|