Skip to content

Commit

Permalink
adding module exmaple
Browse files Browse the repository at this point in the history
  • Loading branch information
clpi committed Dec 3, 2024
1 parent b8a877e commit 91c310a
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 25 deletions.
56 changes: 56 additions & 0 deletions book/lua/module/example.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
local word = require("word")

local mod, config, util = word.mod, word.config, word.util

local M = mod.create("user.example", {
--- @brief submodules
--- child directories containing
--- modules to load in tandem, relative
--- to this (parent) module.
--- "subexample",
--- "pre_example",
--- ...
})

M.setup = function()
return {
requires = {
---@brief required modules
--- modules from builtin or custom
--- modules that can be loaded in (same as
--- if calling `require 'module'`) as a dependency
--- for the module.
--- "ui.popup",
--- "edit.link",
--- "integration.treesitter",
--- ...
},
loaded = true,
}
end

---@class (exact) example.Config
M.config.public = {
--- @brief module config
--- the public facing config for this module that can be
--- set by the user from its default values here.
--- ...
}

---@class example.Data
M.data = {
--- @brief module data
--- the home of the module's internal data and methods
--- TODO: split up concerns
--- ...
}

M.load = function()
--- @brief module load
--- a set of functions to run whenever the
--- module is fist loaded upon startup.
--- TODO: maybe just merge in with setup()
--- ...
end

return M
6 changes: 6 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ Welcome -- to the `word.lua` book. I hope this helps!
- [Keymaps](./extend/keymaps.md)
- [Autocmds](./extend/autocmd.md)

- [Modules](./modules.md)

- [Introduction](./modules/intro.md)

- [Customizing](./customizing.md)

- [Themes](./customizing/themes.md)
- [Highlights](./customizing/highlights.md)

- [Export](./export.md)

- [Frameworks](./publish/frameworks.md)
- [org](./export/org.md)

Expand All @@ -42,6 +47,7 @@ Welcome -- to the `word.lua` book. I hope this helps!
- [Digital garden](./publish/digital_garden.md)

- [Plans](./plans/index.md)

- [Near](./plans/near.md)
- [Far](./plans/far.md)

Expand Down
63 changes: 63 additions & 0 deletions book/src/modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Modules

## Example custom module

```lua
local word = require("word")

local mod, config, util = word.mod, word.config, word.util

local M = mod.create("user.example", {
--- @brief submodules
--- child directories containing
--- modules to load in tandem, relative
--- to this (parent) module.
--- "subexample",
--- "pre_example",
--- ...
})

M.setup = function()
return {
requires = {
---@brief required modules
--- modules from builtin or custom
--- modules that can be loaded in (same as
--- if calling `require 'module'`) as a dependency
--- for the module.
--- "ui.popup",
--- "edit.link",
--- "integration.treesitter",
--- ...
},
loaded = true,
}
end

---@class (exact) example.Config
M.config.public = {
--- @brief module config
--- the public facing config for this module that can be
--- set by the user from its default values here.
--- ...
}

---@class example.Data
M.data = {
--- @brief module data
--- the home of the module's internal data and methods
--- TODO: split up concerns
--- ...
}

M.load = function()
--- @brief module load
--- a set of functions to run whenever the
--- module is fist loaded upon startup.
--- TODO: maybe just merge in with setup()
--- ...
end

return M

```
Empty file added book/src/modules/intro.md
Empty file.
2 changes: 1 addition & 1 deletion lua/word/mod/edit/link/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ link from the word under the cursor or a visual selection (if there is one).
M.load = function()
mod.await("cmd", function(cmd)
cmd.add_commands_from_table({
preview = {
link = {
name = "link",
subcommands = {
update = {
Expand Down
24 changes: 0 additions & 24 deletions test/config/init.lua

This file was deleted.

0 comments on commit 91c310a

Please sign in to comment.