alfred-workflow 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest CHANGED
@@ -2,22 +2,13 @@
2
2
 
3
3
  require 'autotest/restart'
4
4
 
5
- # Autotest.add_hook :initialize do |at|
6
- # at.extra_files << "../some/external/dependency.rb"
7
- #
8
- # at.libs << ":../some/external"
9
- #
10
- # at.add_exception 'vendor'
11
- #
12
- # at.add_mapping(/dependency.rb/) do |f, _|
13
- # at.files_matching(/test_.*rb$/)
14
- # end
15
- #
16
- # %w(TestA TestB).each do |klass|
17
- # at.extra_class_map[klass] = "test/test_misc.rb"
18
- # end
19
- # end
5
+ # Include plugins
6
+ require 'autotest/fsevent'
7
+ require 'autotest/growl'
20
8
 
21
- # Autotest.add_hook :run_command do |at|
22
- # system "rake build"
23
- # end
9
+ Autotest.add_hook :initialize do |at|
10
+ %w{.git .DS_Store ._* vendor}.each { |exception| at.add_exception(exception) }
11
+
12
+ at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
13
+ false
14
+ end
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
+
5
+ source "https://rubygems.org/"
6
+
7
+ gem "plist", "~>3.1.0"
8
+ gem "logging", "~>1.8.0"
9
+
10
+ gem "rdoc", "~>3.10", :group => [:development, :test]
11
+ gem "hoe", "~>3.5", :group => [:development, :test]
12
+
13
+ # vim: syntax=ruby
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ hoe (3.5.2)
5
+ rake (>= 0.8, < 11.0)
6
+ json (1.7.7)
7
+ little-plugger (1.1.3)
8
+ logging (1.8.0)
9
+ little-plugger (>= 1.1.3)
10
+ multi_json (>= 1.3.6)
11
+ multi_json (1.3.7)
12
+ plist (3.1.0)
13
+ rake (10.0.3)
14
+ rdoc (3.12.2)
15
+ json (~> 1.4)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ hoe (~> 3.5)
22
+ logging (~> 1.8.0)
23
+ plist (~> 3.1.0)
24
+ rdoc (~> 3.10)
@@ -1,10 +1,18 @@
1
1
  .autotest
2
2
  .gemtest
3
+ .rspec
4
+ Gemfile
5
+ Gemfile.lock
3
6
  History.txt
4
7
  Manifest.txt
5
8
  README.md
6
9
  Rakefile
10
+ autotest/discover.rb
7
11
  lib/alfred.rb
8
12
  lib/alfred/feedback.rb
13
+ lib/alfred/feedback/file_item.rb
14
+ lib/alfred/feedback/item.rb
9
15
  lib/alfred/ui.rb
10
16
  lib/alfred/version.rb
17
+ spec/item_spec.rb
18
+ spec/spec_helper.rb
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # alfred-workflow
2
2
 
3
3
  * home :: https://github.com/zhaocai/alfred-workflow
4
+ * rdoc :: http://rubydoc.info/gems/alfred-workflow/
4
5
  * code :: https://github.com/zhaocai/alfred-workflow
5
6
  * bugs :: https://github.com/zhaocai/alfred-workflow/issues
6
- * rdoc :: http://rubydoc.info/gems/alfred-workflow/
7
7
 
8
8
 
9
9
  ## DESCRIPTION:
@@ -33,7 +33,7 @@ Alfred.with_friendly_error do |alfred|
33
33
 
34
34
  fb.add_file_item(File.expand_path "~/Applications/")
35
35
 
36
- puts fb.to_xml
36
+ puts fb.to_alfred(ARGV)
37
37
  end
