doc: Add section :h neogen-template-api
This commit is contained in:
@@ -169,7 +169,7 @@ local c_config = {
|
|||||||
granulator = nil,
|
granulator = nil,
|
||||||
generator = nil,
|
generator = nil,
|
||||||
|
|
||||||
template = template:add_default_template("doxygen"),
|
template = template:add_default_annotation("doxygen"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return c_config
|
return c_config
|
||||||
|
|||||||
@@ -116,5 +116,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
template = template:add_default_template("doxygen"):add_template("xmldoc"),
|
template = template:add_default_annotation("doxygen"):add_annotation("xmldoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = template:config({ use_default_comment = true }):add_default_template("godoc"),
|
template = template:config({ use_default_comment = true }):add_default_annotation("godoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,5 +113,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = template:add_default_template("javadoc"),
|
template = template:add_default_annotation("javadoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,5 +112,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = template:add_default_template("jsdoc"),
|
template = template:add_default_annotation("jsdoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,5 +149,5 @@ return {
|
|||||||
granulator = nil,
|
granulator = nil,
|
||||||
generator = nil,
|
generator = nil,
|
||||||
|
|
||||||
template = template:config({ use_default_comment = true }):add_default_template("emmylua"):add_template("ldoc"),
|
template = template:config({ use_default_comment = true }):add_default_annotation("emmylua"):add_annotation("ldoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,5 +78,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
template = template:add_default_template("phpdoc"),
|
template = template:add_default_annotation("phpdoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ return {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:add_default_template("google_docstrings")
|
:add_default_annotation("google_docstrings")
|
||||||
:add_template("numpydoc")
|
:add_annotation("numpydoc")
|
||||||
:add_template("reST"),
|
:add_annotation("reST"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,6 @@ return {
|
|||||||
|
|
||||||
template = template
|
template = template
|
||||||
:config({ use_default_comment = true })
|
:config({ use_default_comment = true })
|
||||||
:add_template("rustdoc")
|
:add_annotation("rustdoc")
|
||||||
:add_default_template("rust_alternative"),
|
:add_default_annotation("rust_alternative"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,5 +134,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = template:add_default_template("jsdoc"),
|
template = template:add_default_annotation("jsdoc"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,20 @@
|
|||||||
--- as well as providing custom configurations in order to be precise about
|
--- as well as providing custom configurations in order to be precise about
|
||||||
--- how to customize the annotations.
|
--- how to customize the annotations.
|
||||||
---
|
---
|
||||||
|
--- We exposed some API to help you customize a template, and add your own custom annotations
|
||||||
|
--- For this, please go to |neogen.template_api|
|
||||||
|
---
|
||||||
---@type neogen.TemplateConfig
|
---@type neogen.TemplateConfig
|
||||||
---
|
---
|
||||||
--- Default values:
|
--- Default values:
|
||||||
---@tag neogen.template_configuration
|
---@tag neogen-template-configuration
|
||||||
---@toc_entry Customize templates for a language
|
---@signature
|
||||||
|
---@toc_entry Configurations for the template table
|
||||||
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
|
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
|
||||||
local template_configuration = {
|
local neogen_template = {
|
||||||
annotation_convention = nil,
|
annotation_convention = nil,
|
||||||
use_default_comment = false,
|
use_default_comment = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- # neogen.TemplateConfig~
|
--- # neogen.TemplateConfig~
|
||||||
---
|
---
|
||||||
---@class neogen.TemplateConfig see |template_config|
|
---@class neogen.TemplateConfig see |template_config|
|
||||||
@@ -63,14 +66,38 @@ local template_configuration = {
|
|||||||
--- <
|
--- <
|
||||||
-- TODO: Add section to tell about annotation convention
|
-- TODO: Add section to tell about annotation convention
|
||||||
|
|
||||||
---Update template configuration
|
--- # Templates API~
|
||||||
---@param tbl neogen.TemplateConfig
|
---
|
||||||
template_configuration.config = function(self, tbl)
|
--- Welcome to the neogen API section for templates.
|
||||||
|
---
|
||||||
|
--- A template is an entity relative to a filetype that holds configurations for how to place
|
||||||
|
--- annotations.
|
||||||
|
--- With it, you can add an annotation convention to a filetype, change defaults,
|
||||||
|
--- and even provide your own annotation convention !
|
||||||
|
--- I exposed some API's, available after you get a template.
|
||||||
|
--- Please see |neogen.get_template()| for how to get a template.
|
||||||
|
---
|
||||||
|
--- Example:
|
||||||
|
--- >
|
||||||
|
--- neogen.get_template("python"):config({ annotation_convention = ... })
|
||||||
|
--- <
|
||||||
|
---@tag neogen-template-api
|
||||||
|
---@toc_entry API to customize templates
|
||||||
|
|
||||||
|
--- Updates a template configuration
|
||||||
|
---@signature <template_obj>:config(tbl)
|
||||||
|
---@param tbl neogen.TemplateConfig Override the template with provided config
|
||||||
|
---@tag neogen-template-api.config()
|
||||||
|
neogen_template.config = function(self, tbl)
|
||||||
self = vim.tbl_extend("force", self, tbl)
|
self = vim.tbl_extend("force", self, tbl)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
template_configuration.add_template = function(self, name)
|
--- Add an annotation convention to the template
|
||||||
|
---@signature <template_obj>:add_annotation(name)
|
||||||
|
---@param name string The name of the annotation convention
|
||||||
|
---@tag neogen-template-api.add_annotation()
|
||||||
|
neogen_template.add_annotation = function(self, name)
|
||||||
local ok, _t = pcall(require, "neogen.templates." .. name)
|
local ok, _t = pcall(require, "neogen.templates." .. name)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
@@ -81,10 +108,16 @@ template_configuration.add_template = function(self, name)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
template_configuration.add_default_template = function(self, name)
|
--- Add an annotation convention to the template and make it the default
|
||||||
|
---@signature <template_obj>:add_default_annotation(name)
|
||||||
|
---@param name string The name of the annotation convention
|
||||||
|
---@tag neogen-template-api.add_default_annotation()
|
||||||
|
neogen_template.add_default_annotation = function(self, name)
|
||||||
self.annotation_convention = name
|
self.annotation_convention = name
|
||||||
self = self:add_template(name)
|
self = self:add_annotation(name)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
return template_configuration
|
-- TODO: add API to create your own annotation convention
|
||||||
|
|
||||||
|
return neogen_template
|
||||||
|
|||||||
Reference in New Issue
Block a user