]> git.r.bdr.sh - rbdr/nota.nvim/blobdiff - lua/configuration.lua
Add rescheduling tasks
[rbdr/nota.nvim] / lua / configuration.lua
index 14e8591a87c88b1ca41d8a5cea53aad722210c12..f251eb9344b036e405b744cfb688e6e5dcf2182c 100644 (file)
@@ -1,3 +1,14 @@
+-------------------------------------------------------------------------------
+-- Configuration for nota
+-------------------------------------------------------------------------------
+local Configuration = {}
+
+local Util = require('util')
+-------------------------------------------------------------------------------
+-- Internal Functions
+-------------------------------------------------------------------------------
+local fs = vim.loop
+
 local defaults = {
   nota_home = '~/.local/share/nota',          -- Root location in which to store all notes
   default_keybinds = true,                    -- Whether or not to set the default keybinds
@@ -22,7 +33,7 @@ local defaults = {
   },
   learning  = {
       learning_file = 'learning.md',            -- Location of the file in which to store learning entries, relative to nota_home
-      prefix = '%Y-%x-%d: '                     -- Prefix to add when capturing learning entries
+      prefix = '%Y-%m-%d: '                     -- Prefix to add when capturing learning entries
   },
   plan = {
       archive = 'plans',                        -- Location of the plan archives.
@@ -33,7 +44,7 @@ local defaults = {
 -- Recursively extends a table with another
 local function extend(target, extender)
   for key, value in pairs(extender) do
-    if type(target[key]) == "table" and type(value) == "table" then
+    if type(target[key]) == 'table' and type(value) == 'table' then
       extend(target[key], value)
     else
       target[key] = value
@@ -41,6 +52,39 @@ local function extend(target, extender)
   end
 end
 
-function configure(user_configuration)
-  return extend(defaults, extender)
+-------------------------------------------------------------------------------
+-- Public Interface
+-------------------------------------------------------------------------------
+
+Configuration.configuration = {}
+extend(Configuration.configuration, defaults)
+
+--- Extends configuration with another configuration
+function Configuration.configure(configuration)
+  configuration = configuration or {}
+  extend(Configuration.configuration, configuration)
+end
+
+--- Gets expanded paths relative to nota_home
+-- @param path string the relative path to expand
+function Configuration.path_for(path)
+  if not path then
+    return vim.fn.expand(Configuration.configuration.nota_home)
+  end
+  return Util.join(vim.fn.expand(Configuration.configuration.nota_home), path)
+end
+
+--- Loads a template by template name
+function Configuration.load_template(type)
+  local template_path = Configuration.path_for(Configuration.configuration.templates[type])
+
+  local template_file = io.open(template_path, 'r')
+  if not template_file then
+      return ''
+  end
+  local content = template_file:read('*a')
+  template_file:close()
+  return content
 end
+
+return Configuration