38
38
  ```
39
39
 
data/Rakefile CHANGED
@@ -4,7 +4,8 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  Hoe.plugin :bundler
7
- Hoe.plugin :gemspec
7
+ Hoe.plugin :test
8
+
8
9
  Hoe.plugin :git
9
10
  Hoe.plugin :rubygems
10
11
  Hoe.plugin :version
@@ -13,8 +14,23 @@ Hoe.spec 'alfred-workflow' do
13
14
 
14
15
  developer('Zhao Cai', 'caizhaoff@gmail.com')
15
16
 
17
+ testlib = :minitest
16
18
  extra_deps << ['plist', '~> 3.1.0']
17
19
  extra_deps << ['logging', '~> 1.8.0']
18
20
  end
19
21
 
22
+ desc "Bump Major Version and Commit"
23
+ task "bump:major" => ["version:bump:major"] do
24
+ sh "git commit -am '! Bump version to #{ENV["VERSION"]}'"
25
+ end
26
+
27
+ desc "Bump Minor Version and Commit"
28
+ task "bump:minor" => ["version:bump:minor"] do
29
+ sh "git commit -am '* Bump version to #{ENV["VERSION"]}'"
30
+ end
31
+ desc "Bump Patch Version and Commit"
32
+ task "bump:patch" => ["version:bump:patch"] do
33
+ sh "git commit -am 'Bump version to #{ENV["VERSION"]}'"
34
+ end
35
+
20
36
  # vim: syntax=ruby
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -1,148 +1,12 @@
1
1
  require "rexml/document"
2
+ require 'alfred/feedback/item'
3
+ require 'alfred/feedback/file_item'
2
4
 
3
5
  module Alfred
4
6
 
5
7
  class Feedback
6
8
  attr_accessor :items
7
9
 
8
- class Item
9
- attr_accessor :uid, :arg, :valid, :autocomplete, :title, :subtitle, :icon
10
-
11
- def initialize(title, opts = {})
12
- @title = title
13
- @subtitle = opts[:subtitle] if opts[:subtitle]
14
-
15
- if opts[:icon]
16
- @icon = opts[:icon]
17
- else
18
- @icon = {:type => "default", :name => "icon.png"}
19
- end
20
-
21
- @uid = opts[:uid] if opts[:uid]
22
-
23
- if opts[:arg]
24
- @arg = opts[:arg]
25
- else
26
- @arg = @title
27
- end
28
-
29
- if opts[:type]
30
- @type = opts[:type]
31
- else
32
- @type = 'default'
33
- end
34
-
35
- if opts[:valid]
36
- @valid = opts[:valid]
37
- else
38
- @valid = 'yes'
39
- end
40
-
41
- if opts[:autocomplete]
42
- @autocomplete = opts[:autocomplete]
43
- else
44
- @autocomplete = @title
45
- end
46
- end
47
-
48
- ## To customize a new match? function, overwrite it.
49
- #
50
- # Module Alfred
51
- # class Feedback
52
- # class Item
53
- # alias_method :default_match?, :match?
54
- # def match?(query)
55
- # # define new match? function here
56
- # end
57
- # end
58
- # end
59
- # end
60
- def match?(query)
61
- return true if query.empty?
62
- if smart_query(query).match(@title)
63
- return true
64
- else
65
- return false
66
- end
67
- end
68
-
69
- def to_xml
70
- xml_element = REXML::Element.new('item')
71
- xml_element.add_attributes({
72
- 'uid' => @uid,
73
- 'arg' => @arg,
74
- 'valid' => @valid,
75
- 'autocomplete' => @autocomplete
76
- })
77
- xml_element.add_attributes('type' => 'file') if @type == "file"
78
-
79
- REXML::Element.new("title", xml_element).text = @title
80
- REXML::Element.new("subtitle", xml_element).text = @subtitle
81
-
82
- icon = REXML::Element.new("icon", xml_element)
83
- icon.text = @icon[:name]
84
- icon.add_attributes('type' => 'fileicon') if @icon[:type] == "fileicon"
85
-
86
- xml_element
87
- end
88
-
89
- protected
90
-
91
- def smart_query(query)
92
- if query.is_a? Array
93
- query = query.join(" ")
94
- end
95
- option = Regexp::IGNORECASE
96
- if /[[:upper:]]/.match(query)
97
- option = nil
98
- end
99
- Regexp.compile(".*#{query.gsub(/\s+/,'.*')}.*", option)
100
- end
101
-
102
- end
103
-
104
- class FileItem < Item
105
-
106
- def initialize(path)
107
- if ['.ennote', '.webbookmark'].include? File.extname(path)
108
- @title = %x{mdls -name kMDItemDisplayName -raw '#{path}'}
109
- else
110
- @title = File.basename(path)
111
- end
112
- @subtitle = path
113
- @uid = path
114
- @arg = path
115
- @icon = {:type => "fileicon", :name => path}
116
- @valid = 'yes'
117
- @autocomplete = @title
118
- @type = 'file'
119
- end
120
-
121
- def match?(query)
122
- return true if query.empty?
123
- if query.is_a? String
124
- query = query.split("\s")
125
- end
126
-
127
- queries = []
128
- query.each { |q|
129
- queries << smart_query(q)
130
- }
131
-
132
- queries.delete_if { |q|
133
- q.match(@title) or q.match(@subtitle)
134
- }
135
-
136
- if queries.empty?
137
- return true
138
- else
139
- return false
140
- end
141
- end
142
-
143
- end
144
-
145
-
146
10
  def initialize
147
11
  @items = []
148
12
  end
@@ -156,15 +20,15 @@ module Alfred
156
20
  @items << FileItem.new(path)
157
21
  end
158
22
 
159
-
160
- def to_xml(query = '', items = @items)
23
+ def to_xml(with_query = '', items = @items)
161
24
  document = REXML::Element.new("items")
162
25
  items.each do |item|
163
- document << item.to_xml if item.match?(query)
26
+ document << item.to_xml if item.match?(with_query)
164
27
  end
165
28
  document.to_s
166
29
  end
167
30
 
31
+ alias_method :to_alfred, :to_xml
168
32
  end
169
33
 
170
34
  end
@@ -0,0 +1,47 @@
1
+ require "rexml/document"
2
+ require "alfred/feedback/item"
3
+
4
+ module Alfred
5
+ class Feedback
6
+ class FileItem < Item
7
+
8
+ def initialize(path)
9
+ if ['.ennote', '.webbookmark'].include? File.extname(path)
10
+ @title = %x{mdls -name kMDItemDisplayName -raw '#{path}'}
11
+ else
12
+ @title = File.basename(path)
13
+ end
14
+ @subtitle = path
15
+ @uid = path
16
+ @arg = path
17
+ @icon = {:type => "fileicon", :name => path}
18
+ @valid = 'yes'
19
+ @autocomplete = @title
20
+ @type = 'file'
21
+ end
22
+
23
+ def match?(query)
24
+ return true if query.empty?
25
+ if query.is_a? String
26
+ query = query.split("\s")
27
+ end
28
+
29
+ queries = []
30
+ query.each { |q|
31
+ queries << smart_query(q)
32
+ }
33
+
34
+ queries.delete_if { |q|
35
+ q.match(@title) or q.match(@subtitle)
36
+ }
37
+
38
+ if queries.empty?
39
+ return true
40
+ else
41
+ return false
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,101 @@
1
+ require "rexml/document"
2
+
3
+ module Alfred
4
+ class Feedback
5
+ class Item
6
+ attr_accessor :uid, :arg, :valid, :autocomplete, :title, :subtitle, :icon, :type
7
+
8
+ def initialize(title, opts = {})
9
+ @title = title
10
+ @subtitle = opts[:subtitle] if opts[:subtitle]
11
+
12
+ if opts[:icon]
13
+ @icon = opts[:icon]
14
+ else
15
+ @icon = {:type => "default", :name => "icon.png"}
16
+ end
17
+
18
+ @uid = opts[:uid] if opts[:uid]
19
+
20
+ if opts[:arg]
21
+ @arg = opts[:arg]
22
+ else
23
+ @arg = @title
24
+ end
25
+
26
+ if opts[:type]
27
+ @type = opts[:type]
28
+ else
29
+ @type = 'default'
30
+ end
31
+
32
+ if opts[:valid]
33
+ @valid = opts[:valid]
34
+ else
35
+ @valid = 'yes'
36
+ end
37
+
38
+ if opts[:autocomplete]
39
+ @autocomplete = opts[:autocomplete]
40
+ else
41
+ @autocomplete = @title
42
+ end
43
+ end
44
+
45
+ ## To customize a new match? function, overwrite it.
46
+ #
47
+ # Module Alfred
48
+ # class Feedback
49
+ # class Item
50
+ # alias_method :default_match?, :match?
51
+ # def match?(query)
52
+ # # define new match? function here
53
+ # end
54
+ # end
55
+ # end
56
+ # end
57
+ def match?(query)
58
+ return true if query.empty?
59
+ if smart_query(query).match(@title)
60
+ return true
61
+ else
62
+ return false
63
+ end
64
+ end
65
+
66
+ def to_xml
67
+ xml_element = REXML::Element.new('item')
68
+ xml_element.add_attributes({
69
+ 'uid' => @uid,
70
+ 'arg' => @arg,
71
+ 'valid' => @valid,
72
+ 'autocomplete' => @autocomplete
73
+ })
74
+ xml_element.add_attributes('type' => 'file') if @type == "file"
75
+
76
+ REXML::Element.new("title", xml_element).text = @title
77
+ REXML::Element.new("subtitle", xml_element).text = @subtitle
78
+
79
+ icon = REXML::Element.new("icon", xml_element)
80
+ icon.text = @icon[:name]
81
+ icon.add_attributes('type' => 'fileicon') if @icon[:type] == "fileicon"
82
+
83
+ xml_element
84
+ end
85
+
86
+ protected
87
+
88
+ def smart_query(query)
89
+ if query.is_a? Array
90
+ query = query.join(" ")
91
+ end
92
+ option = Regexp::IGNORECASE
93
+ if /[[:upper:]]/.match(query)
94
+ option = nil
95
+ end
96
+ Regexp.compile(".*#{query.gsub(/\s+/,'.*')}.*", option)
97
+ end
98
+
99
+ end
100
+ end
101
+ end
@@ -1,3 +1,3 @@
1
1
  module Alfred
2
- VERSION = '1.1.5'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe "Feedback Item" do
4
+ it "should return raise ArgumentError without Item title" do
5
+ expect { Alfred::Feedback::Item.new }.to raise_error(ArgumentError)
6
+ end
7
+
8
+ it "should match default xml item tags" do
9
+ item = Alfred::Feedback::Item.new("title")
10
+ item.title.should eql "title"
11
+ item.subtitle.should eql nil
12
+ item.autocomplete.should eql item.title
13
+ item.arg.should eql item.title
14
+ item.valid.should eql "yes"
15
+ item.type.should eql "default"
16
+
17
+ default_icon = {:type => "default", :name => "icon.png"}
18
+ item.icon.should eql default_icon
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require "rspec"
4
+ require "alfred"
5
+
6
+ RSpec.configure do |c|
7
+ c.color_enabled = true
8
+
9
+ # Use color not only in STDOUT but also in pagers and files
10
+ c.tty = true
11
+
12
+ c.formatter = :documentation # :progress, :html, :textmate
13
+
14
+ c.mock_with :rspec
15
+ end
16
+
17
+ class String
18
+ def strip_heredoc
19
+ indent = scan(/^[ \t]*(?=\S)/).min.size || 0
20
+ gsub(/^[ \t]{#{indent}}/, '')
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alfred-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plist
@@ -87,14 +87,22 @@ extra_rdoc_files:
87
87
  files:
88
88
  - .autotest
89
89
  - .gemtest
90
+ - .rspec
91
+ - Gemfile
92
+ - Gemfile.lock
90
93
  - History.txt
91
94
  - Manifest.txt
92
95
  - README.md
93
96
  - Rakefile
97
+ - autotest/discover.rb
94
98
  - lib/alfred.rb
95
99
  - lib/alfred/feedback.rb
100
+ - lib/alfred/feedback/file_item.rb
101
+ - lib/alfred/feedback/item.rb
96
102
  - lib/alfred/ui.rb
97
103
  - lib/alfred/version.rb
104
+ - spec/item_spec.rb
105
+ - spec/spec_helper.rb
98
106
  homepage: https://github.com/zhaocai/alfred-workflow
99
107
  licenses: []
100
108
  post_install_message: