src/source/developer_guide/howto-skin.rst
branchdoc-dc
changeset 109 31b3d00edb8a
parent 104 942151432421
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/source/developer_guide/howto-skin.rst	Tue Dec 11 16:29:56 2018 +0100
@@ -0,0 +1,75 @@
+.. _skinhowto:
+
+
+How to create Skin?
+===================
+
+A Skin is a tagging interface for associating media, javascript and CSS resources to a **renderer**
+
+1) Configuring resource library
+-------------------------------
+
+
+.. code-block:: python
+
+    from fanstatic import Library, Resource
+    from pyams_default_theme import pyams_default_theme
+
+    #Library(name, folder_path)
+    library = Library('mycms', 'resources')
+
+    #Resource(library, path_to_static)
+    mycms_css = Resource(library, 'css/mystyle.css',)
+
+
+    mycms_js = Resource(library, 'js/pyams-default.js',
+                        depends=(pyams_default_theme, )
+                        bottom=True
+                        )
+
+
+:py:class:`Resource` can include others resources already defined with *depends* attribute, here `pyams_default_theme`.
+
+
+2) Create a new Layer to your skin
+----------------------------------
+
+Build a new interface inherit from `ICustomLayer`
+
+.. code-block:: python
+
+    class ICustomLayer(ICustomLayer):
+        """skin layer"""
+
+Define an utility providing ISkin with the custom label and the layer interface
+
+.. code-block:: python
+
+    @utility_config(name='Custom skin', provides=ISkin)
+    class CustomSkin(object):
+        """custom root skin"""
+
+        label = _("Custom: skin")
+        layer = ICustomLayer
+
+
+3) Declare the layer adapter
+----------------------------
+
+.. code-block:: python
+
+    @adapter_config(context=(Interface, ICustomLayer, Interface), provides=IResources)
+    class CustomSkinResourcesAdapter(ContextRequestViewAdapter):
+    """Custom skin resources adapter"""
+
+        def get_resources(self):
+            mycms.need()
+
+
+We have defined a Multiadapter with context=(context, request, view).
+
+.. note::
+
+    In the ZMI website you can now change the default graphical theme by you custom skin
+
+    .. image:: _static/select_skin.png