notenote 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/note/cli.rb +32 -6
- data/lib/note/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c7fc51bd06351a5ae925a67ac1aa684a2d15ffbc59edd798d3f302ef360b56e
|
4
|
+
data.tar.gz: 0e74c23606640b7eba1ad183720bfa2b847d52ee20ed49bbd47e60484377efac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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(
|
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
|
-
|
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