template.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --- module_template
  2. -- @module module_template
  3. --- (Required): data table containing name and description of the module
  4. -- @field name "Human-readable name"
  5. -- @field slug "Same as module class name"
  6. -- @field desc "Description of the module"
  7. -- @field hide "Whether this is a hidden utility module"
  8. local module_template = {
  9. name = "Module Human-Readable Name",
  10. slug = "template",
  11. desc = "Description of the module",
  12. hide = false;
  13. }
  14. --- (Required) Data for module
  15. -- Variables that module uses during the course of a process
  16. -- Can be blank
  17. module_template.data = {
  18. }
  19. --- (Required): config for module
  20. -- Defines the input parameters to the module initiate function.
  21. -- Can be blank
  22. -- When calling a module from within another module,
  23. -- variables not defined in config will be ignored.
  24. -- Default values set in config can be overridden
  25. -- @field field_1 ex: votes_required, default = 5
  26. -- @field field_2 ex: voting_type, default = "majority"
  27. module_template.config = {
  28. field_1 = 5
  29. field_2 = "majority"
  30. }
  31. --- (Required): initiate function
  32. -- Modules have access to the following instance variables:
  33. -- <li><code>self.org</code> (the org the module was called in),</li>
  34. -- <li><code>self.initiator</code> (the user that callced the module),</li>
  35. -- <li><code>self.id</code> (the process id of the module instance)</li>
  36. -- @param result (optional) Callback if this module is embedded in other modules
  37. -- @function initiate
  38. function module_template:initiate(result)
  39. -- call interaction functions here!
  40. -- concluding functions:
  41. -- call these wherever process might end;
  42. -- may need to put result in self.data.result
  43. -- if process ends in another function
  44. if result then result() end
  45. self.org:delete_process(self.id)
  46. end
  47. --- (Required) Add to module table
  48. modpol.modules.module_template = module_template