work_md 0.2.9 → 0.3.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
  SHA256:
3
- metadata.gz: a981624ebcb01d89fcb6097d5969c8a4953c548c5f0af0ccad81c2ae56af7945
4
- data.tar.gz: 2e22f7de5b3fc2e72025337b7176cb637e09d67ff56e2bbfd2f025ea21108eea
3
+ metadata.gz: db1941195d4c4dddb02ca3375e3f1dcd099e8799330f7ac6b78ac62cb39984b5
4
+ data.tar.gz: 92c72a7d0909f34bab420fabe8c85959b23ce069908da3704cb4b016d036316f
5
5
  SHA512:
6
- metadata.gz: 72060087a643c751da31160dc7d24b8747655ae1f42561fd1d64b4de9172304472d22fcda8da3d10dbf11a1cab27cbed48a5406a63881113cee9cc3a64e69620
7
- data.tar.gz: cb634d22d720628d72a13e6b7975a27934f43064ef9bcacd82eb63d67999703b8df8d00ac5adb923c6d6fa9ab21d34c811b700a6f41ec6a03c5730a4f29ec3c1
6
+ metadata.gz: f5f618a78bab8117824f2819e7c4bf49999a4f3396e1dcd6c198fd78ef37ece4d708ffd7400f9d38eeac72a361109124bf6f9f8feb681730e44d2a65045c91f3
7
+ data.tar.gz: 3030407c84b51b4bb9caf485c88e851b824b1aadcda7ab1859a46c985066a623f74a19614fed3db1a0186822053637fc69deff49d288ab877f4adb9c023df4cf
data/lib/work_md.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'work_md/version'
4
4
  require_relative 'work_md/config'
5
5
  require_relative 'work_md/file'
6
6
  require_relative 'work_md/commands/today'
7
+ require_relative 'work_md/commands/config'
7
8
  require_relative 'work_md/commands/yesterday'
8
9
  require_relative 'work_md/commands/tyesterday'
9
10
  require_relative 'work_md/parser/engine'
data/lib/work_md/cli.rb CHANGED
@@ -9,11 +9,10 @@ module WorkMd
9
9
  't' => 'today',
10
10
  'ty' => 'tyesterday',
11
11
  'y' => 'yesterday',
12
+ 'c' => 'config',
12
13
  'p' => 'parse'
13
14
  }.freeze
14
15
 
15
- DEFAULT_COMMAND = WorkMd::Commands::Today
16
-
17
16
  def self.execute(argv)
18
17
  first_argv_argument = argv.shift
19
18
 
@@ -26,17 +25,17 @@ module WorkMd
26
25
  .const_get("WorkMd::Commands::#{command}")
27
26
  .send(:execute, argv)
28
27
  rescue NameError
