alphred 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77df5b167e6b68eefafefb3f08dcdbd46e8c85f1
4
+ data.tar.gz: 2d49a6168923b37774912de965d24a83c2bee14e
5
+ SHA512:
6
+ metadata.gz: 43dcc97756b74b7e1bd4d0db36a5f100871484f2ac20199b01df16b853d31d82e534c435dbeeca8cfdf6c53528dc78829130beb533c894e7079a6353ca482e7d
7
+ data.tar.gz: ac1a78c4642b4cbb625160e3a27e7a4d089cc80f2af36470642e3b9664dbf63c0490a65575bc4bf690a7d8dd47514b19694d409182e2fa3c78c724c18bfb77a2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alphred.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "guard"
8
+ gem "guard-minitest"
9
+ gem "pry"
10
+ end
@@ -0,0 +1,5 @@
1
+ guard :minitest do
2
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
3
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
4
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
5
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alpha Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,123 @@
1
+ # Alphred
2
+
3
+ Alphred is a library for making Alfred workflows in Ruby. It's designed
4
+ specifically for how I work, so assumes that you manage dependencies with
5
+ [Bundler][bundler] and Rubies with [chruby][chruby].
6
+
7
+ [bundler]: http://bundler.io/
8
+ [chruby]: https://github.com/postmodern/chruby
9
+
10
+ ## Usage
11
+
12
+ The [example script filter][scriptfilter] would look like this using Alphred:
13
+
14
+ [scriptfilter]: https://www.alfredapp.com/help/workflows/inputs/script-filter/
15
+
16
+ ``` ruby
17
+ items = Alphred::Items.new(
18
+ Alphred::Item.new(uid: "desktop",
19
+ arg: "~/Desktop",
20
+ valid: true,
21
+ autocomplete: "Desktop",
22
+ type: :file,
23
+ title: "Desktop",
24
+ subtitle: "~/Desktop",
25
+ icon: { value: "~/Desktop", type: :fileicon }),
26
+ Alphred::Item.new(uid: "flickr",
27
+ valid: false,
28
+ autocomplete: "flickr",
29
+ title: "Flickr",
30
+ icon: "flickr.png"),
31
+ Alphred::Item.new(uid: "image",
32
+ autocomplete: "My holiday photo",
33
+ type: :file,
34
+ title: "My holiday photo",
35
+ subtitle: "~/Pictures/My holiday photo.jpg",
36
+ icon: { value: "public.jpeg", type: :filetype }),
37
+ Alphred::Item.new(uid: "home",
38
+ arg: "~/",
39
+ valid: true,
40
+ autocomplete: "Home",
41
+ type: :file,
42
+ title: "Home Folder",
43
+ subtitle: "Home folder ~/",
44
+ icon: { value: "~/", type: :fileicon },
45
+ mods: { shift: "Subtext when shift is pressed",
46
+ fn: "Subtext when fn is pressed",
47
+ ctrl: "Subtext when ctrl is pressed",
48
+ alt: "Subtext when alt is pressed",
49
+ cmd: "Subtext when cmd is pressed" },
50
+ text: { copy: "Text when copying",
51
+ largetype: "Text for LargeType" }))
52
+ items.to_xml
53
+ ```
54
+
55
+ This produces the following XML:
56
+
57
+ ``` xml
58
+ <?xml version="1.0" encoding="UTF-8"?>
59
+ <items>
60
+ <item uid="desktop" arg="~/Desktop" autocomplete="Desktop" type="file" valid="yes">
61
+ <title>Desktop</title>
62
+ <subtitle>~/Desktop</subtitle>
63
+ <icon type="fileicon">~/Desktop</icon>
64
+ </item>
65
+ <item uid="flickr" autocomplete="flickr" valid="no">
66
+ <title>Flickr</title>
67
+ <icon>flickr.png</icon>
68
+ </item>
69
+ <item uid="image" autocomplete="My holiday photo" type="file">
70
+ <title>My holiday photo</title>
71
+ <subtitle>~/Pictures/My holiday photo.jpg</subtitle>
72
+ <icon type="filetype">public.jpeg</icon>
73
+ </item>
74
+ <item uid="home" arg="~/" autocomplete="Home" type="file" valid="yes">
75
+ <title>Home Folder</title>
76
+ <subtitle>Home folder ~/</subtitle>
77
+ <icon type="fileicon">~/</icon>
78
+ <subtitle mod="shift">Subtext when shift is pressed</subtitle>
79
+ <subtitle mod="fn">Subtext when fn is pressed</subtitle>
80
+ <subtitle mod="ctrl">Subtext when ctrl is pressed</subtitle>
81
+ <subtitle mod="alt">Subtext when alt is pressed</subtitle>
82
+ <subtitle mod="cmd">Subtext when cmd is pressed</subtitle>
83
+ <text type="copy">Text when copying</text>
84
+ <text type="largetype">Text for LargeType</text>
85
+ </item>
86
+ </items>
87
+ ```
88
+
89
+ ### Releasing
90
+
91
+ Including `alphred/tasks` in your `Rakefile` will allow access to Alphred's
92
+ Rake tasks for releasing a workflow. `release` will tag the current commit with
93
+ the provided version and create a .alfredworkflow package with vendored gem
94
+ dependencies.
95
+
96
+ ## TODO
97
+
98
+ - Make workflow configuration easier.
99
+
100
+ ## Development
101
+
102
+ After checking out the repo, run `bundle install` to install dependencies.
103
+ Then, run `rake test` to run the tests. You can also run `rake console` for an
104
+ interactive prompt that will allow you to experiment.
105
+
106
+ To install this gem onto your local machine, run `bundle exec rake install`. To
107
+ release a new version, update the version number in `version.rb`, and then run
108
+ `bundle exec rake release`, which will create a git tag for the version, push
109
+ git commits and tags, and push the `.gem` file to
110
+ [rubygems.org](https://rubygems.org).
111
+
112
+ ## Contributing
113
+
114
+ Bug reports and pull requests are welcome on GitHub at
115
+ https://github.com/kejadlen/alphred. This project is intended to be a safe,
116
+ welcoming space for collaboration, and contributors are expected to adhere to
117
+ the [Contributor Covenant](contributor-covenant.org) code of conduct.
118
+
119
+ ## License
120
+
121
+ The gem is available as open source under the terms of the [MIT
122
+ License](http://opensource.org/licenses/MIT).
123
+
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "lib"
6
+ t.test_files = FileList['test/**/test_*.rb']
7
+ end
8
+
9
+ task :console do
10
+ require "bundler/setup"
11
+ require "alphred"
12
+
13
+ require "pry"
14
+ Pry.start
15
+ end
16
+
17
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "alphred/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alphred"
8
+ spec.version = Alphred::VERSION
9
+ spec.authors = ["Alpha Chen"]
10
+ spec.email = ["alpha.chen@gmail.com"]
11
+
12
+ spec.summary = %q{Helper utilities for making Alfred workflows.}
13
+ spec.homepage = "https://github.com/kejadlen/alph"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "builder", "~> 3.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ end
@@ -0,0 +1,9 @@
1
+ require "builder"
2
+
3
+ require_relative "alphred/version"
4
+
5
+ require_relative "alphred/icon"
6
+ require_relative "alphred/item"
7
+ require_relative "alphred/items"
8
+ require_relative "alphred/mods"
9
+ require_relative "alphred/text"
@@ -0,0 +1,39 @@
1
+ require "builder"
2
+
3
+ module Alphred
4
+ class Icon
5
+ VALID_TYPES = %i[ fileicon filetype ]
6
+
7
+ attr_accessor *%i[ value type ]
8
+
9
+ def initialize(**kwargs)
10
+ raise ArgumentError.new("missing keyword: value") unless kwargs.has_key?(:value)
11
+
12
+ @value = kwargs[:value]
13
+ self.type = kwargs[:type] if kwargs.has_key?(:type)
14
+ end
15
+
16
+ def type=(type)
17
+ raise ArgumentError.new("`type` must be one of #{VALID_TYPES}") unless type.nil? || VALID_TYPES.include?(type)
18
+
19
+ @type = type
20
+ end
21
+
22
+ def to_xml(xml=nil)
23
+ xml ||= Builder::XmlMarkup.new(indent: 2)
24
+ attrs = {}
25
+ attrs[:type] = self.type unless self.type.nil?
26
+ xml.icon self.value, attrs
27
+ end
28
+ end
29
+ end
30
+
31
+ module Kernel
32
+ def Icon(value)
33
+ case value
34
+ when Alphred::Icon then value
35
+ when String then Alphred::Icon.new(value: value)
36
+ when Hash then Alphred::Icon.new(**value)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,59 @@
1
+ require "builder"
2
+
3
+ require_relative "mods"
4
+ require_relative "text"
5
+
6
+ module Alphred
7
+ class Item
8
+ VALID_TYPES = %i[ default file file_skipcheck ]
9
+
10
+ attr_accessor *%i[ uid arg valid autocomplete title subtitle mods icon text ]
11
+
12
+ def initialize(**kwargs)
13
+ raise ArgumentError.new("missing keyword: title") unless kwargs.has_key?(:title)
14
+
15
+ @title = kwargs[:title]
16
+
17
+ %i[ uid arg valid autocomplete subtitle ].each do |attr|
18
+ self.instance_variable_set("@#{attr}", kwargs[attr]) if kwargs.has_key?(attr)
19
+ end
20
+
21
+ @icon = Icon(kwargs[:icon]) if kwargs.has_key?(:icon)
22
+ @text = Text.new(kwargs[:text]) if kwargs.has_key?(:text)
23
+ @mods = Mods.new(kwargs[:mods]) if kwargs.has_key?(:mods)
24
+
25
+ self.type = kwargs[:type] if kwargs.has_key?(:type)
26
+ end
27
+
28
+ def type=(type)
29
+ raise ArgumentError.new("`type` must be one of #{VALID_TYPES}") unless type.nil? || VALID_TYPES.include?(type)
30
+
31
+ @type = type
32
+ end
33
+
34
+ def type
35
+ @type && @type.to_s.gsub(?_, ?:)
36
+ end
37
+
38
+ def to_xml(xml=nil)
39
+ xml ||= Builder::XmlMarkup.new(indent: 2)
40
+ xml.item self.attrs do
41
+ xml.title self.title
42
+ xml.subtitle self.subtitle unless self.subtitle.nil?
43
+ self.icon.to_xml(xml) unless self.icon.nil?
44
+ self.mods.to_xml(xml) unless self.mods.nil?
45
+ self.text.to_xml(xml) unless self.text.nil?
46
+ end
47
+ end
48
+
49
+ def attrs
50
+ attrs = {}
51
+ %i[ uid arg autocomplete type ].each do |attr|
52
+ value = self.send(attr)
53
+ attrs[attr] = value unless value.nil?
54
+ end
55
+ attrs[:valid] = (self.valid) ? "yes" : "no" unless self.valid.nil?
56
+ attrs
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,22 @@
1
+ require "builder"
2
+
3
+ module Alphred
4
+ class Items < DelegateClass(Array)
5
+ attr_reader :items
6
+
7
+ def initialize(*items)
8
+ @items = items
9
+ super(@items)
10
+ end
11
+
12
+ def to_xml
13
+ xml = Builder::XmlMarkup.new(indent: 2)
14
+ xml.instruct! :xml
15
+ xml.items do
16
+ self.items.each do |item|
17
+ item.to_xml(xml)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require "builder"
2
+
3
+ module Alphred
4
+ class Mods
5
+ MODS = %i[ shift fn ctrl alt cmd ]
6
+
7
+ attr_accessor *MODS
8
+
9
+ def initialize(**kwargs)
10
+ MODS.each do |mod|
11
+ self.instance_variable_set("@#{mod}", kwargs[mod]) if kwargs.has_key?(mod)
12
+ end
13
+ end
14
+
15
+ def to_xml(xml)
16
+ MODS.each do |mod|
17
+ value = self.send(mod)
18
+ xml.subtitle value, mod: mod unless value.nil?
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,40 @@
1
+ require "rake"
2
+
3
+ namespace :alphred do
4
+ desc "Prepare a release, named after the directory"
5
+ task :release, [:version] => [:tag, :package]
6
+
7
+ desc "Tag the current commit in git with VERSION"
8
+ task :tag, [:version] do |t, args|
9
+ version = args[:version]
10
+
11
+ git_status = `git status --porcelain`
12
+ fail <<-FAIL unless git_status.empty?
13
+ Can't tag #{version}: dirty working directory.
14
+ FAIL
15
+
16
+ sh "git tag #{version}"
17
+ end
18
+
19
+ desc "Create an alfredworkflow package with vendored dependencies"
20
+ task :package do
21
+ restore_bundler_config do
22
+ cmd = "bundle install --standalone --path vendor/bundle --without development test"
23
+ sh "chruby-exec 2.0.0 -- #{cmd}"
24
+ end
25
+ sh "zip -r #{application_dir.pathmap("%n.alfredworkflow")} *"
26
+ rm_rf "vendor"
27
+ end
28
+
29
+ def application_dir
30
+ Rake.application.original_dir
31
+ end
32
+
33
+ def restore_bundler_config
34
+ path = File.join(application_dir, ".bundle", "config")
35
+ config = File.read(path)
36
+ yield
37
+ ensure
38
+ File.write(path, config, mode: ?w)
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ require "builder"
2
+
3
+ module Alphred
4
+ class Text
5
+ attr_accessor *%i[ copy largetype ]
6
+
7
+ def initialize(copy: nil, largetype: nil)
8
+ @copy = copy
9
+ @largetype = largetype
10
+ end
11
+
12
+ def to_xml(xml)
13
+ xml.text copy, type: :copy unless self.copy.nil?
14
+ xml.text largetype, type: :largetype unless self.largetype.nil?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Alphred
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alphred
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alpha Chen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - alpha.chen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - alphred.gemspec
85
+ - lib/alphred.rb
86
+ - lib/alphred/icon.rb
87
+ - lib/alphred/item.rb
88
+ - lib/alphred/items.rb
89
+ - lib/alphred/mods.rb
90
+ - lib/alphred/tasks.rb
91
+ - lib/alphred/text.rb
92
+ - lib/alphred/version.rb
93
+ homepage: https://github.com/kejadlen/alph
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Helper utilities for making Alfred workflows.
117
+ test_files: []