work_md 0.2.7 → 0.2.8

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
  SHA256:
3
- metadata.gz: 240715cce22ce57249e206aaccb86151732c059fa4af0f00b1b3d2c8f47389bb
4
- data.tar.gz: 436b17f29758239fe959abdf6d8ffaf24f629ba3fb41315bf92e8c42eaaac4cb
3
+ metadata.gz: e7f163bb109aa82d9095042209b18157e3ba0ff0ab23456b43e0cd65ba90aeee
4
+ data.tar.gz: a78b3daa4090a73e1bcdda5e51eb30718a4787f2932027c5945e6e14322b826b
5
5
  SHA512:
6
- metadata.gz: 595cc7e93141034918c3076dcf1416fe46ba9c0194fd06026e117269c73482a595d8d6cfdf7b23cc73e67a60880971d3ba2c76453a567ea6581d273c529414d7
7
- data.tar.gz: e9599c13e70ade59262afb89dca054c8dc54821906e9eca4a113efc579716f3df2e1e2f91819d1a0b0edb77a632b8d227233aa3912b70fd87dcb509b984cd0ed
6
+ metadata.gz: d2e117fa8755001b8f4ccb44a77666e2c3b8f25c1deb959d8c702c55096bfb4cf625923eb09cf184ff3aef14659beabfdd3718ecd492384044efb5b01010ca29
7
+ data.tar.gz: 7a555df5793cbc958eff5ff7f42a5078357afeb9ab66b561ff4a82a04c0e120c565f22041e8bf1bff3b8e5f5ca345945b570cd015b66b92f037b481a4fd602b6
data/bin/work_md CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ # require_relative '../lib/work_md'
4
5
  require 'work_md'
5
6
 
6
7
  WorkMd::Cli.execute(ARGV)
@@ -5,8 +5,12 @@ module WorkMd
5
5
  class Tyesterday
6
6
  class << self
7
7
  def execute(_argv = [])
8
- WorkMd::File.open_or_create(DateTime.now)
9
- WorkMd::File.open_or_create(Date.today.prev_day)
8
+ filenames =
9
+ [DateTime.now, Date.today.prev_day].map do |date|
10
+ WorkMd::File.create_if_not_exist(date)
11
+ end
12
+
13
+ WorkMd::File.open_in_editor(filenames[0], filenames[1])
10
14
  end
11
15
  end
12
16
  end
data/lib/work_md/file.rb CHANGED
@@ -1,49 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'byebug'
4
+
3
5
  module WorkMd
4
6
  class File
5
7
  def self.open_or_create(some_date)
8
+ open_in_editor(create_if_not_exist(some_date))
9
+ end
10
+
11
+ def self.create_if_not_exist(some_date)
6
12
  t = WorkMd::Config.translations
7
13
  work_dir = WorkMd::Config.work_dir
8
14
 
9
15
  ::FileUtils
10
16
  .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
11
- unless ::File.exist?("#{work_dir}/#{some_date.strftime('%Y/%m/%d')}.md")
12
- ::File.open(
13
- "#{work_dir}/#{some_date.strftime('%Y/%m/%d')}.md",
14
- 'w+'
15
- ) do |f|
16
- # rubocop:disable Layout/LineLength
17
- f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{WorkMd::Config.title} \n\n")
18
- # rubocop:enable Layout/LineLength
19
- f.puts("### #{t[:tasks]}:\n\n")
20
- f.puts("- [ ]\n\n")
21
- f.puts("---\n\n")
22
- f.puts("### #{t[:meetings]}:\n\n")
23
- f.puts("- [ ]\n\n")
24
- f.puts("---\n\n")
25
- f.puts("### #{t[:interruptions]}:\n\n")
26
- f.puts("---\n\n")
27
- f.puts("### #{t[:difficulties]}:\n\n")
28
- f.puts("---\n\n")
29
- f.puts("### #{t[:observations]}:\n\n")
30
- f.puts("---\n\n")
31
- f.puts("### #{t[:pomodoros]}:\n\n")
32
- f.puts("0\n\n")
33
- end
17
+
18
+ filename = "#{some_date.strftime('%Y/%m/%d')}.md"
19
+
20
+ return filename if ::File.exist?("#{work_dir}/#{filename}")
21
+
22
+ ::File.open(
23
+ "#{work_dir}/#{filename}",
24
+ 'w+'
25
+ ) do |f|
26
+ # rubocop:disable Layout/LineLength
27
+ f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{WorkMd::Config.title} \n\n")
28
+ # rubocop:enable Layout/LineLength
29
+ f.puts("### #{t[:tasks]}:\n\n")
30
+ f.puts("- [ ]\n\n")
31
+ f.puts("---\n\n")
32
+ f.puts("### #{t[:meetings]}:\n\n")
33
+ f.puts("- [ ]\n\n")
34
+ f.puts("---\n\n")
35
+ f.puts("### #{t[:interruptions]}:\n\n")
36
+ f.puts("---\n\n")
37
+ f.puts("### #{t[:difficulties]}:\n\n")
38
+ f.puts("---\n\n")
39
+ f.puts("### #{t[:observations]}:\n\n")
40
+ f.puts("---\n\n")
41
+ f.puts("### #{t[:pomodoros]}:\n\n")
42
+ f.puts("0\n\n")
34
43
  end
35
44
 
45
+ filename
46
+ end
47
+
48
+ def self.open_in_editor(filename1, filename2 = nil)
36
49
  editor = WorkMd::Config.editor
37
50
 
38
- ::FileUtils.cd(work_dir) do
39
- if editor.nil?
40
- ::TTY::Editor.open("#{some_date.strftime('%Y/%m/%d')}.md")
41
- else
42
- ::TTY::Editor.open(
43
- "#{some_date.strftime('%Y/%m/%d')}.md",
44
- command: editor
45
- )
46
- end
51
+ ::FileUtils.cd(WorkMd::Config.work_dir) do
52
+ ENV['EDITOR'] = editor unless editor.nil?
53
+
54
+ return ::TTY::Editor.open(filename1) if filename2.nil?
55
+
56
+ ::TTY::Editor.open(filename1, filename2)
47
57
  end
48
58
  end
49
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.7'
4
+ VERSION = '0.2.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Fernandez Teixeira