template.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --- Template for module writers.
  2. -- Short description goes here.
  3. -- @module module_template
  4. --- (Required): Data table containing name and description of the module
  5. -- @field name "Human-readable name (parens OK, no brackets)"
  6. -- @field slug "Same as module class name"
  7. -- @field desc "Description of the module"
  8. -- @field hide Whether this is a hidden utility module
  9. local module_template = {
  10. name = "Module Human-Readable Name",
  11. slug = "module_template",
  12. desc = "Description of the module",
  13. hide = false;
  14. }
  15. --- (Required) Data for module
  16. -- Variables that module uses during the course of a process.
  17. -- Can be blank
  18. module_template.data = {
  19. }
  20. --- (Required): Config for module
  21. -- Defines the input parameters to the module initiate function.
  22. -- Can be blank
  23. -- When calling a module from within another module,
  24. -- variables not defined in config will be ignored.
  25. -- Default values set in config can be overridden
  26. -- @field approval_module names a module that must pass before approval; defaults to false
  27. -- @field field_1 ex: votes_required, default = 5
  28. -- @field field_2 ex: voting_type, default = "majority"
  29. module_template.config = {
  30. approval_module = false -- visible but empty
  31. hidden_config = nil -- not visible to users unless used
  32. field_1 = 5
  33. field_2 = "majority"
  34. }
  35. --- (Required): Initiate function
  36. -- Modules have access to the following instance variables:
  37. -- <li><code>self.org</code> (the org the module was called in),</li>
  38. -- <li><code>self.initiator</code> (the user that callced the module),</li>
  39. -- <li><code>self.id</code> (the process id of the module instance)</li>
  40. -- @function module_template:initiate
  41. -- @param result (optional) Callback if this module is embedded in other modules
  42. function module_template:initiate(result)
  43. -- call interaction functions here!
  44. -- concluding functions:
  45. -- first, where appropriate, return users to dashboards.
  46. -- second, result:
  47. -- may need to put result in self.data.result
  48. -- call this when module is successful (not for abort):
  49. if result then result() end
  50. -- third, delete the process
  51. -- call this wherever process might end:
  52. self.org:delete_process(self.id)
  53. end
  54. --- (Required) Add to module table
  55. modpol.modules.module_template = module_template