alphred 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77df5b167e6b68eefafefb3f08dcdbd46e8c85f1
4
- data.tar.gz: 2d49a6168923b37774912de965d24a83c2bee14e
3
+ metadata.gz: 795eb675cd111730b33cab166f6e9787971eee70
4
+ data.tar.gz: 688aa2fc538532b9e545fe51618a42e3af931da9
5
5
  SHA512:
6
- metadata.gz: 43dcc97756b74b7e1bd4d0db36a5f100871484f2ac20199b01df16b853d31d82e534c435dbeeca8cfdf6c53528dc78829130beb533c894e7079a6353ca482e7d
7
- data.tar.gz: ac1a78c4642b4cbb625160e3a27e7a4d089cc80f2af36470642e3b9664dbf63c0490a65575bc4bf690a7d8dd47514b19694d409182e2fa3c78c724c18bfb77a2
6
+ metadata.gz: b8f23d077d9e757647dcd9f159b3affaf4b44fe874d80244293f8aa62a440f56a0e399fc5a51531e02150700033058c13ef1005aaccf64e535f9a2c4fa8e2391
7
+ data.tar.gz: 143b5a4a6ebf396baeeac8f4eed372236efbd2896b0e457740dbb32c8b278e5f0438ed0edac14d1d422a638f735e3aedf3447d52c2c57a66985ae6cf1d9cfd76
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.0.0
4
4
  before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,12 @@
1
+ ## Unreleased
2
+
3
+ ## [1.1.0] - 2015-11-01
4
+
5
+ ### Added
6
+ - `Config` class for handling persistent configuration across workflow updates.
7
+ - CHANGELOG
8
+
9
+ ## [1.0.0] - 2015-10-31
10
+
11
+ ### Added
12
+ - Library for making Alfred workflows.
data/README.md CHANGED
@@ -86,6 +86,34 @@ This produces the following XML:
86
86
  </items>
87
87
  ```
88
88
 
89
+ ### Workflow Configuration
90
+
91
+ `Alphred::Config` provides some helpers for managing configuration that should
92
+ persist when updating the workflow. This configuration is stored in an JSON
93
+ file in the workflow data directory.
94
+
95
+ ``` ruby
96
+ # config.rb
97
+
98
+ module Workflow
99
+ defaults = { foo: "bar" }
100
+ Config = Alphred::Config.new(**defaults)
101
+ ```
102
+
103
+ The corresponding Script Filter input and Run Action output then look like this:
104
+
105
+ ``` shell
106
+ # script filter
107
+
108
+ ruby -r./config -e'puts Workflow::Config.filter_xml("{query}")'
109
+ ```
110
+
111
+ ``` shell
112
+ # run action
113
+
114
+ ruby -r./config -e'Forecast::Config.update!("{query}")'
115
+ ```
116
+
89
117
  ### Releasing
90
118
 
91
119
  Including `alphred/tasks` in your `Rakefile` will allow access to Alphred's
@@ -95,7 +123,7 @@ dependencies.
95
123
 
96
124
  ## TODO
97
125
 
98
- - Make workflow configuration easier.
126
+ - Add development mode for easier debugging. (Nicer errors, etc.)
99
127
 
100
128
  ## Development
101
129
 
@@ -2,6 +2,7 @@ require "builder"
2
2
 
3
3
  require_relative "alphred/version"
4
4
 
5
+ require_relative "alphred/config"
5
6
  require_relative "alphred/icon"
6
7
  require_relative "alphred/item"
7
8
  require_relative "alphred/items"
@@ -0,0 +1,52 @@
1
+ require "json"
2
+
3
+ module Alphred
4
+ class Config
5
+ PATH = File.join(ENV["alfred_workflow_data"], 'config.json')
6
+
7
+ def self.load(**defaults)
8
+ config = self.new(**defaults)
9
+ config.load!
10
+ config
11
+ end
12
+
13
+ attr_reader :data
14
+
15
+ def initialize(**defaults)
16
+ @data = Hash[defaults.map {|k,v| [k.to_s, v.to_s] }]
17
+ end
18
+
19
+ def load!
20
+ self.data.merge!(JSON.load(File.open(PATH)))
21
+ end
22
+
23
+ def update!(json)
24
+ data = self.data.merge(JSON.load(json))
25
+ File.write(PATH, JSON.dump(data), mode: ?w)
26
+ end
27
+
28
+ def [](key)
29
+ self.data[key.to_s]
30
+ end
31
+
32
+ def filter_xml(filter=nil)
33
+ filter ||= ""
34
+
35
+ items = self.data.map do |key, value|
36
+ title = if filter.empty?
37
+ "Unset #{key}"
38
+ else
39
+ "Set #{key} to #{filter}"
40
+ end
41
+ Item.new(
42
+ uid: key,
43
+ arg: JSON.dump(key => filter),
44
+ title: title,
45
+ subtitle: self[key]
46
+ )
47
+ end
48
+
49
+ Items.new(*items).to_xml
50
+ end
51
+ end
52
+ end
@@ -1,4 +1,5 @@
1
1
  require "builder"
2
+ require "delegate"
2
3
 
3
4
  module Alphred
4
5
  class Items < DelegateClass(Array)
@@ -1,3 +1,3 @@
1
1
  module Alphred
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alphred
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alpha Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-31 00:00:00.000000000 Z
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - CHANGELOG.md
78
79
  - CODE_OF_CONDUCT.md
79
80
  - Gemfile
80
81
  - Guardfile
@@ -83,6 +84,7 @@ files:
83
84
  - Rakefile
84
85
  - alphred.gemspec
85
86
  - lib/alphred.rb
87
+ - lib/alphred/config.rb
86
88
  - lib/alphred/icon.rb
87
89
  - lib/alphred/item.rb
88
90
  - lib/alphred/items.rb