alfred-workflow 1.1.0 → 1.1.1

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.
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
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
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/Manifest.txt CHANGED
@@ -1,6 +1,10 @@
1
+ .autotest
2
+ .gemtest
1
3
  History.txt
2
4
  Manifest.txt
3
5
  README.md
4
6
  Rakefile
5
7
  lib/alfred.rb
8
+ lib/alfred/feedback.rb
9
+ lib/alfred/ui.rb
6
10
  lib/alfred/version.rb
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  Ruby Gem helper for building [Alfred](http://www.alfredapp.com) workflow.
6
6
 
7
+
7
8
  ## FEATURES:
8
9
 
9
10
  * Use standard [bundler][gembundler] to easily package, manage, and update ruby gems in the workflow.
@@ -14,9 +15,6 @@ Ruby Gem helper for building [Alfred](http://www.alfredapp.com) workflow.
14
15
  * Functions to simplify saving and retrieving settings.
15
16
 
16
17
 
17
- ## REQUIREMENTS:
18
-
19
-
20
18
  ## INSTALL:
21
19
 
22
20
  `gem install alfred-workflow`
@@ -25,6 +23,10 @@ Ruby Gem helper for building [Alfred](http://www.alfredapp.com) workflow.
25
23
 
26
24
  * Refer to [alfred2-ruby-template]( https://github.com/zhaocai/alfred2-ruby-template ) for example and detailed instruction.
27
25
 
26
+ ## Example Projects
27
+
28
+ * [alfred2_top_workflow]( https://github.com/zhaocai/alfred2-top-workflow )
29
+
28
30
 
29
31
  ## DEVELOPERS:
30
32
 
@@ -0,0 +1,170 @@
1
+ require "rexml/document"
2
+
3
+ module Alfred
4
+
5
+ class Feedback
6
+ attr_accessor :items
7
+
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
+ def initialize
147
+ @items = []
148
+ end
149
+
150
+ def add_item(opts = {})
151
+ raise ArgumentError, "Feedback item must have title!" if opts[:title].nil?
152
+ @items << Item.new(opts[:title], opts)
153
+ end
154
+
155
+ def add_file_item(path)
156
+ @items << FileItem.new(path)
157
+ end
158
+
159
+
160
+ def to_xml(query = '', items = @items)
161
+ document = REXML::Element.new("items")
162
+ items.each do |item|
163
+ document << item.to_xml if item.match?(query)
164
+ end
165
+ document.to_s
166
+ end
167
+
168
+ end
169
+
170
+ end
data/lib/alfred/ui.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'logging'
2
+
3
+ module Alfred
4
+
5
+ class Logger
6
+ def initialize(id)
7
+ @id = id
8
+ end
9
+
10
+ def info(msg)
11
+ logger.info msg
12
+ end
13
+ def warn(msg)
14
+ logger.warn msg
15
+ end
16
+ def debug(msg)
17
+ logger.debug msg
18
+ end
19
+ def error(msg)
20
+ logger.error msg
21
+ end
22
+ def fatal(msg)
23
+ logger.fatal msg
24
+ end
25
+
26
+ def logger
27
+ @logger ||= init_log
28
+ end
29
+
30
+ private
31
+
32
+ def init_log
33
+ @logger = Logging.logger[@id]
34
+ logger_file = File.expand_path("~/Library/Logs/Alfred-Workflow.log")
35
+ @logger.level = :debug
36
+ @logger.add_appenders(
37
+ Logging.appenders.file(logger_file)
38
+ )
39
+ @logger
40
+ end
41
+ end
42
+
43
+
44
+ end
45
+
46
+
@@ -1,3 +1,3 @@
1
1
  module Alfred
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  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.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -84,13 +84,16 @@ extra_rdoc_files:
84
84
  - History.txt
85
85
  - Manifest.txt
86
86
  files:
87
+ - .autotest
88
+ - .gemtest
87
89
  - History.txt
88
90
  - Manifest.txt
89
91
  - README.md
90
92
  - Rakefile
91
93
  - lib/alfred.rb
94
+ - lib/alfred/feedback.rb
95
+ - lib/alfred/ui.rb
92
96
  - lib/alfred/version.rb
93
- - .gemtest
94
97
  homepage: https://github.com/zhaocai/alfred-workflow
95
98
  licenses: []
96
99
  post_install_message: