alfredo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +1 -0
- data/alfredo.gemspec +25 -0
- data/lib/alfredo/item.rb +36 -0
- data/lib/alfredo/version.rb +3 -0
- data/lib/alfredo/workflow.rb +31 -0
- data/lib/alfredo.rb +4 -0
- data/spec/alfredo_spec.rb +1 -0
- data/spec/item_spec.rb +55 -0
- data/spec/workflow_spec.rb +57 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODViMmFhNjU4ZmRjMGI5OGMxZDM0Yzc5NWJiOWUyMzZhMGY1NzRjNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzY3MTk2YzU4YTI4MTc5MjNlYzM5NjY2ZjFlYWE0NWJmNjJjYjcwNg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjhiOTE0OGNhZWY2YTIwMWUwNmZmNWMxMTc1ZjUzODdjZDY5YmRmZTU4ZDNl
|
10
|
+
ZjBmYzg0YWExOWJmMGM0NjJmYzIzYmMyN2MzMWE0N2Q2ZWM2Zjk1ZWMxNTVi
|
11
|
+
ZWQ1NTQxNWM0NjllYjk0N2I5ZmMzOGNhM2QzZDRhYTIxMjg2YTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODY1NjU3Nzg1YTU0MjdhMzI2MjI3NjVmZTFlNjYxMDc3ZTk5MWZmMmY4ZTVj
|
14
|
+
Y2ZiZGNhMzk0YjViNjc5MzU0NjY3YjE2YTg5NzQ3OTFiYTMxMGVmZTM0Y2E5
|
15
|
+
YjlmMGRkMDgwMTM0ZGE2NjgxOGEwMDA0MGNhZDBhZDM4MTU3MDU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dennis Paagman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Alfredo
|
2
|
+
|
3
|
+
Alfredo is wrapper for Alfred 2's new Workflow system. It generates a
|
4
|
+
XML response based on the work of
|
5
|
+
[alfred2-top-workflow](https://github.com/zhaocai/alfred2-top-workflow/tree/master/top).
|
6
|
+
I'm pretty sure Alfredo is not feature complete, so pull requests that
|
7
|
+
fix or add features will be appreciated.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem install alfredo
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Using Alfredo is pretty straightforward:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'alfredo'
|
19
|
+
|
20
|
+
# set up the workflow
|
21
|
+
workflow = Alfredo::Workflow.new
|
22
|
+
|
23
|
+
# you can add as many items as you want like this:
|
24
|
+
workflow << Alfredo::Item.new(...)
|
25
|
+
|
26
|
+
# At the end of your script call:
|
27
|
+
workflow.output!
|
28
|
+
```
|
29
|
+
|
30
|
+
Parameters available for `Alfredo::Item.new` are:
|
31
|
+
|
32
|
+
* ``title``
|
33
|
+
* `subtitle`
|
34
|
+
* `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)
|
37
|
+
* `icon_type`
|
38
|
+
* `type`
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/alfredo.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alfredo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alfredo"
|
8
|
+
spec.version = Alfredo::VERSION
|
9
|
+
spec.authors = ["Dennis Paagman"]
|
10
|
+
spec.email = ["dennispaagman@gmail.com"]
|
11
|
+
spec.description = %q{Wrapper for Alfred 2's Workflows}
|
12
|
+
spec.summary = %q{Easy generation of XML responses usable in Alfred 2 Workflows}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
24
|
+
spec.add_dependency 'nokogiri'
|
25
|
+
end
|
data/lib/alfredo/item.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Alfredo
|
2
|
+
class Item
|
3
|
+
attr_accessor :title, :subtitle, :arg, :uid, :icon_path, :icon_type, :type
|
4
|
+
|
5
|
+
def initialize(attributes = {})
|
6
|
+
attributes.each do |attribute,value|
|
7
|
+
send("#{attribute}=", value) if respond_to? "#{attribute}="
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def uid
|
12
|
+
@uid || "#{title}_#{Time.now.to_i}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def icon_type
|
16
|
+
@icon_type || 'default'
|
17
|
+
end
|
18
|
+
|
19
|
+
def type
|
20
|
+
@type || 'default'
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_xml
|
24
|
+
Nokogiri::XML::Builder.new do |xml|
|
25
|
+
xml.item(arg: arg, uid: uid, valid: 'yes') {
|
26
|
+
xml.title title
|
27
|
+
xml.subtitle subtitle
|
28
|
+
xml.icon(type: icon_type) {
|
29
|
+
xml.text icon_path
|
30
|
+
}
|
31
|
+
xml.type type
|
32
|
+
}
|
33
|
+
end.doc.children.first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Alfredo
|
2
|
+
class Workflow
|
3
|
+
attr_accessor :items
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@items = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def <<(item)
|
10
|
+
@items << item if item.is_a? Alfredo::Item
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method :add, :<<
|
14
|
+
|
15
|
+
def to_xml
|
16
|
+
xml = Nokogiri::XML::Builder.new do |xml|
|
17
|
+
xml.items
|
18
|
+
end.doc
|
19
|
+
|
20
|
+
items.each do |item|
|
21
|
+
xml.xpath('/items').first.add_child(item.build_xml)
|
22
|
+
end
|
23
|
+
|
24
|
+
xml.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def output!
|
28
|
+
puts to_xml
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/alfredo.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'alfredo'
|
data/spec/item_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'alfredo'
|
2
|
+
|
3
|
+
describe 'Alfredo::Item' do
|
4
|
+
describe '#build_xml' do
|
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')
|
7
|
+
|
8
|
+
@xml = @item.build_xml
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should set title' do
|
12
|
+
@xml.xpath('/item/title').first.text.should eq 'foo'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set subtitle' do
|
16
|
+
@xml.xpath('/item/subtitle').first.text.should eq 'bar'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set arg' do
|
20
|
+
@xml.xpath('/item/@arg').first.text.should eq 'baz'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set uid' do
|
24
|
+
@xml.xpath('/item/@uid').first.text.should eq '123'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should generate uid when not set' do
|
28
|
+
@item.uid = nil
|
29
|
+
@item.build_xml.xpath('/item/@uid').first.text.should match /#{@item.title}_[0-9]+/
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should set icon_path' do
|
33
|
+
@xml.xpath('/item/icon').first.text.should eq 'icon.png'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should set icon_type' do
|
37
|
+
@xml.xpath('/item/icon/@type').first.text.should eq 'fileicon'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should use default icon_type when not set' do
|
41
|
+
@item.icon_type = nil
|
42
|
+
@item.build_xml.xpath('/item/icon/@type').first.text.should eq 'default'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set type' do
|
46
|
+
@xml.xpath('/item/type').first.text.should eq 'file'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should use default type when not set' do
|
50
|
+
@item.type = nil
|
51
|
+
@item.build_xml.xpath('/item/type').first.text.should eq 'default'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'alfredo'
|
2
|
+
|
3
|
+
describe 'Alfredo::Workflow' do
|
4
|
+
before do
|
5
|
+
@workflow = Alfredo::Workflow.new
|
6
|
+
3.times do
|
7
|
+
@workflow.items << Alfredo::Item.new(title: SecureRandom.hex)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#<<" do
|
12
|
+
it "should add Alfredo::Item" do
|
13
|
+
item = Alfredo::Item.new
|
14
|
+
|
15
|
+
@workflow << item
|
16
|
+
@workflow.items.should include(item)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not add a random thing" do
|
20
|
+
item = 'foo'
|
21
|
+
|
22
|
+
@workflow << item
|
23
|
+
@workflow.items.should_not include(item)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#add" do
|
28
|
+
it "should be an alias for <<" do
|
29
|
+
@workflow.method(:add).should eq(@workflow.method(:<<))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_xml" do
|
34
|
+
before do
|
35
|
+
@xml = Nokogiri::XML.parse(@workflow.to_xml)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return valid XML" do
|
39
|
+
@xml.should be_an_instance_of(Nokogiri::XML::Document)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have an <items> root" do
|
43
|
+
@xml.xpath('/items').size.should eq 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should have an <item> per item in Workflow" do
|
47
|
+
@xml.xpath('/items/item').size.should eq @workflow.items.size
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#output!" do
|
52
|
+
it "should output XML to the STDOUT" do
|
53
|
+
$stdout.should_receive(:puts).with(@workflow.to_xml)
|
54
|
+
@workflow.output!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alfredo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Paagman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Wrapper for Alfred 2's Workflows
|
70
|
+
email:
|
71
|
+
- dennispaagman@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- alfredo.gemspec
|
82
|
+
- lib/alfredo.rb
|
83
|
+
- lib/alfredo/item.rb
|
84
|
+
- lib/alfredo/version.rb
|
85
|
+
- lib/alfredo/workflow.rb
|
86
|
+
- spec/alfredo_spec.rb
|
87
|
+
- spec/item_spec.rb
|
88
|
+
- spec/workflow_spec.rb
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.3
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Easy generation of XML responses usable in Alfred 2 Workflows
|
113
|
+
test_files:
|
114
|
+
- spec/alfredo_spec.rb
|
115
|
+
- spec/item_spec.rb
|
116
|
+
- spec/workflow_spec.rb
|