todo_cli_app 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 95063a1e4b786e7bbf9791959c9c4b91391dc624d8f9dcaa46fcd32e1e4baaf9
4
+ data.tar.gz: 626f4c7c37a78542373e72af0186535a80aaf5bf8c44f8820a5397496e5b06b0
5
+ SHA512:
6
+ metadata.gz: a5483884fc56111c19e7783406c886b1eb40b2478969f7774781d103f8a7565df364643d03aeea8c7d134779e9a8444daf0d278c22ba2a9bc078a233e385ba4e
7
+ data.tar.gz: 3410c99f7bc59e047a216d83e6c07bda2d1a2f95e5de123d0ff459bdd3aefdfb31ed32f7c3679d623c9562f0035b1945db7152f266f4af6bc955ed3b2f6a860a
@@ -0,0 +1,7 @@
1
+ Copyright 2021 Juan Manuel Ramallo
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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 ARTICULAR 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.P
@@ -0,0 +1,16 @@
1
+ # What?
2
+ A to-do app, the ruby cli-only edition to-do app [insert registered mark logo here].
3
+
4
+ # Why?
5
+ Why not?
6
+
7
+ # How to use
8
+
9
+ 1. `link ./exe/todo /usr/local/bin/todo` or whatever folder that is present in $PATH
10
+ 2. `todo -h` to get started
11
+
12
+ # Contribute
13
+ Do not. This is just for fun.
14
+
15
+ # License
16
+ It's fancier with [a license](https://opensource.org/licenses/MIT)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'todo'
5
+
6
+ options = ToDo::Parser.new(ARGV).parse
7
+ context = ToDo::Context.new(options)
8
+
9
+ if options.query
10
+ ToDo::Finder.new(context: context, query: options.query).find
11
+ elsif options.visualize
12
+ ToDo::Visualizer.new(context).view
13
+ else
14
+ ToDo::Session.new(context).start
15
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToDo
4
+ #
5
+ # Context object that provides general info for all objects in the to-do app.
6
+ #
7
+ class Context
8
+ DIR_PATH = '.todo'
9
+
10
+ attr_reader :options
11
+
12
+ def initialize(options)
13
+ @options = options
14
+ end
15
+
16
+ def dir_path
17
+ File.join(Dir.home, DIR_PATH)
18
+ end
19
+
20
+ def file_name
21
+ "#{options.date}.md"
22
+ end
23
+
24
+ def file_path
25
+ File.join(dir_path, file_name)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToDo
4
+ #
5
+ # Finds text in to-dos entries. Relies on system's `find' and `grep' commands.
6
+ #
7
+ class Finder
8
+ attr_reader :context, :query
9
+
10
+ def initialize(context:, query:)
11
+ @context = context
12
+ @query = query
13
+ end
14
+
15
+ def find
16
+ system("find #{context.dir_path} -type f | xargs grep -Hni \"#{query}\"")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToDo
4
+ #
5
+ # OptionParser wrapper for the to-do app.
6
+ #
7
+ class Parser
8
+ Options = Struct.new(:date, :yesterday, :query, :visualize, keyword_init: true)
9
+
10
+ attr_reader :args
11
+
12
+ def initialize(args)
13
+ @args = args
14
+ end
15
+
16
+ def parse
17
+ OptionParser.new do |parser|
18
+ parser.banner = <<~TXT
19
+ A ruby CLI-only To Do app, because why not?
20
+ Usage:
21
+ todo -d, --date 2020-12-25 # Open todo for the date
22
+ todo -y, --yesterday # Open todo yesterday
23
+ todo # Open todo for today
24
+ todo -f, --find algo # Looks for todo with word "algo"
25
+ todo -v, --visualize # Opens an HTML file with the to-dos
26
+
27
+ TXT
28
+
29
+ parser.on('-y', '--yesterday', "Todo's for yesterday") do |y|
30
+ options.yesterday = y
31
+ options.date = Date.today - 1
32
+ end
33
+
34
+ parser.on('-dDATE', '--date=DATE', "Todo's date") do |d|
35
+ options.date = parse_date(d)
36
+ end
37
+
38
+ parser.on('-fQUERY', '--find=QUERY', 'Looks for query') do |q|
39
+ options.query = q
40
+ end
41
+
42
+ parser.on('-v', '--visualize', 'Visualize a todo list') do |v|
43
+ options.visualize = v
44
+ end
45
+
46
+ parser.parse!(args)
47
+ end
48
+
49
+ options
50
+ end
51
+
52
+ private
53
+
54
+ def options
55
+ @options ||= Options.new(date: Date.today)
56
+ end
57
+
58
+ def parse_date(date)
59
+ case date
60
+ when /[0-9]{4}-[0-9]{2}-[0-9]{2}/
61
+ Date.parse(date)
62
+ when nil, ''
63
+ Date.today
64
+ else
65
+ raise 'WAT'
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToDo
4
+ #
5
+ # Creates or reopens a to-do file for the given date.
6
+ #
7
+ class Session
8
+ # TODO: Add support for custom templates
9
+ TEMPLATE = ERB.new(<<~ERB).freeze
10
+ # <%= @date %>
11
+
12
+ ## To-do
13
+ -
14
+ ## Plan
15
+ -
16
+ ## Questions
17
+ -
18
+ ERB
19
+
20
+ attr_reader :context
21
+
22
+ def initialize(context)
23
+ @context = context
24
+ @date = context.options.date
25
+
26
+ Dir.mkdir(context.dir_path) unless Dir[context.dir_path].any?
27
+ prepare_todo_file
28
+ end
29
+
30
+ def start
31
+ system("$EDITOR #{context.file_path}")
32
+ end
33
+
34
+ private
35
+
36
+ def prepare_todo_file
37
+ return if Dir[context.file_path].any?
38
+
39
+ File.open(context.file_path, 'w') do |f|
40
+ f.puts TEMPLATE.result(self.binding)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tmpdir'
4
+ require 'optparse'
5
+ require 'date'
6
+ require 'erb'
7
+
8
+ require 'context'
9
+ require 'session'
10
+ require 'parser'
11
+ require 'finder'
12
+ require 'visualizer'
13
+ require 'version'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToDo
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ VERSION = [MAJOR, MINOR, PATCH].join('.')
8
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToDo
4
+ #
5
+ # Relies on pandoc to generate HTML out from a Github flavored markdown file.
6
+ # https://pandoc.org/installing.html
7
+ #
8
+ class Visualizer
9
+ CSS_URL = 'https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css'
10
+ BODY_CSS = <<~CSS
11
+ max-width: 700px;
12
+ margin: 40px auto;
13
+ CSS
14
+
15
+ attr_reader :context
16
+
17
+ def initialize(context)
18
+ @context = context
19
+ end
20
+
21
+ def view
22
+ raise 'Something failed with Pandoc' unless system(command)
23
+
24
+ update_body_class
25
+ system("open #{tmpfile}")
26
+ end
27
+
28
+ private
29
+
30
+ def command
31
+ [
32
+ "pandoc #{context.file_path}",
33
+ '-f gfm',
34
+ '-s',
35
+ "-o #{tmpfile}",
36
+ '--metadata title="TODO"',
37
+ "-c #{CSS_URL}"
38
+ ].join(' ')
39
+ end
40
+
41
+ def tmpfile
42
+ "#{File.join(Dir.tmpdir, context.file_name)}.html"
43
+ end
44
+
45
+ # TODO: This can be updated to just modify the body tag
46
+ def update_body_class
47
+ html = File.read(tmpfile)
48
+ html.sub!('<body>', "<body class='markdown-body' style='#{BODY_CSS}'>")
49
+ File.open(tmpfile, 'wb') { |f| f.puts(html) }
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: todo_cli_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Manuel Ramallo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A to-do app, the ruby cli-only edition to-do app [insert registered mark
14
+ logo here].
15
+ email: juanmanuelramallo@hey.com
16
+ executables:
17
+ - todo
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE.txt
22
+ - README.md
23
+ - exe/todo
24
+ - lib/context.rb
25
+ - lib/finder.rb
26
+ - lib/parser.rb
27
+ - lib/session.rb
28
+ - lib/todo.rb
29
+ - lib/version.rb
30
+ - lib/visualizer.rb
31
+ homepage: https://github.com/juanmanuelramallo/todo
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ homepage_uri: https://github.com/juanmanuelramallo/todo
36
+ source_code_uri: https://github.com/juanmanuelramallo/todo
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.2.3
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: A ruby cli-only to-do app
56
+ test_files: []