Commit Graph

10 Commits

Author SHA1 Message Date
FUJIWARA Katsunori
7a6d96d902 registrar: add templatefunc to mark a function as template function (API)
This patch also adds loadfunction() to templater, because this
combination helps to figure out how they cooperate with each other.

Listing up loadfunction() in dispatch.extraloaders causes implicit
loading template function at loading (3rd party) extension.

This patch explicitly tests whether templatefunc decorator works as
expected, because there is no bundled extension, which defines
template function.

This change requires that "templatefunc" attribute of (3rd party)
extension is registrar.templatefunc or so.
2016-03-30 02:10:44 +09:00
FUJIWARA Katsunori
098aa2f5a6 registrar: add templatefilter to mark a function as template filter (API)
This patch also adds loadfilter() to templatefilters, because this
combination helps to figure out how they cooperate with each other.

Listing up loadfilter() in dispatch.extraloaders causes implicit
loading template filter functions at loading (3rd party) extension.

This change requires that "templatefilter" attribute of (3rd party)
extension is registrar.templatefilter or so.
2016-03-30 02:10:44 +09:00
FUJIWARA Katsunori
adbb470b46 registrar: add templatekeyword to mark a function as template keyword (API)
_templateregistrarbase is defined as a super class of templatekeyword,
for ease of adding template common features between "keyword",
"filter" and "function".

This patch also adds loadkeyword() to templatekw, because this
combination helps to figure out how they cooperate with each other.

Listing up loadkeyword() in dispatch.extraloaders causes implicit
loading template keyword functions at loading (3rd party) extension.

This change requires that "templatekeyword" attribute of (3rd party)
extension is registrar.templatekeyword or so.
2016-03-13 05:17:06 +09:00
FUJIWARA Katsunori
f997d054b1 registrar: add filesetpredicate to mark a function as fileset predicate
filesetpredicate is used to replace fileset.predicate in subsequent
patch.

This patch also adds loadpredicate() to fileset, because this
combination helps to figure out how the name of "status caller" (or
"existing caller") predicate is put into _statuscallers (or
_existingcallers).

Listing up loadpredicate() in dispatch.extraloaders causes implicit
loading fileset predicate functions at loading (3rd party) extension.
2016-03-11 04:14:54 +09:00
FUJIWARA Katsunori
e8fc6a5935 registrar: remove useless base classes (API)
Previous patches make these classes useless by removing classes
derived from them.
2016-03-11 04:14:54 +09:00
FUJIWARA Katsunori
8227e106c7 registrar: define revsetpredicate to decorate revset predicate
revsetpredicate is used to replace revset.predicate and
revset.extpredicate in subsequent patches.

This patch also adds loadpredicate() to revset, because this
combination helps to figure out how the name of safe predicate is put
into safesymbols.

This patch still uses safesymbols set to examine whether the predicate
corresponded to the 'name' is safe from DoS attack or not, because
just setting func._safe property needs changes below for such
examination.

  before:
      name in revset.safesymbols

  after:
      getattr(revset.symbols.get(name, None), '_safe', False)

"automatic registration" described in help doc of revsetpredicate
class will be achieved by the subsequent patch, which lists
loadpredicate() up in dispatch.extraloaders.
2016-03-08 23:04:53 +09:00
FUJIWARA Katsunori
e72a9be81f registrar: introduce new class for registration to replace funcregistrar
_funcregistrarbase differs from funcregistrar in points below:

  - every code paths should use same class derived from
    _funcregistrarbase to register functions in a same category

    funcregistrar expects (3rd party) extensions to use (a class
    derived from) delayregistrar.

  - actual extra setup should be executed in another function

    For example, marking revset predicate as "safe" is executed in a
    class derived from _funcregistrarbase, but putting name of "safe"
    predicate into safesymbols is executed in another function for it.

    funcregistrar expects derived classes to do so.

New class is named as module private one, because code paths, which
register functions, should use not it directly but one derived from
it.
2016-03-08 23:04:53 +09:00
FUJIWARA Katsunori
7a45cbf23f registrar: add delayregistrar class to register function in extensions
'delayregistrar' delays actual registration of function until
'setup()' invocation on it.
2015-12-29 23:58:30 +09:00
FUJIWARA Katsunori
3a36e78620 revset: use decorator to register a function as revset predicate
Using decorator can localize changes for adding (or removing) a revset
predicate function in source code.

It is also useful to pick predicates up for specific purpose. For
example, subsequent patch marks predicates as "safe" by decorator.

This patch defines 'parsefuncdecl()' in 'funcregistrar' class, because
this implementation can be uesd by other decorator class for fileset
predicate and template function.
2015-12-29 23:58:30 +09:00
FUJIWARA Katsunori
3b76ba51d4 registrar: add funcregistrar class to register function for specific purpose
This class centralizes the common logic to register function for
specific purpose like below:

    - template keyword, filter and function
    - revset predicate
    - fileset predicate
    - webcommand

'funcregistrar' also formats help document of the function with the
'decl'(aration) specified at the construction.

This can avoid (1) redundancy between 'decl' and help document, and
(2) accidental typo of help document. For example, 'foo' should appear
twice like below, if without such formatting:

    @keyword('foo')
    def foo(....):
        """:foo: Explanation of keyword foo ..."""

Almost all cases needs very simple document formatting like below:

    - "``DECL``\n    EXPLANATION"
    - ":DECL: EXPLANATION"

But webcommand needs a little complicated formatting like:

    /PATH/SPEC
    ----------

    EXPLANATION ....

To make minirst recognize the section header, hyphen line should be as
long as "/PATH/SPEC". It should be arranged by program.

Implementing 'formatdoc()' in derived class can support complicated
formatting in the latter case. But it seems redundant for simple one
in the former case.

Therefore, 'funcregistrar' does:

    - invoke 'self.formatdoc', if it is callable (for the latter case)
    - use it as the format string, otherwise (for the former case)
2015-12-29 23:58:30 +09:00