{
"info": {
"author": "keul",
"author_email": "luca@keul.it",
"bugtrack_url": null,
"classifiers": [
"Framework :: Plone",
"Framework :: Plone :: 4.2",
"Framework :: Plone :: 4.3",
"Intended Audience :: Developers",
"Programming Language :: Python"
],
"description": ".. contents:: **Table of contents**\n\nIntroduction\n============\n\nThis product is targeted to developer who need to distribute JavaScript configuration data or\ni18n strings with their Plone products.\n\nData injected in the page could be taken from whatever server side configuration setting you want\nbut most of the time you want to read application configuration from the Plone registry and translations\nfrom page templates.\n\nHow it works\n============\n\nA new viewlet will be registered in the HTML head of the site. This viewlet is normally empty and will\ndo nothing until a 3rd party product will register new ``IJSDataProvider`` adapters.\n\nThere are three subtypes of adapters, choosing one of them depends on what you want to reach in your\nadd-on.\n\nRegistering *named adapters* is recommended, in that way override the registration with a more\nspecific ones will be possible.\nIn the case of ``IJSObjectDataProvider`` the name is required because it's used as name of the defined\nvariable (see below).\n\nIJSONDataProvider\n-----------------\n\nUse it when you want to add new JavaScript data in the form of a JSON *template*.\n\nThe adapter must be a callable object that return a string that could be threat as a JSON\nstring. It will be added to the page in a ``script`` of type \"text/collective.jsconfiguration.json\".\n\nFor example:\n\n.. code-block:: xml\n\n \n\nIt's not a duty of this package telling you how to read the data, but for example you could do something\nlike this:\n\n.. code-block:: javascript\n\n var configuration = $.parseJSON($('#your_adapter_name_if_any').text());\n\nIDOMDataProvider\n----------------\n\nUse it when you want to add new JavaScript data in the form of XML nodes.\n\nThe adapter must be a callable object that return something you want to be put inside the page.\nIt will be added to the page in a ``script`` of type \"text/collective.jsconfiguration.xml\".\n\nAn example:\n\n.. code-block:: xml\n\n \n\nAlthough there's no real limitation in using this provider, it has been designed for injecting\nXML sub-DOM.\nIf the callable use a template to render it's content you can use a browser view.\nThis can be *really* useful for internationalization of your JavaScript interface (because\nyou can then rely on Zope i18n support and tools like `i18ndude`__).\n\n__ http://pypi.python.org/pypi/i18ndude\n\nReading the translation string from JavaScript will be really simple:\n\n.. code-block:: javascript\n\n var label1 = $($('#your_adapter_name_if_any').text()).attr('data-i18n-label1');\n var label2 = $($('#your_adapter_name_if_any').text()).attr('data-i18n-label2');\n\nIJSObjectDataProvider\n---------------------\n\nUse it when you want to add new JavaScript data in the form of a plain JavaScript object\nassigned to a variable. For this reason the data will be used in a standard ``script``\ntag.\n\nThis is very similar to the ``IJSONDataProvider`` above (the callable must return a valid JSON string)\nbut with some important differences:\n\n* a name for the adapter is required\n* the name of the adapter will be used as variable name to which the data will be assigned\n\nIf the name will be dotted, a nested JavaScript objects structure will be created.\n\nAn example for an adapter called \"``foo.bar``\":\n\n.. code-block:: html\n\n \n\nWhile the use of ``IJSONDataProvider`` will not include new JavaScript data in the JavaScript global\nnamespace but leave to developer the access to the new data, using ``IJSObjectDataProvider`` you are\ndirectly adding new data to the JavaScript environment:\n\n.. code-block:: javascript\n\n alert(foo.bar.baz); // whil be \"Hello World\"\n\nRegistering a new configuration\n===============================\n\nWhatever is your choice, you simply need to register an adapter that adapts the **current context**,\nthe **request** and the **current view**.\n\nAn example:\n\n.. code-block:: xml\n\n \n\nIn the example above the configuration will be added to every page of the site.\n\n.. code-block:: xml\n\n \n\nIn the last example another configuration will only added to the site root, only when a 3rd party browser\nlayers is registered (commonly: your add-on product is installed) and only when a specific view is called.\n\nAs far as the adapter registration is using the same name of the first example, the last registration will\noverride the first when applicable.\n\nFinally, there's the adapter class:\n\n.. code-block:: python\n\n class YourXMLAdapter(object):\n implements(IDOMDataProvider)\n \n def __init__(self, context, request, view):\n self.context = context\n self.request = request\n self.view = view\n \n def __call__(self):\n ...\n\nWhen using ``IJSONDataProvider`` or ``IJSObjectDataProvider`` and you want to directly read data from the\nPlone registry, you can rely on `collective.regjsonify`__ package, that can quickly help you in this task:\n\n.. code-block:: python\n\n from collective.regjsonify.interfaces import IJSONifier\n from collective.jsconfiguration.interfaces import IJSONDataProvider\n from plone.registry.interfaces import IRegistry\n from zope.interface import implements\n\n class YourXMLAdapter(object):\n implements(IJSONDataProvider)\n \n def __init__(self, context, request, view):\n self.context = context\n self.request = request\n self.view = view\n \n def __call__(self):\n registry = queryUtility(IRegistry)\n settings = registry.forInterface(IMyRegistrySettings)\n return IJSONifier(settings).json()\n\n__ http://github.com/keul/collective.regjsonify\n\nExample application\n===================\n\nYou can find all those features in action in the `collective.externalizelink`__ Plone add-on.\n\n__ https://github.com/keul/collective.externalizelink\n\nChangelog\n=========\n\n0.1.1 (2015-08-25)\n------------------\n\n- ``IJSONDataProvider`` was masking HTML like output \n [keul]\n- Tests were broken\n [keul]\n\n0.1.0 (2014-05-02)\n------------------\n\n- Initial release",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/keul/collective.jsconfiguration",
"keywords": "plone javascript configuration i18n",
"license": "GPL",
"maintainer": null,
"maintainer_email": null,
"name": "collective.jsconfiguration",
"package_url": "https://pypi.org/project/collective.jsconfiguration/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/collective.jsconfiguration/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/keul/collective.jsconfiguration"
},
"release_url": "https://pypi.org/project/collective.jsconfiguration/0.1.1/",
"requires_dist": null,
"requires_python": null,
"summary": "General approach for adding JavaScript configuration (and i18n data) to Plone products",
"version": "0.1.1"
},
"last_serial": 1692685,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "2818c825dad9a7d9c3eb2e940e966d6b",
"sha256": "d6ad1b37d0f8fd6548b88afb4e6c46aa60794046dfde6b07aa95cac82550c607"
},
"downloads": -1,
"filename": "collective.jsconfiguration-0.1.0.zip",
"has_sig": false,
"md5_digest": "2818c825dad9a7d9c3eb2e940e966d6b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 29750,
"upload_time": "2014-05-02T13:08:04",
"url": "https://files.pythonhosted.org/packages/63/40/fc2b41c578008ff1a2334e3a72229e5de8b1073225fe5eeaeb9903402f31/collective.jsconfiguration-0.1.0.zip"
}
],
"0.1.1": [
{
"comment_text": "",
"digests": {
"md5": "b972a580184ca94875063e7e4ffd1b2d",
"sha256": "f260efdcec8e2b7438ce7785ef07b7aee6f04b48a0abb4e25115bf4eb0f848da"
},
"downloads": -1,
"filename": "collective.jsconfiguration-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b972a580184ca94875063e7e4ffd1b2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17875,
"upload_time": "2015-08-25T10:31:17",
"url": "https://files.pythonhosted.org/packages/bf/3f/fedd20f4a582a53aec4905a02237ede243c98c6a5d1c93509e0bf27d7635/collective.jsconfiguration-0.1.1.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "b972a580184ca94875063e7e4ffd1b2d",
"sha256": "f260efdcec8e2b7438ce7785ef07b7aee6f04b48a0abb4e25115bf4eb0f848da"
},
"downloads": -1,
"filename": "collective.jsconfiguration-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b972a580184ca94875063e7e4ffd1b2d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17875,
"upload_time": "2015-08-25T10:31:17",
"url": "https://files.pythonhosted.org/packages/bf/3f/fedd20f4a582a53aec4905a02237ede243c98c6a5d1c93509e0bf27d7635/collective.jsconfiguration-0.1.1.tar.gz"
}
]
}