Skip to content

Commit f30e5d0

Browse files
committed
Fixed some issue to accept multi-byte search query
1 parent d20acd9 commit f30e5d0

File tree

17 files changed

+144
-163
lines changed

17 files changed

+144
-163
lines changed

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
source 'https://rubygems.org'
22

3-
gem 'rake'
4-
gem 'plist'
3+
gem 'rake'

Gemfile.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
plist (3.1.0)
5-
rake (0.9.6)
4+
rake (10.1.0)
65

76
PLATFORMS
87
ruby
98

109
DEPENDENCIES
11-
plist
1210
rake

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
## Installation
66

7-
Double-click `Qiita.alfredworkflow` to install workflow.
7+
Double-click `Qiita.alfredworkflow` to install Alfred workflow.
88

9-
## Development installation
9+
## Development Installation
1010

1111
```
12-
$ bundle install --path vendor/bundle --binstubs=.bundle/bin
12+
$ bundle install
1313
$ bundle exec rake link
1414
```
1515

16-
If you using Alfred with Dropbox Sync folder, you should type `rake install` instead of `rake link`.
16+
If you using Alfred with Dropbox Sync folder, you should type `rake link_dropbox` instead of `rake link`.
1717

1818
## Thanks
1919

20-
- [Alfred 2 Ruby Template](https://github.com/zhaocai/alfred2-ruby-template)
20+
- [Alfred 2 Ruby Template](https://github.com/zhaocai/alfred2-ruby-template)

Rakefile

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
1-
require 'yaml'
2-
require 'plist'
1+
BUNDLE_ID = "co.randompaper.qiita.alfred"
2+
PACKAGE_FILE = "info.plist"
33

4-
config_file = 'config.yml'
5-
workflow_home = File.expand_path('~/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows')
6-
7-
$config = YAML.load_file config_file
8-
$config['bundleid'] = "#{$config['domain']}.#{$config['id']}"
9-
$config['package_file'] = File.join($config['path'], 'info.plist')
10-
$config['dbx_workflow_path'] = File.join(File.expand_path($config['dropbox']), '/Alfred.alfredpreferences/workflows')
11-
12-
desc "Generate a plist file for Alfred from config.yml"
13-
task :configure do
14-
package = Plist::parse_xml $config['package_file']
15-
16-
unless package['bundleid'].eql?($config["bundleid"])
17-
package['bundleid'] = $config['bundleid']
18-
File.open($config['package_file'], 'wb') do |f|
19-
f.write package.to_plist
20-
end
21-
end
22-
end
4+
workflow_home = File.expand_path('~/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows')
5+
dbx_workflow_path = File.expand_path('~/Dropbox/アプリ/Alfred.alfredpreferences/workflows')
236

247
desc "Link to Alfred"
258
task :link => [:configure] do
26-
ln_sf File.expand_path($config["path"]), File.join(workflow_home, $config["bundleid"])
9+
ln_sf File.expand_path('../', __FILE__), File.join(workflow_home, BUNDLE_ID)
2710
end
2811

2912
desc "Unlink from Alfred"
3013
task :unlink => [:configure] do
31-
rm File.join(workflow_home, $config["bundleid"])
14+
rm File.join(workflow_home, BUNDLE_ID)
3215
end
3316

3417
desc "Install to Alfred Sync folder on Dropbox"
35-
task :install => [:configure] do
36-
ln_sf File.expand_path($config["path"]), File.join($config["dbx_workflow_path"], $config["bundleid"])
18+
task :link_dropbox => [:configure] do
19+
ln_sf File.expand_path('../', __FILE__), File.join(dbx_workflow_path, BUNDLE_ID)
3720
end
3821

3922
desc "Unlink from Alfred Sync folder on Dropbox"
40-
task :uninstall => [:configure] do
41-
rm File.join($config["dbx_workflow_path"], $config["bundleid"])
23+
task :unlink_dropbox => [:configure] do
24+
rm File.join(dbx_workflow_path, BUNDLE_ID)
4225
end

commands/qiita.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
QUERY = ARGV[0].to_s.strip
2+
3+
require_relative "../lib/qiita"
4+
5+
data = Qiita::API.search(QUERY)
6+
7+
results = []
8+
data.each do |q|
9+
arg = q['url']
10+
subtitle = "Stocks: " + q['stock_count'].to_s + " LGTM:" + q['lgtm_count'].to_s + " Comments:" + q['comment_count'].to_s + " Create At:" + q['created_at']
11+
12+
item = { uid: q['id'], arg: arg, title: q['title'], subtitle: subtitle, icon: 'icon.png'}
13+
results << item
14+
end
15+
16+
puts Qiita::Alfred.to_alfred(results)

config.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
<key>argumenttype</key>
3535
<integer>0</integer>
3636
<key>escaping</key>
37-
<integer>1</integer>
37+
<integer>0</integer>
3838
<key>keyword</key>
3939
<string>qiita</string>
4040
<key>runningsubtext</key>
4141
<string>Searching...</string>
4242
<key>script</key>
43-
<string>python ./main.py "{query}"</string>
43+
<string>ruby ./commands/qiita.rb "{query}"</string>
4444
<key>title</key>
4545
<string>Qiita</string>
4646
<key>type</key>

lib/qiita.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Qiita
2+
BUNDLE_ID = 'co.randompaper.qiita.alfred'
3+
4+
CONFIG_FILE = File.expand_path("~/Library/Application Support/Alfred 2/Workflow Data/#{BUNDLE_ID}/config.json")
5+
CACHE_DIR = File.expand_path("~/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/#{BUNDLE_ID}")
6+
end
7+
8+
require_relative 'qiita/version.rb'
9+
require_relative 'qiita/object.rb'
10+
require_relative 'qiita/config.rb'
11+
require_relative 'qiita/api.rb'
12+
require_relative 'qiita/alfred.rb'

lib/qiita/alfred.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'rexml/document'
2+
3+
module Qiita::Alfred
4+
def self.to_alfred(array)
5+
raise "Argument must be an Array" unless array.kind_of? Array
6+
7+
doc = REXML::Document.new
8+
root = doc.add_element("items")
9+
10+
array.each do |entry|
11+
item = root.add_element("item")
12+
13+
entry.each do |key, value|
14+
if [:uid, :arg, :valid, :autocomplete].include?(key)
15+
item.attributes[key.to_s] = value.to_s
16+
else
17+
element = item.add_element(key.to_s)
18+
element.text = value ? value.to_s : ""
19+
end
20+
end
21+
end
22+
23+
doc.to_s
24+
end
25+
end

0 commit comments

Comments
 (0)