diff --git a/workflow/Gemfile b/workflow/Gemfile
index 010c8be6..4eb32e37 100644
--- a/workflow/Gemfile
+++ b/workflow/Gemfile
@@ -1,7 +1,6 @@
source 'https://rubygems.org'
gem 'plist', '3.1.0'
-gem 'alfred-workflow', '1.11.3'
gem 'htmlentities', '4.3.1'
group :test do
diff --git a/workflow/Gemfile.lock b/workflow/Gemfile.lock
index b6a19d59..3ed699c1 100644
--- a/workflow/Gemfile.lock
+++ b/workflow/Gemfile.lock
@@ -1,8 +1,6 @@
GEM
remote: https://rubygems.org/
specs:
- alfred-workflow (1.11.3)
- plist (>= 3.1.0)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
@@ -30,7 +28,6 @@ PLATFORMS
ruby
DEPENDENCIES
- alfred-workflow (= 1.11.3)
coveralls (= 0.7.0)
htmlentities (= 4.3.1)
minitest (= 5.0.8)
diff --git a/workflow/encode.rb b/workflow/encode.rb
index aa8c7a60..65a763e3 100644
--- a/workflow/encode.rb
+++ b/workflow/encode.rb
@@ -5,8 +5,7 @@
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require 'bundle/bundler/setup'
-require 'alfred'
require 'lib/font_awesome'
-character_code = ARGV[0].chomp.split("|||")[1]
+character_code = ARGV[0].chomp.split('|||')[1]
print FontAwesome.to_character_reference(character_code)
diff --git a/workflow/lib/font_awesome.rb b/workflow/lib/font_awesome.rb
index f9c58f8b..9b7ea77f 100644
--- a/workflow/lib/font_awesome.rb
+++ b/workflow/lib/font_awesome.rb
@@ -1,12 +1,15 @@
# encoding: utf-8
+require 'yaml'
require 'htmlentities'
+# FontAwesome class
class FontAwesome
attr_reader :icons
ICONS = YAML.load_file(File.expand_path('./icons.yml'))['icons']
+ # FontAwesome::Icon class
class Icon
attr_reader :id, :unicode
@@ -58,13 +61,19 @@ def item_hash(icon)
}
end
- def add_items(feedback, icons = @icons)
- icons.each { |icon| feedback.add_item(item_hash(icon)) }
- feedback
+ def item_xml(options = {})
+ <<-XML
+-
+ #{options[:title]}
+ #{options[:subtitle]}
+ #{options[:icon][:name]}
+
+ XML
end
- def to_alfred(alfred)
- add_items(alfred.feedback).to_alfred
+ def to_alfred
+ xml = @icons.map { |icon| item_xml(item_hash(icon)) }.join
+ "\n\n#{xml}"
end
private
diff --git a/workflow/main.rb b/workflow/main.rb
index 8296b76a..2b5aad33 100755
--- a/workflow/main.rb
+++ b/workflow/main.rb
@@ -4,21 +4,25 @@
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
+require 'logger'
require 'bundle/bundler/setup'
-require 'alfred'
require 'lib/font_awesome'
-def puts_log(str)
- log_file = File.expand_path('~/Library/Logs/Alfred-Workflow.log')
- File.open(log_file, 'a+') do |log|
- log.puts "[PUTS LOG] #{str}\n"
- log.flush
+# Main class
+class Main
+ def initialize(query, debug = false)
+ puts result = FontAwesome.new(query).to_alfred
+ logging(result) if debug
end
-end
-
-Alfred.with_friendly_error do |alfred|
- alfred.with_rescue_feedback = true
- query = ARGV.join(' ').strip
- puts FontAwesome.new(query).to_alfred(alfred)
+ def logging(result)
+ log_file = File.expand_path('~/Library/Logs/font-awesome-workflow.log')
+ logger = Logger.new(log_file, 'daily')
+ logger.progname = 'Font Awesome Workflow'
+ logger.debug(result)
+ end
end
+
+# entry point
+query = ARGV.join(' ').strip
+Main.new(query)
diff --git a/workflow/test/font_awesome_test.rb b/workflow/test/font_awesome_test.rb
index 9bb0f438..f54d377a 100644
--- a/workflow/test/font_awesome_test.rb
+++ b/workflow/test/font_awesome_test.rb
@@ -109,46 +109,52 @@
describe '#item_hash' do
before do
- @icon = FontAwesome::Icon.new('apple')
- @item_hash = FontAwesome.new.item_hash(@icon)
+ icon = FontAwesome::Icon.new('apple')
+ @item_hash = FontAwesome.new.item_hash(icon)
end
it { @item_hash[:uid].must_equal '' }
it { @item_hash[:title].must_equal 'apple' }
- it { @item_hash[:subtitle].must_equal "Paste class name: fa-apple" }
+ it { @item_hash[:subtitle].must_equal 'Paste class name: fa-apple' }
it { @item_hash[:arg].must_equal 'apple|||f179' }
it { @item_hash[:icon][:type].must_equal 'default' }
- it { @item_hash[:icon][:name].must_equal "./icons/fa-apple.png" }
+ it { @item_hash[:icon][:name].must_equal './icons/fa-apple.png' }
it { @item_hash[:valid].must_equal 'yes' }
it { @item_hash.size.must_equal 6 }
end
- describe '#add_items' do
+ describe '#item_xml' do
before do
- feedback = Alfred::Core.new.feedback
- icon_ids = %w(beer cloud apple)
- icons = icon_ids.map { |name| FontAwesome::Icon.new(name) }
- @feedback = FontAwesome.new.add_items(feedback, icons)
+ icon = FontAwesome::Icon.new('apple')
+ item_hash = FontAwesome.new.item_hash(icon)
+ @item_xml = FontAwesome.new.item_xml(item_hash)
end
- it { @feedback.items.first.title.must_equal 'beer' }
- it { @feedback.items.last.title.must_equal 'apple' }
+ it do
+ expectation = <<-XML
+-
+ apple
+ Paste class name: fa-apple
+ ./icons/fa-apple.png
+
+ XML
+ @item_xml.must_equal expectation
+ end
end
describe '#to_alfred' do
before do
- alfred = Alfred::Core.new
query = 'bookmark'
- xml = FontAwesome.new(query).to_alfred(alfred)
+ xml = FontAwesome.new(query).to_alfred
@doc = REXML::Document.new(xml)
end
- it { @doc.elements['items'].size.must_equal 2 }
+ it { @doc.elements['items'].elements.size.must_equal 2 }
+ it { @doc.elements['items/item[1]'].attributes['arg'].must_equal 'bookmark|||f02e' }
it { @doc.elements['items/item[1]/title'].text.must_equal 'bookmark' }
- it { @doc.elements['items/item[1]/arg'].text.must_equal 'bookmark|||f02e' }
it { @doc.elements['items/item[1]/icon'].text.must_equal './icons/fa-bookmark.png' }
+ it { @doc.elements['items/item[2]'].attributes['arg'].must_equal 'bookmark-o|||f097' }
it { @doc.elements['items/item[2]/title'].text.must_equal 'bookmark-o' }
- it { @doc.elements['items/item[2]/arg'].text.must_equal 'bookmark-o|||f097' }
it { @doc.elements['items/item[2]/icon'].text.must_equal './icons/fa-bookmark-o.png' }
end