{ "info": { "author": "Ben Holzman", "author_email": "ben.holzman@axial.net", "bugtrack_url": null, "classifiers": [], "description": "=====\nSpoke\n=====\n\nSpoke provides a framework for building reusable front-end components.\n\nInstalling\n==========\n\nThe spoke project lives on github_, and is available via pip_.\n\n.. _github: https://github.com/axialmarket/spoke\n.. _pip: https://pypi.python.org/pypi/spoke/0.2\n\nInstalling v0.2 From Pip\n------------------------\n\n::\n\n sudo pip install spoke==0.2\n\nInstalling v0.2 From Source\n---------------------------\n\n::\n\n curl https://github.com/axialmarket/spoke/archive/version_0.2.tar.gz | tar vzxf -\n cd spoke\n sudo python setup.py install\n\n\nWhat is a Spoke?\n================\n\nA spoke is an executable javascript file that can contain javascript, CSS and HTML templates. In addition, a spoke can have dependencies on other spokes, which allows us to partition front-end components into small discrete chunks and at build time create a single loadable javascript file for a page that includes just the functionality we need. Now, you may be wondering how we embed CSS and HTML templates into an executable javascript file. We're using a somewhat unsophisticated approach; we URI-encode the CSS or HTML content into a string and embed it in some simple javascript that decodes the content and dynamically adds it to the DOM.\n\nA simple example\n================\n\nLet's create a spoke for rendering a user's name. This perhaps sounds like it's too simple a task, but there could be some complexity to the logic required:\n\n- To save space, if the user's full name would be more than 20 characters, we will render just their first initial followed by their last name.\n- If the user is an internal user, we want to annotate their name with (internal).\n- If the user is an internal user masquerading as a regular user, we want to annotate their name with (masq).\n\nFor this example, we will use a Backbone model and view, and an Underscore template, but these are implementation choices and not imposed on us just because we are creating a spoke.\n\nHere is the Backbone model we will use:\n\n::\n\n var UsernameModel = Backbone.Model.extend({\n defaults: { first_name: \"\",\n last_name: \"\",\n is_internal: false,\n is_masq: false }\n });\n\nThe view is pretty straightforward:\n\n::\n\n var UsernameView = Backbone.View.extend({\n className: 'username',\n render: function() {\n this.$el.html(this.template(this.model.attributes));\n return this;\n },\n template: _.template($('#username-template').html())\n });\n\n\nWe will store the Underscore template in a \n\nIn addition, we have a CSS file to control the styling of the username:\n\n::\n\n .username {\n font-size: 18px;\n color: #333;\n white-space: nowrap;\n }\n\nTo turn this into a spoke, all we have to do is store these source files in the spoke source tree, which is in /var/spoke/:\n\n::\n\n js/models/Username.js\n js/views/Username.js\n html/username.html.tpl\n css/username.css\n\nThen we add a definition for this spoke (which we will call, surprise, surprise, \"username\") to a spoke config, which we add to /etc/spoke/:\n\n::\n\n # /etc/spoke/username.cfg\n [username]\n js = [ 'models/Username.js', 'views/Username.js' ]\n html = 'username.html.tpl'\n css = 'username.css'\n spokes = 'backbone'\n\nSpokes do not need to have all of these types of files; a spoke might contain only CSS or only javascript content. Note, also, that we have made the \"username\" spoke dependent on the \"backbone\" spoke. The definition of the \"backbone\" spoke in turn references the \"underscore\" spoke. When we use spokec to generate a spoke, these dependencies are followed and included in the output. As you probably anticipate, if a spoke is referenced multiple times, it only gets included in the output once.\n\nNow that we've defined this spoke, here's how we would call spokec to generate it:\n\n::\n\n spokec username [add'l spokes] -o path/to/output.js\n\nEach invocation of spokec generates a single executable javascript file containing all of the specified spokes and their dependencies. So typically a service will create a single spoke file for all of its pages, or sometimes a few different spoke files if the pages that service provides are significantly different.\n\nFor More Help\n=============\n\n::\n\n spokec --help\n\nLicense\n=======\n\nBSD 3-Clause, see LICENSE.txt_.\n\n.. _LICENSE.txt: https://github.com/axialmarket/spoke/LICENSE.txt\n\nAuthors\n=======\n\n| Ben Holzman \n| Matthew Story ", "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/axialmarket/spoke", "keywords": null, "license": "3-BSD", "maintainer": null, "maintainer_email": null, "name": "spoke", "package_url": "https://pypi.org/project/spoke/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/spoke/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/axialmarket/spoke" }, "release_url": "https://pypi.org/project/spoke/0.2/", "requires_dist": null, "requires_python": null, "summary": "Spoke -- Reusable Front-End Components", "version": "0.2" }, "last_serial": 991722, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "5afd4f432a97ea82abca9b44aaee8b7b", "sha256": "da97e06a54d047cebff1bec029d39de616bab666c4c9f3b9b33bb13b801ffe0e" }, "downloads": -1, "filename": "spoke-0.1.tar.gz", "has_sig": false, "md5_digest": "5afd4f432a97ea82abca9b44aaee8b7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7291, "upload_time": "2014-01-28T00:44:27", "url": "https://files.pythonhosted.org/packages/9a/da/1c90342204b7de62ad253e3ea1ba160e3367b247d6a2c228ab12b9dedcea/spoke-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "9b602bf9ebb42a74fb20fc146428a7e7", "sha256": "8d70779cf2f492d681822f0031d54f9922aa52cfc549af4ae85eb658b73a1bb7" }, "downloads": -1, "filename": "spoke-0.2.tar.gz", "has_sig": false, "md5_digest": "9b602bf9ebb42a74fb20fc146428a7e7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6958, "upload_time": "2014-02-05T21:36:50", "url": "https://files.pythonhosted.org/packages/1d/db/d3de28690cf67aa7487f5f66aaafcb93fc5faecbaf05a85e1cfb1c93b9a5/spoke-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9b602bf9ebb42a74fb20fc146428a7e7", "sha256": "8d70779cf2f492d681822f0031d54f9922aa52cfc549af4ae85eb658b73a1bb7" }, "downloads": -1, "filename": "spoke-0.2.tar.gz", "has_sig": false, "md5_digest": "9b602bf9ebb42a74fb20fc146428a7e7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6958, "upload_time": "2014-02-05T21:36:50", "url": "https://files.pythonhosted.org/packages/1d/db/d3de28690cf67aa7487f5f66aaafcb93fc5faecbaf05a85e1cfb1c93b9a5/spoke-0.2.tar.gz" } ] }