notenote 0.0.12 → 0.0.18

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: f4bfbe93ef96f0ef2b6b847ac331acd843aab4bec7c18ddcd93b40ab53d5f2d5
4
- data.tar.gz: 1824c7d21df7dffb7331964713aac63983fe43abc6065c9c8b6d04d959493116
3
+ metadata.gz: 2c1d8aaf090a602327ca4668ddf2302f8f44c0d9b8214b6b5ee5ef3e4708a4df
4
+ data.tar.gz: 430c780ce77443c2d35e59df835c700b4083ead5277cda6fd5e0a6b2835aeb5f
5
5
  SHA512:
6
- metadata.gz: c7896d0e5bc3cd154b079e6e966d6b4d898799202ddab1e19dfae517cb68a13a86241893fca7c5dd2f01dd3dc4ccfc06bcdfeaf79631a1e5a8cddcbfb6d37145
7
- data.tar.gz: 879d4ddb424ef4c6949c29894e3a171232129a016a277d71c737d650401a54906928b733386fcaf377e3ff5556bf950d06d220b3defcb872be42ebc482b7e14e
6
+ metadata.gz: 7d2813c76e15f4752700371fbbbc7d3d8ceb369f4591cacb541437c577f91d94df6dd43d50e8f65f7984df240bab6bafec268d41f40afaffc4aa8fc7b5dacf80
7
+ data.tar.gz: ab3916c6b9b49da5ac7861f6687eeba44528e46b523c1f965d53c58af031140ed25d8f17a8fce07905cb915a29014c74d8aa02fdc561db13927ed53ec227fb6c
data/lib/note/cli.rb CHANGED
@@ -3,15 +3,18 @@
3
3
  require "optparse"
4
4
  require "json"
5
5
  require "date"
6
+ require_relative "helpers"
6
7
 
7
8
  $LOAD_PATH << File.expand_path(__dir__)
8
9
 
9
10
  module Note
10
11
  class CLI
12
+ include Helpers
13
+
14
+ CONFIG_FILE_NAME = ".notenote"
15
+
11
16
  def run(args = [])
12
17
  if args.first == "init"
13
- require "fileutils"
14
-
15
18
  notes_folder = args[1]
16
19
 
17
20
  if notes_folder.nil?
@@ -26,13 +29,32 @@ module Note
26
29
  Dir.mkdir(notes_folder)
27
30
  end
28
31
 
32
+ vscode_config_folder = File.join(notes_folder, ".vscode")
33
+ unless Dir.exists?(vscode_config_folder)
34
+ Dir.mkdir(vscode_config_folder)
35
+ end
36
+
37
+ vscode_settings_file = File.join(vscode_config_folder, "settings.json")
38
+ if File.exist?(vscode_settings_file)
39
+ vscode_settings = JSON.parse(File.read(vscode_settings_file))
40
+
41
+ vscode_settings["markdown.editor.drop.enabled"] = false
42
+
43
+ File.open(vscode_settings_file, "w") do |f|
44
+ f.puts(JSON.pretty_generate(vscode_settings))
45
+ end
46
+ else
47
+ File.open(vscode_settings_file, "w") do |f|
48
+ f.puts(JSON.pretty_generate({ "markdown.editor.drop.enabled": false }))
49
+ end
50
+ end
51
+
29
52
  notes_folder_full_path = File.join(Dir.pwd, notes_folder)
30
53
 
31
54
  create_config_file(notes_folder: notes_folder_full_path)
32
55
  create_readme_file
33
56
  create_note_file
34
57
 
35
-
36
58
  puts %(Your note folder "#{notes_folder}" and the first log file are created. You're ready to go! 🚀)
37
59
 
38
60
  0
@@ -116,31 +138,33 @@ module Note
116
138
  end
117
139
 
118
140
  def create_config_file(notes_folder:)
141
+ config_file = File.join(Dir.home, CONFIG_FILE_NAME)
142
+
143
+ if File.exist?(config_file)
144
+ puts "📢 You already have a config file: ~/#{CONFIG_FILE_NAME}"
145
+ return
146
+ end
147
+
119
148
  config_template = File.read(File.join(File.dirname(__FILE__), "config.json.template"))
120
149
 
121
- config = safe_tt(config_template, {
150
+ config = hash_format(config_template, {
122
151
  notes_folder: notes_folder
123
152
  })
124
153
 
125
- config_file = File.join(Dir.home, ".notenote")
126
-
127
154
  File.open(config_file, "w") do |f|
128
155
  f.puts(config)
129
156
  end
130
157
  end
131
158
 
132
- def create_note_file(note_name: "#{notenote_config["default_note_file_name"]}.md")
159
+ def create_note_file(note_name: notenote_config["default_note_file_name"])
133
160
  notes_folder = notenote_config["notes_folder"]
134
161
 
135
162
  today_folder = File.join(notes_folder, formatted_todays_date)
136
163
 
137
164
  Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
138
165
 
139
- file_name = note_name.strip.downcase.
140
- gsub(/[^a-z0-9\-]+/, "_").
141
- gsub(/\A\_+/, "").
142
- gsub(/\_+\z/, "").
143
- concat(".md")
166
+ file_name = markdown_file_name(note_name: note_name)
167
+
144
168
  note_file = File.join(today_folder, file_name)
145
169
 
146
170
  if File.exist?(note_file)
@@ -148,7 +172,7 @@ module Note
148
172
  else
149
173
  File.open(note_file, "w") do |file|
150
174
  file.puts unindent <<-TEXT
151
- # #{note_name.capitalize}
175
+ # #{upcate_first(note_name)}
152
176
 
153
177
 
154
178
  TEXT
@@ -159,7 +183,7 @@ module Note
159
183
  end
160
184
 
161
185
  def notenote_config
162
- config_file = File.join(Dir.home, ".notenote")
186
+ config_file = File.join(Dir.home, CONFIG_FILE_NAME)
163
187
 
164
188
  JSON.parse(File.read(config_file))
165
189
  end
@@ -170,18 +194,6 @@ module Note
170
194
  system("#{editor_command} #{path}")
171
195
  end
172
196
 
173
- def mac?
174
- RbConfig::CONFIG["host_os"] =~ /darwin/
175
- end
176
-
177
- def osascript(script)
178
- system "osascript", *unindent(script).split(/\n/).map { |line| ['-e', line] }.flatten
179
- end
180
-
181
- def unindent(str)
182
- str.gsub(/^#{str.scan(/^[ \t]+(?=\S)/).min}/, "")
183
- end
184
-
185
197
  # This function parses the output of diffstat:
186
198
  #
187
199
  # git diff HEAD | diffstat -Cm
@@ -237,18 +249,6 @@ module Note
237
249
  system "git pull --ff-only"
238
250
  end
239
251
 
240
- # A custom string format method to avoid type
241
- # errors when using str % hash.
242
- def safe_tt(str, hash)
243
- str_copy = str
244
-
245
- hash.each do |key, value|
246
- str_copy.gsub!("%{#{key}}", value.to_s)
247
- end
248
-
249
- str_copy
250
- end
251
-
252
252
  def formatted_todays_date
253
253
  date_format = notenote_config["date_format"]
254
254
 
@@ -1,7 +1,8 @@
1
1
  {
2
+ "version": 1,
2
3
  "notes_folder": "%{notes_folder}",
3
4
  "date_format": "%d-%m-%Y",
4
- "default_note_file_name: "notes",
5
+ "default_note_file_name": "today",
5
6
  "editor_command": "code",
6
7
  "commit_message": "Added new notes"
7
8
  }
@@ -0,0 +1,59 @@
1
+ module Helpers
2
+ private
3
+
4
+ def markdown_file_name(note_name:)
5
+ note_name.strip.downcase.
6
+ gsub(/[^a-z0-9]+/, "_").
7
+ gsub(/\A\_+/, "").
8
+ gsub(/\_+\z/, "").
9
+ concat(".md")
10
+ end
11
+
12
+ def upcate_first(str)
13
+ return if str.nil?
14
+ return "" if str.empty?
15
+
16
+ str.dup.tap { |s| s[0] = s[0].upcase }
17
+ end
18
+
19
+ # A custom string format method to avoid type
20
+ # errors when using str % hash.
21
+ def hash_format(str, hash)
22
+ return if str.nil?
23
+
24
+ str_copy = str.dup
25
+
26
+ hash.each do |key, value|
27
+ str_copy.gsub!("%{#{key}}", value.to_s)
28
+ end
29
+
30
+ str_copy
31
+ end
32
+
33
+ def unindent(str)
34
+ return if str.nil?
35
+
36
+ str_copy = str.dup
37
+ lines = str_copy.split("\n")
38
+
39
+ first_char = str_copy[0]
40
+
41
+ while lines.all? { |l| l.start_with?(first_char) } &&
42
+ (first_char == " " || first_char == "\t")
43
+
44
+ lines.map! { |l| l[1..-1] }
45
+
46
+ first_char = lines.first[0]
47
+ end
48
+
49
+ return lines.join("\n")
50
+ end
51
+
52
+ def mac?
53
+ RbConfig::CONFIG["host_os"] =~ /darwin/
54
+ end
55
+
56
+ def osascript(script)
57
+ system "osascript", *unindent(script).split(/\n/).map { |line| ["-e", line] }.flatten
58
+ end
59
+ end
data/lib/note/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Note
2
- VERSION = "0.0.12".freeze
2
+ VERSION = "0.0.18".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notenote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-08 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: CLI tool to keep daily notes.
70
84
  email:
71
85
  - makaroni4@gmail.com
@@ -79,6 +93,7 @@ files:
79
93
  - lib/note.rb
80
94
  - lib/note/cli.rb
81
95
  - lib/note/config.json.template
96
+ - lib/note/helpers.rb
82
97
  - lib/note/version.rb
83
98
  homepage: https://github.com/makaroni4/note
84
99
  licenses: