<commit_before>Creating plugins to rearrange things after a successfull templates generation
-------------------------------------------------------------------------------



A plugin is a simple adapter
++++++++++++++++++++++++++++

Creating plugins to run after a generation is really simple.
It is just a matter of implementing an adapter which takes an ``\IPasterConfiguration`` and provided ``IPostGenerationPlugin``.
::

    <adapter
      name="plugin name"
      provides=".interfaces.IPostGenerationPlugin"
      factory=".plugins.MyPluginFactory"
      for=".interfaces.IPasterAssembly"
    />

The eggs plugin
+++++++++++++++++

For example, here is a simple plugin which take all eggs in a 'src' directory and register them in 'zcml' and 'develop' in the relative ''buildout.cfg''
It will add just the 'policy' egg to the intance's zcml option.


Boiler plate to simulate a generation

    >>> import tempfile, shutil, os
    >>> c = os.getcwd()
    >>> d = tempfile.mkdtemp()
    >>> os.chdir(d)
    >>> open('buildout.cfg', 'w').write('[buildout]\ndevelop+=\n   foo\n[instance]\nzcml=  too\n')
    >>> os.makedirs('src/bar/src')
    >>> os.makedirs('src/policy/src')
    >>> open('src/bar/setup.py', 'w').write('')
    >>> open('src/policy/setup.py', 'w').write('')

Running the plugin

    >>> from collective.generic.webbuilder.models import root
    >>> conf = root.configurations['Generic Portal Plone3']
    >>> from collective.generic.webbuilder import interfaces, paster
    >>> pa = paster.PasterAssembly('Generic Portal Plone3')
    >>> plugin = zope.component.queryAdapter(pa, interfaces.IPostGenerationPlugin, name='egg_plugin')
    >>> plugin.process(d, 'foo', {})
    >>> print open('buildout.cfg').read()
    [buildout]
    develop+=src/bar
       src/policy
       foo
    eggs += bar
            policy
    [instance]
    zcml=  policy
            too
    <BLANKLINE>

Cleanup

    >>> os.chdir(c);shutil.rmtree(d)


Registering plugins
+++++++++++++++++++++
Please refer to the *plugin* zcml directive to know how to add plugins for a 'Configuration'.

Here is an example about the "eggs_plugins"
::

    <configure xmlns="http://namespaces.repoze.org/bfg"
        xmlns:meta="http://namespaces.zope.org/meta"
        xmlns:cgwb=xmlns="http://webbuilder.org/webbuilder">
        <adapter
            name="egg_plugin"
            provides=".interfaces.IPostGenerationPlugin"
            factory=".plugins.EggPlugin"
            for=".interfaces.IPasterAssembly"
        />
        <cgwb:genericpaster name="Generic Portal Plone">
            <cgwb:plugin name="egg_plugin" order="2"/>
            <cgwb:template name="minitage.plone3" order="1">
            </template><commit_msg>fixTests<commit_after>Creating plugins to rearrange things after a successfull templates generation
-------------------------------------------------------------------------------



A plugin is a simple adapter
++++++++++++++++++++++++++++

Creating plugins to run after a generation is really simple.
It is just a matter of implementing an adapter which takes an ``\IPasterConfiguration`` and provided ``IPostGenerationPlugin``.
::

    <adapter
      name="plugin name"
      provides=".interfaces.IPostGenerationPlugin"
      factory=".plugins.MyPluginFactory"
      for=".interfaces.IPasterAssembly"
    />

The eggs plugin
+++++++++++++++++

For example, here is a simple plugin which take all eggs in a 'src' directory and register them in 'zcml' and 'develop' in the relative ''buildout.cfg''
It will add just the 'policy' egg to the intance's zcml option.


Boiler plate to simulate a generation

    >>> import tempfile, shutil, os
    >>> c = os.getcwd()
    >>> d = tempfile.mkdtemp()
    >>> os.chdir(d)
    >>> open('buildout.cfg', 'w').write('[buildout]\ndevelop+=\n   foo\n[instance]\nzcml=  too\n')
    >>> os.makedirs('src/bar/src')
    >>> os.makedirs('src/policy/src')
    >>> open('src/bar/setup.py', 'w').write('')
    >>> open('src/policy/setup.py', 'w').write('')

Running the plugin

    >>> from collective.generic.webbuilder.models import root
    >>> conf = root.configurations['Generic Portal Plone3']
    >>> from collective.generic.webbuilder import interfaces, paster
    >>> pa = paster.PasterAssembly('Generic Portal Plone3')
    >>> plugin = zope.component.queryAdapter(pa, interfaces.IPostGenerationPlugin, name='egg_plugin')
    >>> plugin.process(d, 'foo', {})
    >>> print open('buildout.cfg').read()
    [buildout]
    develop+=src/policy
       src/bar
       foo
    eggs += policy
            bar
    [instance]
    zcml=  too  
                policy
    <BLANKLINE>

Cleanup

    >>> os.chdir(c);shutil.rmtree(d)


Registering plugins
+++++++++++++++++++++
Please refer to the *plugin* zcml directive to know how to add plugins for a 'Configuration'.

Here is an example about the "eggs_plugins"
::

    <configure xmlns="http://namespaces.repoze.org/bfg"
        xmlns:meta="http://namespaces.zope.org/meta"
        xmlns:cgwb=xmlns="http://webbuilder.org/webbuilder">
        <adapter
            name="egg_plugin"
            provides=".interfaces.IPostGenerationPlugin"
            factory=".plugins.EggPlugin"
            for=".interfaces.IPasterAssembly"
        />
        <cgwb:genericpaster name="Generic Portal Plone">
            <cgwb:plugin name="egg_plugin" order="2"/>
            <cgwb:template name="minitage.plone3" order="1">
            </template>
{'fraction_non_alphanumeric': 0.1794730053436521, 'fraction_numerical': 0.0018426386585590566, 'mean_word_length': 2.852377572746629, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6611068', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1555, 'n_words': 401}