template.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 field_1 ex: votes_required, default = 5
  27. -- @field field_2 ex: voting_type, default = "majority"
  28. module_template.config = {
  29. field_1 = 5
  30. field_2 = "majority"
  31. }
  32. --- (Required): Initiate function
  33. -- Modules have access to the following instance variables:
  34. -- <li><code>self.org</code> (the org the module was called in),</li>
  35. -- <li><code>self.initiator</code> (the user that callced the module),</li>
  36. -- <li><code>self.id</code> (the process id of the module instance)</li>
  37. -- @function module_template:initiate
  38. -- @param result (optional) Callback if this module is embedded in other modules
  39. function module_template:initiate(result)
  40. -- call interaction functions here!
  41. -- concluding functions:
  42. -- first, where appropriate, return users to dashboards.
  43. -- second, result:
  44. -- may need to put result in self.data.result
  45. -- call this when module is successful (not for abort):
  46. if result then result() end
  47. -- third, delete the process
  48. -- call this wherever process might end:
  49. self.org:delete_process(self.id)
  50. end
  51. --- (Required) Add to module table
  52. modpol.modules.module_template = module_template