things_templates 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56793d5a794adbf6f1a21fa3c818d470b4e72943
4
+ data.tar.gz: bc72bf3e7a53b7c46266ff009e7abe1cc2762b6e
5
+ SHA512:
6
+ metadata.gz: ec173eef6819ac02c0c635d35de9beed28825ddb49fea7b776e09b353456a0d2dcda1ea975b074b2127d4907360025c5bf6740161e7c6af6aacd40cdb78c28a7
7
+ data.tar.gz: e2ab2cce281f45287e380140d14c7d575227c3c0a0719a91da2f0800ae1f0356992b8d39ef4477f442c5124b2d697abc82a7b6ea3ab7c7fa404f2dc686a94d6e
data/.cane ADDED
@@ -0,0 +1,5 @@
1
+ --no-doc
2
+ --style-measure 100
3
+ --abc-max 8
4
+ --abc-glob {rakefile,Gemfile,**/*.{rb,rake}}
5
+ --style-glob {rakefile,Gemfile,**/*.{rb,rake}}
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in things_templates.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chris Svenningsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Things Templates
2
+
3
+ An easy(?) way to save templates for Things.app. These can include projects or
4
+ items that you often find yourself creating over and over together.
5
+ Example: a template might include the ingredients needed for a particular
6
+ recipe that you want to add to a grocery list.
7
+
8
+ ## Installation
9
+ `$ gem install things_templates`
10
+
11
+ ## Usage
12
+ `$ build_template <path to template>`
13
+
14
+ ## Template Format
15
+ ```
16
+ project: 'Project Name' <optional>
17
+ tags:
18
+ - 'Tag 1'
19
+ - 'Tag 2'
20
+ items:
21
+ - 'Item 1'
22
+ - 'Item 2'
23
+ ```
24
+ Tags will be applied to all items. If a project of the same name already exists,
25
+ the existing project will be used.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Write tests (I'm using RSpec in the `spec` folder)
33
+ 5. Make sure all tests pass
34
+ 6. Push to the branch (`git push origin my-new-feature`)
35
+ 7. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'things_templates'
5
+ rescue
6
+ require 'rubygems'
7
+ require 'things_templates'
8
+ end
9
+
10
+ template = Template.new(ARGV[0])
11
+ template.build!
@@ -0,0 +1,7 @@
1
+ require "things_templates/version"
2
+ require "things_templates/template"
3
+ require "things_templates/things_controller"
4
+
5
+ module ThingsTemplates
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+
3
+ class Template
4
+ attr_reader :items, :project, :tags
5
+
6
+ def initialize(file)
7
+ yaml = YAML.load(File.open(file))
8
+ @items = yaml['items']
9
+ @project = yaml.fetch('project', nil)
10
+ @tags = yaml.fetch('tags', nil)
11
+ end
12
+
13
+ def build!
14
+ if project
15
+ ThingsController.add_items_to_project(project, items, tags)
16
+ else
17
+ items.each do |item|
18
+ ThingsController.add_item(item)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,67 @@
1
+ class ThingsController
2
+ class << self
3
+ def add_item(item)
4
+ command = [base_command, add_item_command(item), end_command].join("\n")
5
+ system(command)
6
+ end
7
+
8
+ def add_project(project)
9
+ unless project_exists?(project)
10
+ command_list = [base_command, add_project_command(project), end_command]
11
+ command = command_list.join("\n")
12
+ system(command)
13
+ end
14
+ end
15
+
16
+ def add_items_to_project(project, items, tags=nil)
17
+ add_project(project) unless project_exists?(project)
18
+ commands = [base_command]
19
+ items.each do |item|
20
+ commands << add_item_command(item, project, tags)
21
+ end
22
+ commands << end_command
23
+ command = commands.join("\n")
24
+ system(command)
25
+ end
26
+
27
+ private
28
+
29
+ def project_exists?(project)
30
+ command = """
31
+ set foundProject to project \"#{project}\"\n
32
+ if status of foundProject is completed then\n
33
+ return false\n
34
+ else\n
35
+ return true\n
36
+ end if\n
37
+ """
38
+ command_list = [base_command, command, end_command].join("\n")
39
+ response = `#{command_list}`
40
+ return false unless response.include?("true") || response.include?("Can't get project")
41
+ true
42
+ end
43
+
44
+ def add_item_command(item, project=nil, tags=nil)
45
+ base_add = "set newToDo to make new to do with properties {name:\"#{item}\" }"
46
+ base_add += " at beginning of project \"#{project}\"" if project
47
+ base_add += tags_command(tags) if tags
48
+ base_add
49
+ end
50
+
51
+ def add_project_command(project)
52
+ "set newProject to make new project with properties {name:\"#{project}\"}"
53
+ end
54
+
55
+ def base_command
56
+ "osascript -e 'tell application \"Things\""
57
+ end
58
+
59
+ def end_command
60
+ "end tell'"
61
+ end
62
+
63
+ def tags_command(tags)
64
+ "\nset tag names of newToDo to \"#{tags.join(', ')}\""
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module ThingsTemplates
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ items:
2
+ - test_item_1
3
+ - test_item_2
@@ -0,0 +1,7 @@
1
+ project: test_project
2
+ tags:
3
+ - tag_1
4
+ - tag_2
5
+ items:
6
+ - test_item_1
7
+ - test_item_2
@@ -0,0 +1 @@
1
+ require 'things_templates'
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Template do
4
+ let(:file_path) { 'spec/files/test_template.yml' }
5
+
6
+ subject { Template.new file_path }
7
+
8
+ describe '.initialize' do
9
+ let(:items) { ['test_item_1', 'test_item_2'] }
10
+
11
+ it 'loads the given file' do
12
+ expect(subject.items).to eq items
13
+ end
14
+ end
15
+
16
+ describe '#build' do
17
+ before { ThingsController.stub(:add_item) }
18
+
19
+ context 'with an item list template' do
20
+ before { subject.build! }
21
+
22
+ it 'adds a Things item for each item' do
23
+ expect(ThingsController).to have_received(:add_item).with('test_item_1')
24
+ expect(ThingsController).to have_received(:add_item).with('test_item_2')
25
+ end
26
+ end
27
+
28
+ context 'with a project list template with tags' do
29
+ let(:file_path) { 'spec/files/test_template_with_project.yml' }
30
+
31
+ before { ThingsController.stub(:add_items_to_project) }
32
+ before { subject.build! }
33
+
34
+ it 'creates a project' do
35
+ expect(ThingsController).to have_received(:add_items_to_project)
36
+ .with('test_project', ['test_item_1', 'test_item_2'], ['tag_1', 'tag_2'])
37
+ end
38
+
39
+ it 'adds a Things item for each item' do
40
+ expect(ThingsController).to_not have_received(:add_item)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThingsController do
4
+ describe '.add_item' do
5
+ let(:new_item) { 'new item' }
6
+ before { ThingsController.stub(:system) }
7
+ before { ThingsController.add_item(new_item) }
8
+
9
+ it 'calls the add script with the item' do
10
+ expect(ThingsController).to have_received(:system)
11
+ .with(/.*#{new_item}.*/)
12
+ end
13
+ end
14
+
15
+ describe '.add_project' do
16
+ let(:new_project) { 'new project' }
17
+
18
+ subject { ThingsController.add_project new_project }
19
+
20
+ before { ThingsController.stub(:system) }
21
+
22
+ context 'given the project does not exist' do
23
+ before { ThingsController.stub(:project_exists?).and_return(false) }
24
+ before { subject }
25
+
26
+ it 'creates the project' do
27
+ expect(ThingsController).to have_received(:system)
28
+ .with(/.*#{new_project}.*/)
29
+ end
30
+ end
31
+
32
+ context 'given the project already exists' do
33
+ before { ThingsController.stub(:project_exists?).and_return(true) }
34
+
35
+ it 'does not create the project' do
36
+ expect(ThingsController).to_not have_received(:system)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '.add_items_to_project' do
42
+ let(:new_item) { 'new item' }
43
+ let(:new_project) { 'new project' }
44
+ let(:tags) { nil }
45
+
46
+ subject { ThingsController.add_items_to_project(new_project, [new_item], tags) }
47
+
48
+ before { ThingsController.stub(:system) }
49
+
50
+ context 'given the project exists' do
51
+ before { ThingsController.stub(:project_exists?).and_return(true) }
52
+ before { subject }
53
+
54
+ it 'calls the add script with the item and project' do
55
+ expect(ThingsController).to have_received(:system)
56
+ .with(/.*#{new_item}.*#{new_project}.*/)
57
+ end
58
+
59
+ context 'given tags' do
60
+ let(:tags) { ['best', 'ever'] }
61
+
62
+ it 'calls the add script with the item, project and tags' do
63
+ expect(ThingsController).to have_received(:system)
64
+ .with(/.*#{new_item}.*#{new_project}.*#{tags.join(', ')}.*/)
65
+ end
66
+ end
67
+ end
68
+
69
+ context 'given the project does not exist' do
70
+ before { ThingsController.stub(:project_exists?).and_return(false) }
71
+
72
+ it 'creates the project and item' do
73
+ expect(ThingsController).to receive(:system)
74
+ .with(/.*#{new_project}.*/).ordered
75
+
76
+ expect(ThingsController).to receive(:system)
77
+ .with(/.*#{new_item}.*#{new_project}.*/).ordered
78
+
79
+ subject
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'things_templates/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "things_templates"
8
+ spec.version = ThingsTemplates::VERSION
9
+ spec.authors = ["Chris Svenningsen"]
10
+ spec.email = ["crsven@gmail.com"]
11
+ spec.description = "Templating for Things.app"
12
+ spec.summary = "Easy(?) templating for Things.app. Create and build templates of projects, items and tags."
13
+ spec.homepage = "https://github.com/crsven/things_templates"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "cane"
25
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: things_templates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Svenningsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cane
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: Templating for Things.app
70
+ email:
71
+ - crsven@gmail.com
72
+ executables:
73
+ - build_template
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .cane
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/build_template
84
+ - lib/things_templates.rb
85
+ - lib/things_templates/template.rb
86
+ - lib/things_templates/things_controller.rb
87
+ - lib/things_templates/version.rb
88
+ - spec/files/test_template.yml
89
+ - spec/files/test_template_with_project.yml
90
+ - spec/spec_helper.rb
91
+ - spec/template_spec.rb
92
+ - spec/things_controller_spec.rb
93
+ - things_templates.gemspec
94
+ homepage: https://github.com/crsven/things_templates
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.1.9
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Easy(?) templating for Things.app. Create and build templates of projects,
118
+ items and tags.
119
+ test_files:
120
+ - spec/files/test_template.yml
121
+ - spec/files/test_template_with_project.yml
122
+ - spec/spec_helper.rb
123
+ - spec/template_spec.rb
124
+ - spec/things_controller_spec.rb