markdo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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 markdo.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2016 Benjamin Oakes
2
+
3
+ (The MIT license)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Benjamin Oakes
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,59 @@
1
+ # Markdo
2
+
3
+ Markdown-based task manager. Inspired by OmniFocus and GitHub Flavored Markdown's task lists.
4
+
5
+ ## Installation
6
+
7
+ Install Ruby, and then:
8
+
9
+ gem install markdo
10
+
11
+ ## Usage
12
+
13
+ You might already be using Markdo-formatted text already!
14
+
15
+ Basically, you write Markdown, and use the GFM "task list" syntax:
16
+
17
+ ```
18
+ # Example
19
+
20
+ Any Markdown you want
21
+
22
+ ## Like headings
23
+
24
+ ## And subheadings
25
+
26
+ > Quoted text.
27
+
28
+ And of course:
29
+
30
+ - [x] A completed task
31
+ - [ ] An incomplete task
32
+ - [ ] A subtask
33
+ - [ ] 2016-01-01 A task with a date
34
+ - [ ] A task with a @tag
35
+ ```
36
+
37
+ Then you can use `markdo` to interact with your files.
38
+
39
+ See `markdo help` for more information.
40
+
41
+ add "string" Add a task to the inbox. (Set $MARKDO_ROOT and $MARKDO_INBOX.)
42
+ edit Edit $MARKDO_ROOT in $EDITOR.
43
+ help, --help Display this help text.
44
+ overview Get overview of starred, today's, and tomorrow's tasks.
45
+ overdue Search *.md files for previous dates. (YYYY-MM-DD format.)
46
+ tag "string' Search *.md files for @tag.
47
+ today Search *.md files for today's date. (YYYY-MM-DD format.)
48
+ tomorrow Search *.md files for tomorrow's date. (YYYY-MM-DD format.)
49
+ star, starred Search *.md files for @star.
50
+ query, q "string" Search *.md files for string.
51
+ version, --version Display the version.
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/markdo ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'markdo'
3
+
4
+ Markdo::CLI.new(STDOUT, STDERR, ENV).run(*ARGV)
data/lib/markdo.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "markdo/version"
2
+ require "markdo/cli"
@@ -0,0 +1,21 @@
1
+ require 'markdo/command'
2
+
3
+ module Markdo
4
+ class AddCommand < Command
5
+ def run(task)
6
+ File.open(inbox_path, 'a') do |file|
7
+ file.puts(template(task))
8
+ end
9
+ end
10
+
11
+ protected
12
+
13
+ def template(task)
14
+ "- [ ] #{task}"
15
+ end
16
+
17
+ def inbox_path
18
+ File.join(@env['MARKDO_ROOT'], @env['MARKDO_INBOX'])
19
+ end
20
+ end
21
+ end
data/lib/markdo/cli.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'markdo/add_command'
2
+ require 'markdo/edit_command'
3
+ require 'markdo/help_command'
4
+ require 'markdo/overview_command'
5
+ require 'markdo/query_command'
6
+ require 'markdo/star_command'
7
+ require 'markdo/tag_command'
8
+ require 'markdo/today_command'
9
+ require 'markdo/tomorrow_command'
10
+ require 'markdo/version_command'
11
+
12
+ module Markdo
13
+ class CLI
14
+ def initialize(stdout, stderr, full_env)
15
+ @stdout = stdout
16
+ @stderr = stderr
17
+ @full_env = full_env
18
+ end
19
+
20
+ def run(command_name = 'help', *args)
21
+ command = case command_name
22
+ when 'add'
23
+ AddCommand
24
+ when 'edit'
25
+ EditCommand
26
+ when 'overdue'
27
+ OverdueCommand
28
+ when 'overview'
29
+ OverviewCommand
30
+ when 'query', 'q'
31
+ QueryCommand
32
+ when 'star', 'starred'
33
+ StarCommand
34
+ when 'tag'
35
+ TagCommand
36
+ when 'today'
37
+ TodayCommand
38
+ when 'tomorrow'
39
+ TomorrowCommand
40
+ when 'version', '--version'
41
+ VersionCommand
42
+ else
43
+ HelpCommand
44
+ end
45
+
46
+ command.new(@stdout, @stderr, env).run(*args)
47
+ end
48
+
49
+ private
50
+
51
+ def default_env
52
+ {
53
+ 'MARKDO_ROOT' => '.',
54
+ 'MARKDO_INBOX' => 'Inbox.md',
55
+ }
56
+ end
57
+
58
+ def env
59
+ default_env.merge(@full_env)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ module Markdo
2
+ class Command
3
+ def initialize(stdout, stderr, env)
4
+ @stdout = stdout
5
+ @stderr = stderr
6
+ @env = env
7
+ end
8
+
9
+ def run
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'markdo/query_command'
2
+
3
+ module Markdo
4
+ class DateCommand < QueryCommand
5
+ def run(date)
6
+ super(date.iso8601)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'shellwords'
2
+ require 'markdo/command'
3
+
4
+ module Markdo
5
+ class EditCommand < Command
6
+ def run
7
+ system("#{@env['EDITOR']} #{safe_markdo_root}")
8
+ end
9
+
10
+ private
11
+
12
+ def safe_markdo_root
13
+ Shellwords.shellescape(@env['MARKDO_ROOT'])
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'markdo/command'
2
+
3
+ module Markdo
4
+ class HelpCommand < Command
5
+ def run
6
+ @stderr.puts <<-EOF
7
+ Markdown-based task manager.
8
+
9
+ add "string" Add a task to the inbox. (Set $MARKDO_ROOT and $MARKDO_INBOX.)
10
+ edit Edit $MARKDO_ROOT in $EDITOR.
11
+ help, --help Display this help text.
12
+ overview Get overview of overdue, starred, today's, and tomorrow's tasks.
13
+ overdue Search *.md files for previous dates. (YYYY-MM-DD format.)
14
+ tag "string' Search *.md files for @tag.
15
+ today Search *.md files for today's date. (YYYY-MM-DD format.)
16
+ tomorrow Search *.md files for tomorrow's date. (YYYY-MM-DD format.)
17
+ star, starred Search *.md files for @star.
18
+ query, q "string" Search *.md files for string.
19
+ version, --version Display the version.
20
+ EOF
21
+
22
+ exit 1
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ require 'date'
2
+ require 'markdo/query_command'
3
+
4
+ module Markdo
5
+ # TODO: More testing of this logic. As of 2016-01-23, I was building this
6
+ # project as a proof of concept.
7
+ class OverdueCommand < Command
8
+ def initialize(*)
9
+ @date = Date.today
10
+ super
11
+ end
12
+
13
+ def run
14
+ query_command = QueryCommand.new(@stdout, @stderr, @env)
15
+
16
+ all_queries.each do |query|
17
+ query_command.run(query)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def all_queries
24
+ [previous_years, previous_months_this_year, previous_days_this_month].flatten
25
+ end
26
+
27
+ def previous_days_this_month
28
+ (1...@date.day).to_a.map { |day|
29
+ "#{@date.year}-#{justify(@date.month)}-#{justify(day)}"
30
+ }
31
+ end
32
+
33
+ def previous_months_this_year
34
+ (1...@date.month).to_a.map { |month|
35
+ "#{@date.year}-#{justify(month)}"
36
+ }
37
+ end
38
+
39
+ def previous_years
40
+ (2000...@date.year).to_a.map { |year| "#{year}-" }
41
+ end
42
+
43
+ def justify(less_than_100)
44
+ less_than_100.to_s.rjust(2, '0')
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ require 'markdo/command'
2
+ require 'markdo/overdue_command'
3
+ require 'markdo/star_command'
4
+ require 'markdo/today_command'
5
+ require 'markdo/tomorrow_command'
6
+
7
+ module Markdo
8
+ class OverviewCommand < Command
9
+ def run
10
+ commands = [OverdueCommand, StarCommand, TodayCommand, TomorrowCommand]
11
+
12
+ commands.each do |command|
13
+ command.new(@stdout, @stderr, @env).run
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'markdo/command'
2
+
3
+ module Markdo
4
+ class QueryCommand < Command
5
+ def run(string)
6
+ regexp = Regexp.new(string, Regexp::IGNORECASE)
7
+
8
+ matches = Dir.
9
+ glob(markdown_glob).
10
+ map { |path| File.readlines(path) }.
11
+ flatten.
12
+ grep(regexp)
13
+
14
+ @stdout.puts(matches)
15
+ end
16
+
17
+ protected
18
+
19
+ def markdown_glob
20
+ "#{@env['MARKDO_ROOT']}/*.md"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'markdo/tag_command'
2
+
3
+ module Markdo
4
+ class StarCommand < TagCommand
5
+ def run
6
+ super('star')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'markdo/query_command'
2
+
3
+ module Markdo
4
+ class TagCommand < QueryCommand
5
+ def run(string)
6
+ super("@#{string}")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'date'
2
+ require 'markdo/date_command'
3
+
4
+ module Markdo
5
+ class TodayCommand < DateCommand
6
+ def run
7
+ super(Date.today)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'date'
2
+ require 'markdo/date_command'
3
+
4
+ module Markdo
5
+ class TomorrowCommand < DateCommand
6
+ def run
7
+ super(Date.today + 1)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Markdo
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'markdo/command'
2
+ require 'markdo/version'
3
+
4
+ module Markdo
5
+ class VersionCommand < Command
6
+ def run
7
+ @stdout.puts("v#{Markdo::VERSION}")
8
+ end
9
+ end
10
+ end
data/markdo.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markdo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "markdo"
8
+ spec.version = Markdo::VERSION
9
+ spec.authors = ["Benjamin Oakes"]
10
+ spec.email = ["hello@benjaminoakes.com"]
11
+ spec.description = %q{Markdown-based task manager}
12
+ spec.summary = %q{Markdown-based task manager}
13
+ spec.homepage = "http://github.com/benjaminoakes/markdo"
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
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Benjamin Oakes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-01-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &23813680 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *23813680
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &23812900 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *23812900
36
+ description: Markdown-based task manager
37
+ email:
38
+ - hello@benjaminoakes.com
39
+ executables:
40
+ - markdo
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - bin/markdo
51
+ - lib/markdo.rb
52
+ - lib/markdo/add_command.rb
53
+ - lib/markdo/cli.rb
54
+ - lib/markdo/command.rb
55
+ - lib/markdo/date_command.rb
56
+ - lib/markdo/edit_command.rb
57
+ - lib/markdo/help_command.rb
58
+ - lib/markdo/overdue_command.rb
59
+ - lib/markdo/overview_command.rb
60
+ - lib/markdo/query_command.rb
61
+ - lib/markdo/star_command.rb
62
+ - lib/markdo/tag_command.rb
63
+ - lib/markdo/today_command.rb
64
+ - lib/markdo/tomorrow_command.rb
65
+ - lib/markdo/version.rb
66
+ - lib/markdo/version_command.rb
67
+ - markdo.gemspec
68
+ homepage: http://github.com/benjaminoakes/markdo
69
+ licenses:
70
+ - MIT
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.11
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Markdown-based task manager
93
+ test_files: []
94
+ has_rdoc: