notenote 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/note/cli.rb +32 -6
  3. data/lib/note/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f78d842dc42121cfc84e9610b0b7869b6c968f0dcaa4874dda75d618de9bfa81
4
- data.tar.gz: 7b2efa649831bb0ce998974cfab33879864486118fab60baaa4ea313f4bf0509
3
+ metadata.gz: 9c7fc51bd06351a5ae925a67ac1aa684a2d15ffbc59edd798d3f302ef360b56e
4
+ data.tar.gz: 0e74c23606640b7eba1ad183720bfa2b847d52ee20ed49bbd47e60484377efac
5
5
  SHA512:
6
- metadata.gz: 4e3962ada9564374f722f51ce976e99934c7d3bdda17a165f0c7f856a4b88d3ea53d588d4c0a916b77c8f20250cd01e2c75b06644e1ba3d3cdbe4c40118c878d
7
- data.tar.gz: 7937389c96e845c4f96e70dcc005ae272be582fe0068c83deff63fb773a713a215c4b196853c1e4c5cc0e40e282b5f3b47749a4c65ca4be6a6e4de8d0da97fef
6
+ metadata.gz: c36db2f227e1a29144e5fbffbad8f9dcc277f514b67829b1824998d001da3839f04333c8f62d34be33fd48d70ac19f24823924dbbc5d9adea52e3befa177e235
7
+ data.tar.gz: 46f4e35b88ff4558849bac03353147f65d7cb717b4d7c0e76a7dd57a17211cb96572c9f393deecf6cd3b5f193e2a8eb9bff1d054a2ca44223e999c06124cd7ac
data/lib/note/cli.rb CHANGED
@@ -37,9 +37,8 @@ module Note
37
37
  0
38
38
  elsif args.first == "on"
39
39
  note_name = args[1..-1].join(" ") # "tax return" for `note on tax return``
40
- file_name = note_name.gsub(/[^a-z0-9\-]+/, "_")
41
40
 
42
- create_note_file(file_name: "#{file_name}.md")
41
+ create_note_file(note_name: note_name)
43
42
 
44
43
  0
45
44
  elsif args.first == "all"
@@ -99,9 +98,9 @@ module Note
99
98
  def create_config_file(notes_folder:)
100
99
  config_template = File.read(File.join(File.dirname(__FILE__), "config.json.template"))
101
100
 
102
- config = config_template % {
101
+ config = safe_tt(config_template, {
103
102
  notes_folder: notes_folder
104
- }
103
+ })
105
104
 
106
105
  config_file = File.join(Dir.home, ".notenote")
107
106
 
@@ -110,7 +109,7 @@ module Note
110
109
  end
111
110
  end
112
111
 
113
- def create_note_file(file_name: "notes.md")
112
+ def create_note_file(note_name: "notes")
114
113
  notes_folder = notenote_config["notes_folder"]
115
114
  date_format = notenote_config["date_format"]
116
115
 
@@ -118,9 +117,24 @@ module Note
118
117
 
119
118
  Dir.mkdir(today_folder) unless Dir.exist?(today_folder)
120
119
 
120
+ file_name = note_name.strip.downcase.
121
+ gsub(/[^a-z0-9\-]+/, "_").
122
+ gsub(/\A\_+/, "").
123
+ gsub(/\_+\z/, "").
124
+ concat(".md")
121
125
  note_file = File.join(today_folder, file_name)
122
126
 
123
- FileUtils.touch(note_file)
127
+ if File.exist?(note_file)
128
+ puts "This note already exists. ⚠️"
129
+ else
130
+ File.open(note_file, "w") do |file|
131
+ file.puts unindent <<-TEXT
132
+ # #{note_name}
133
+
134
+
135
+ TEXT
136
+ end
137
+ end
124
138
 
125
139
  open_editor(path: note_file)
126
140
  end
@@ -197,5 +211,17 @@ module Note
197
211
 
198
212
  puts "Pushed. ✅"
199
213
  end
214
+
215
+ # A custom string format method to avoid type
216
+ # errors when using str % hash.
217
+ def safe_tt(str, hash)
218
+ str_copy = str
219
+
220
+ hash.each do |key, value|
221
+ str_copy.gsub!("%{#{key}}", value.to_s)
222
+ end
223
+
224
+ str_copy
225
+ end
200
226
  end
201
227
  end
data/lib/note/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Note
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.8".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notenote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich