Skip to content

Commit 8b59db7

Browse files
benlubasvhyrro
authored andcommitted
feat: make journal methods public
1 parent 62671a7 commit 8b59db7

File tree

1 file changed

+53
-56
lines changed

1 file changed

+53
-56
lines changed

lua/neorg/modules/core/journal/module.lua

+53-56
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,47 @@ module.setup = function()
9797
}
9898
end
9999

100-
module.private = {
100+
module.config.public = {
101+
-- Which workspace to use for the journal files, the default behaviour
102+
-- is to use the current workspace.
103+
--
104+
-- It is recommended to set this to a static workspace, but the most optimal
105+
-- behaviour may vary from workflow to workflow.
106+
workspace = nil,
107+
108+
-- The name for the folder in which the journal files are put.
109+
journal_folder = "journal",
110+
111+
-- The strategy to use to create directories.
112+
-- May be "flat" (`2022-03-02.norg`), "nested" (`2022/03/02.norg`),
113+
-- a lua string with the format given to `os.date()` or a lua function
114+
-- that returns a lua string with the same format.
115+
strategy = "nested",
116+
117+
-- The name of the template file to use when running `:Neorg journal template`.
118+
template_name = "template.norg",
119+
120+
-- Whether to apply the template file to new journal entries.
121+
use_template = true,
122+
123+
-- Formatter function used to generate the toc file.
124+
-- Receives a table that contains tables like { yy, mm, dd, link, title }.
125+
--
126+
-- The function must return a table of strings.
127+
toc_format = nil,
128+
}
129+
130+
module.config.private = {
131+
strategies = {
132+
flat = "%Y-%m-%d.norg",
133+
nested = "%Y" .. config.pathsep .. "%m" .. config.pathsep .. "%d.norg",
134+
},
135+
}
136+
137+
---@class core.journal
138+
module.public = {
139+
version = "0.0.9",
140+
101141
--- Opens a diary entry at the given time
102142
---@param time? number #The time to open the journal entry at as returned by `os.time()`
103143
---@param custom_date? string #A YYYY-mm-dd string that specifies a date to open the diary at instead
@@ -148,20 +188,19 @@ module.private = {
148188

149189
--- Opens a diary entry for tomorrow's date
150190
diary_tomorrow = function()
151-
module.private.open_diary(os.time() + 24 * 60 * 60)
191+
module.public.open_diary(os.time() + 24 * 60 * 60)
152192
end,
153193

154194
--- Opens a diary entry for yesterday's date
155195
diary_yesterday = function()
156-
module.private.open_diary(os.time() - 24 * 60 * 60)
196+
module.public.open_diary(os.time() - 24 * 60 * 60)
157197
end,
158198

159199
--- Opens a diary entry for today's date
160200
diary_today = function()
161-
module.private.open_diary()
201+
module.public.open_diary()
162202
end,
163203

164-
--- Creates a template file
165204
create_template = function()
166205
local workspace = module.config.public.workspace
167206
local folder_name = module.config.public.journal_folder
@@ -183,7 +222,7 @@ module.private = {
183222
if module.required["core.dirman"].file_exists(folder_name .. config.pathsep .. index) then
184223
module.required["core.dirman"].open_file(workspace, folder_name .. config.pathsep .. index)
185224
else
186-
module.private.create_toc()
225+
module.public.create_toc()
187226
end
188227
end,
189228

@@ -377,48 +416,6 @@ module.private = {
377416
end,
378417
}
379418

380-
module.config.public = {
381-
-- Which workspace to use for the journal files, the default behaviour
382-
-- is to use the current workspace.
383-
--
384-
-- It is recommended to set this to a static workspace, but the most optimal
385-
-- behaviour may vary from workflow to workflow.
386-
workspace = nil,
387-
388-
-- The name for the folder in which the journal files are put.
389-
journal_folder = "journal",
390-
391-
-- The strategy to use to create directories.
392-
-- May be "flat" (`2022-03-02.norg`), "nested" (`2022/03/02.norg`),
393-
-- a lua string with the format given to `os.date()` or a lua function
394-
-- that returns a lua string with the same format.
395-
strategy = "nested",
396-
397-
-- The name of the template file to use when running `:Neorg journal template`.
398-
template_name = "template.norg",
399-
400-
-- Whether to apply the template file to new journal entries.
401-
use_template = true,
402-
403-
-- Formatter function used to generate the toc file.
404-
-- Receives a table that contains tables like { yy, mm, dd, link, title }.
405-
--
406-
-- The function must return a table of strings.
407-
toc_format = nil,
408-
}
409-
410-
module.config.private = {
411-
strategies = {
412-
flat = "%Y-%m-%d.norg",
413-
nested = "%Y" .. config.pathsep .. "%m" .. config.pathsep .. "%d.norg",
414-
},
415-
}
416-
417-
---@class core.journal
418-
module.public = {
419-
version = "0.0.9",
420-
}
421-
422419
module.load = function()
423420
if module.config.private.strategies[module.config.public.strategy] then
424421
module.config.public.strategy = module.config.private.strategies[module.config.public.strategy]
@@ -452,9 +449,9 @@ end
452449
module.on_event = function(event)
453450
if event.split_type[1] == "core.neorgcmd" then
454451
if event.split_type[2] == "journal.tomorrow" then
455-
module.private.diary_tomorrow()
452+
module.public.diary_tomorrow()
456453
elseif event.split_type[2] == "journal.yesterday" then
457-
module.private.diary_yesterday()
454+
module.public.diary_yesterday()
458455
elseif event.split_type[2] == "journal.custom" then
459456
if not event.content[1] then
460457
local calendar = modules.get_module("core.ui.calendar")
@@ -466,7 +463,7 @@ module.on_event = function(event)
466463

467464
calendar.select_date({
468465
callback = vim.schedule_wrap(function(osdate)
469-
module.private.open_diary(
466+
module.public.open_diary(
470467
nil,
471468
string.format("%04d", osdate.year)
472469
.. "-"
@@ -477,16 +474,16 @@ module.on_event = function(event)
477474
end),
478475
})
479476
else
480-
module.private.open_diary(nil, event.content[1])
477+
module.public.open_diary(nil, event.content[1])
481478
end
482479
elseif event.split_type[2] == "journal.today" then
483-
module.private.diary_today()
480+
module.public.diary_today()
484481
elseif event.split_type[2] == "journal.template" then
485-
module.private.create_template()
482+
module.public.create_template()
486483
elseif event.split_type[2] == "journal.toc.open" then
487-
module.private.open_toc()
484+
module.public.open_toc()
488485
elseif event.split_type[2] == "journal.toc.update" then
489-
module.private.create_toc()
486+
module.public.create_toc()
490487
end
491488
end
492489
end

0 commit comments

Comments
 (0)