29
- puts info(
28
+ puts help(
30
29
  ::TTY::Box.frame(
31
30
  "Command '#{first_argv_argument}' not found!",
32
31
  **error_frame_style
33
32
  )
34
33
  )
35
34
  rescue CommandMissing
36
- DEFAULT_COMMAND.execute(argv)
35
+ help('Welcome! =)')
37
36
  end
38
37
 
39
- def self.info(message = '')
38
+ def self.help(message = '')
40
39
  # rubocop:disable Layout/LineLength
41
40
  puts ::TTY::Box.frame(
42
41
  message,
@@ -49,8 +48,9 @@ module WorkMd
49
48
  '- work_md yesterday',
50
49
  '- work_md tyesterday',
51
50
  '- work_md parse',
51
+ '- work_md config',
52
52
  '',
53
- 'read more in github.com/henriquefernandez/work_md',
53
+ 'more information in github.com/henriquefernandez/work_md',
54
54
  padding: 1,
55
55
  title: { top_left: '(work_md)', bottom_right: "(v#{WorkMd::VERSION})" }
56
56
  )
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkMd
4
+ module Commands
5
+ class Config
6
+ class << self
7
+ def execute(_argv = [])
8
+ file_name = 'config.yml'
9
+ work_dir = ::WorkMd::Config::DEFAULT_WORK_DIR
10
+
11
+ unless ::File.exist?("#{work_dir}/#{file_name}")
12
+ ::FileUtils.mkdir_p(work_dir)
13
+
14
+ ::File.open("#{work_dir}/#{file_name}", 'w+') do |f|
15
+ f.puts("# Example configuration:")
16
+ f.puts("#")
17
+ f.puts("# title: Your Name")
18
+ f.puts("# editor: vim")
19
+ f.puts("# lang: en")
20
+ f.puts("#")
21
+ f.puts("title: # Title your work_md files")
22
+ f.puts("editor: # Your default editor")
23
+ f.puts("lang: # Only 'pt', 'en' and 'es' avaiable")
24
+ end
25
+ end
26
+
27
+ ::WorkMd::File.open_in_editor(
28
+ file_names: [file_name],
29
+ dir: work_dir
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -83,7 +83,7 @@ module WorkMd
83
83
  ::TTY::Editor.open(PARSED_FILE_PATH)
84
84
  end
85
85
  rescue => e
86
- WorkMd::Cli.info(
86
+ WorkMd::Cli.help(
87
87
  ::TTY::Box.frame(
88
88
  "message: #{e.message}",
89
89
  "",
@@ -5,12 +5,12 @@ module WorkMd
5
5
  class Tyesterday
6
6
  class << self
7
7
  def execute(_argv = [])
8
- filenames =
8
+ file_names =
9
9
  [DateTime.now, Date.today.prev_day].map do |date|
10
10
  WorkMd::File.create_if_not_exist(date)
11
11
  end
12
12
 
13
- WorkMd::File.open_in_editor(filenames[0], filenames[1])
13
+ WorkMd::File.open_in_editor(file_names: file_names)
14
14
  end
15
15
  end
16
16
  end
@@ -4,7 +4,7 @@ require 'yaml'
4
4
 
5
5
  module WorkMd
6
6
  module Config
7
- DEFAULT_WORK_DIR = Dir.home + '/work_md'
7
+ DEFAULT_WORK_DIR = "#{Dir.home}/work_md"
8
8
  TRANSLATIONS = {
9
9
  'pt' =>
10
10
  {
@@ -25,7 +25,18 @@ module WorkMd
25
25
  observations: 'Observations',
26
26
  pomodoros: 'Pomodoros / Cycles',
27
27
  per_day: 'per day'
28
+ },
29
+ 'es' =>
30
+ {
31
+ tasks: 'Tareas',
32
+ meetings: 'Reuniones',
33
+ interruptions: 'Interrupciones',
34
+ difficulties: 'Dificultades',
35
+ observations: 'Observaciones',
36
+ pomodoros: 'Pomodoros / Ciclos',
37
+ per_day: 'por día'
28
38
  }
39
+
29
40
  }.freeze
30
41
 
31
42
  def self.title
@@ -47,7 +58,7 @@ module WorkMd
47
58
  end
48
59
 
49
60
  def self.yaml_file
50
- YAML.load_file(DEFAULT_WORK_DIR + '/config.yml')
61
+ YAML.load_file("#{DEFAULT_WORK_DIR}/config.yml")
51
62
  rescue StandardError
52
63
  {}
53
64
  end
data/lib/work_md/file.rb CHANGED
@@ -5,22 +5,22 @@ require 'byebug'
5
5
  module WorkMd
6
6
  class File
7
7
  def self.open_or_create(some_date)
8
- open_in_editor(create_if_not_exist(some_date))
8
+ open_in_editor(file_names: [create_if_not_exist(some_date)])
9
9
  end
10
10
 
11
11
  def self.create_if_not_exist(some_date)
12
12
  t = WorkMd::Config.translations
13
13
  work_dir = WorkMd::Config.work_dir
14
14
 
15
- ::FileUtils
16
- .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
15
+ file_name = "#{some_date.strftime('%Y/%m/%d')}.md"
17
16
 
18
- filename = "#{some_date.strftime('%Y/%m/%d')}.md"
17
+ return file_name if ::File.exist?("#{work_dir}/#{file_name}")
19
18
 
20
- return filename if ::File.exist?("#{work_dir}/#{filename}")
19
+ ::FileUtils
20
+ .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
21
21
 
22
22
  ::File.open(
23
- "#{work_dir}/#{filename}",
23
+ "#{work_dir}/#{file_name}",
24
24
  'w+'
25
25
  ) do |f|
26
26
  # rubocop:disable Layout/LineLength
@@ -42,18 +42,19 @@ module WorkMd
42
42
  f.puts("0\n\n")
43
43
  end
44
44
 
45
- filename
45
+ file_name
46
46
  end
47
47
 
48
- def self.open_in_editor(filename1, filename2 = nil)
48
+ def self.open_in_editor(file_names: [], dir: nil)
49
49
  editor = WorkMd::Config.editor
50
+ work_dir = dir || WorkMd::Config.work_dir
50
51
 
51
- ::FileUtils.cd(WorkMd::Config.work_dir) do
52
+ ::FileUtils.cd(work_dir) do
52
53
  ENV['EDITOR'] = editor unless editor.nil?
53
54
 
54
- return ::TTY::Editor.open(filename1) if filename2.nil?
55
+ return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
55
56
 
56
- ::TTY::Editor.open(filename1, filename2)
57
+ ::TTY::Editor.open(file_names[0], file_names[1])
57
58
  end
58
59
  end
59
60
  end
@@ -94,7 +94,7 @@ module WorkMd
94
94
 
95
95
  @pomodoros_bars ||=
96
96
  @parsed_files.map do |f|
97
- "(#{f.date}) #{(1..f.pomodoros).map { '◘' }.join }"
97
+ "(#{f.date}) #{(1..f.pomodoros).map { '◘' }.join}"
98
98
  end
99
99
  end
100
100
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.9'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Fernandez Teixeira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-13 00:00:00.000000000 Z
11
+ date: 2021-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -51,6 +51,7 @@ files:
51
51
  - bin/work_md
52
52
  - lib/work_md.rb
53
53
  - lib/work_md/cli.rb
54
+ - lib/work_md/commands/config.rb
54
55
  - lib/work_md/commands/parse.rb
55
56
  - lib/work_md/commands/today.rb
56
57
  - lib/work_md/commands/tyesterday.rb