|
| 1 | +============================ |
| 2 | + In a Nutshell |
| 3 | +============================ |
| 4 | + |
| 5 | +Plim is a Python port of `Ruby's Slim template language <http://slim-lang.com/>`_ |
| 6 | +built on top of the `Mako Templates <http://www.makotemplates.org/>`_. |
| 7 | +It exploits `Mako's preprocessor feature <http://docs.makotemplates.org/en/latest/usage.html?highlight=preprocessor#api-reference>`_ |
| 8 | +to translate its syntax to a valid HTML/Mako markup. |
| 9 | + |
| 10 | + |
| 11 | +Installation |
| 12 | +============= |
| 13 | + |
| 14 | +.. code-block:: bash |
| 15 | + |
| 16 | + pip install Plim |
| 17 | + |
| 18 | + |
| 19 | +Tests |
| 20 | +======= |
| 21 | + |
| 22 | +Plim provides an extensive test suite based on `nosetests <http://nose.readthedocs.org/en/latest/>`_. |
| 23 | +You can run the tests with the following command |
| 24 | + |
| 25 | +.. code-block:: bash |
| 26 | + |
| 27 | + python setup.py nosetests |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +Syntax Highlighters |
| 32 | +====================== |
| 33 | + |
| 34 | +At this moment, Plim doesn't have syntax highlighters. |
| 35 | + |
| 36 | +But, at a starting point you can use |
| 37 | +`Slim syntax highlighters <https://github.com/stonean/slim#syntax-highlighters>`_, |
| 38 | +since Most of the Plim syntax is the same as of Slim. |
| 39 | + |
| 40 | + |
| 41 | +Syntactic Differences |
| 42 | +===================== |
| 43 | + |
| 44 | +Plim is *not the exact* port of Slim. Here is the full list of differences. |
| 45 | + |
| 46 | + |
| 47 | +#. Slim has the ( ``'`` ), ( ``='`` ), and ( ``=='`` ) `line indicators <https://github.com/stonean/slim#line-indicators>`_. |
| 48 | + In Plim, single quote has been replaced by the comma char ( ``,`` ): |
| 49 | + |
| 50 | + .. code-block:: slim |
| 51 | + |
| 52 | + , value |
| 53 | + =, value |
| 54 | + ==, value |
| 55 | + |
| 56 | + |
| 57 | + The change was made in order to get rid of the syntactic ambiguities like these: |
| 58 | + |
| 59 | + .. code-block:: plim |
| 60 | + |
| 61 | + / Is this an empty python string or a syntax error caused by the unclosed single quote? |
| 62 | + ='' |
| 63 | + |
| 64 | + / Is this a python string 'u' ('u''' is the correct python syntax) or |
| 65 | + a syntax error caused by the unclosed unicode docstring? |
| 66 | + ='u''' |
| 67 | + |
| 68 | + Meanwhile, the comma char is not allowed at the beginning of python expression, |
| 69 | + therefore the following code samples are consistent: |
| 70 | + |
| 71 | + .. code-block:: plim |
| 72 | + |
| 73 | + / Syntax error at mako runtime caused by the unclosed single quote |
| 74 | + =,' |
| 75 | + |
| 76 | + / Correct and consistent. Produces an explicit whitespace |
| 77 | + followed by empty unicode string |
| 78 | + =,u'' |
| 79 | + |
| 80 | + |
| 81 | + In addition, the comma-syntax seems more natural, since in formal writing we also add a whitespace |
| 82 | + between a comma and the following word (in contrast to apostrophes, which are usually |
| 83 | + written together with words). |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +#. Unlike Slim, Plim does not support square or curly braces for wrapping tag attributes. |
| 88 | + You can use only parentheses ``()``: |
| 89 | + |
| 90 | + .. code-block:: slim |
| 91 | + |
| 92 | + / For attributes wrapping we can use only parentheses |
| 93 | + p(title="Link Title") |
| 94 | + h1 class=(item.id == 1 and 'one' or 'unknown') Title |
| 95 | + |
| 96 | + / Square and curly braces are allowed only in Python and Mako expressions |
| 97 | + a#idx-${item.id} href=item.get_link( |
| 98 | + **{'argument': 'value'}) = item.attrs['title'] |
| 99 | + |
| 100 | + |
| 101 | +#. In Plim, all html tags **MUST** be written in lowercase. |
| 102 | + |
| 103 | + This restriction was introduced to support Implicit Litaral Block feature. |
| 104 | + |
| 105 | + .. code-block:: slim |
| 106 | + |
| 107 | + doctype 5 |
| 108 | + html |
| 109 | + head |
| 110 | + title Page Title |
| 111 | + body |
| 112 | + p |
| 113 | + | Hello, Explicit Literal Block! |
| 114 | + p |
| 115 | + Hello, Implicit Literal Block! |
| 116 | + |
| 117 | + |
| 118 | +#. Plim does not distinguish between control structures and embedded filters. |
| 119 | + |
| 120 | + In Slim, you would write ``-if``, ``-for``, and ``coffee:`` (without preceding dash, |
| 121 | + but with the colon sign at the tail). |
| 122 | + But in Plim, you must write ``-if``, ``-for``, and ``-coffee``. |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +Full Example |
| 127 | +============================== |
| 128 | + |
| 129 | +.. code-block:: plim |
| 130 | + |
| 131 | + / base.html |
| 132 | + ------------------------- |
| 133 | + doctype html |
| 134 | + html = next.body() |
| 135 | + |
| 136 | + |
| 137 | +.. code-block:: plim |
| 138 | + |
| 139 | + / helpers.html |
| 140 | + ------------------------- |
| 141 | + -def other_headers() |
| 142 | + meta charset="utf-8" |
| 143 | + link rel="stylesheet" href="/static/css/main.css" |
| 144 | + |
| 145 | + |
| 146 | +.. code-block:: plim |
| 147 | + |
| 148 | + / layout.html |
| 149 | + ------------------------- |
| 150 | + -inherit base.html |
| 151 | + -namespace name="helper" helpers.html |
| 152 | + |
| 153 | + head |
| 154 | + title Plim Example |
| 155 | + meta name="keywords" content="template language" |
| 156 | + = helper.other_headers() |
| 157 | + |
| 158 | + script |
| 159 | + /* "script" and "style" blocks do not require explicit literal indicator "|" */ |
| 160 | + $(content).do_something(); |
| 161 | + |
| 162 | + style |
| 163 | + body { |
| 164 | + background:#FFF; |
| 165 | + } |
| 166 | + |
| 167 | + -scss |
| 168 | + /* SCSS/SASS extension */ |
| 169 | + @option compress: no; |
| 170 | + .selector { |
| 171 | + a { |
| 172 | + display: block; |
| 173 | + } |
| 174 | + strong { |
| 175 | + color: blue; |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + -coffee |
| 180 | + # CoffeeScript extension |
| 181 | + square = (x) -> x * x |
| 182 | + |
| 183 | + body |
| 184 | + h1 Markup examples |
| 185 | + #content.example1 |
| 186 | + p Nest by indentation |
| 187 | + <div> |
| 188 | + p Mix raw HTML and Plim markup |
| 189 | + </div> |
| 190 | + |
| 191 | + -md |
| 192 | + Use Markdown |
| 193 | + ============ |
| 194 | + |
| 195 | + See the syntax on [this page][1]. |
| 196 | + |
| 197 | + [1]: http://daringfireball.net/projects/markdown/basics |
| 198 | + |
| 199 | + -rest |
| 200 | + or Use reStructuredText |
| 201 | + ======================= |
| 202 | + |
| 203 | + See the syntax on `this page`_. |
| 204 | + |
| 205 | + .. _this page: http://docutils.sourceforge.net/docs/user/rst/quickref.html |
| 206 | + |
| 207 | + |
| 208 | + -if items |
| 209 | + table |
| 210 | + -for item in items |
| 211 | + tr |
| 212 | + td = item.name |
| 213 | + td = item.price |
| 214 | + -elif show_empty |
| 215 | + p No items found |
| 216 | + -else |
| 217 | + a href=request.route_url('items.add') =, _('Add items') |
| 218 | + |
| 219 | + -unless user.authenticated |
| 220 | + p Please, sign in. |
| 221 | + -else |
| 222 | + p Welcome, ${user.name}! |
| 223 | + ul |
| 224 | + -python |
| 225 | + i = 0 |
| 226 | + limit = 5 |
| 227 | + |
| 228 | + -while i < limit |
| 229 | + li#idx-${i}.up: a href='#' title="Title" == i |
| 230 | + -py i += 1 |
| 231 | + |
| 232 | + -until i < 0 |
| 233 | + li#idx-${i}.down-${i}: a href='''#''' title="""Title""" ==, i |
| 234 | + -python |
| 235 | + i -= 1 |
| 236 | + |
| 237 | + #footer |
| 238 | + Copyright © 2010 Andrew Stone. |
| 239 | + -include footer_links.html |
| 240 | + |
| 241 | + = render('tracking_code') |
0 commit comments