语法区别¶
Plim 不是完整的 Slim 移植,两者区别在于:
Slim 中有 (
'
)、(='
)、(=='
) ` 三种行内指示符(line indicators)<https://github.com/stonean/slim#line-indicators>`_ 。Plim 使用,
代替'
。, value =, value ==, value
之所以这样改动,是为了避免这种情况下的语法歧义:
/ Is this an empty python string or a syntax error caused by the unclosed single quote? ='' / Is this a python string 'u' ('u''' is the correct python syntax) or a syntax error caused by the unclosed unicode docstring? ='u'''
然而 Python 表达式不允许以逗号起始,因此下面的例子并不会产生歧义
/ Syntax error at mako runtime caused by the unclosed single quote =,' / Correct and consistent. Produces an empty unicode string followed by an explicit trailing whitespace =,u''
另外,使用逗号相比引号也更自然,因为我们在书写普通英文单词,如 “I’m”、“it’s” 时也会使用单引号。
和 Slim 不同的是,Plim 并不支持方括号或者花括号作为标签属性标记,只允许小括号
()
:/ For attributes wrapping we can use only parentheses p(title="Link Title") h1 class=(item.id == 1 and 'one' or 'unknown') Title / Square and curly braces are allowed only in Python and Mako expressions a#idx-${item.id} href=item.get_link( **{'argument': 'value'}) = item.attrs['title']
Plim 中,所有 HTML 标签 必须 完全小写:
该限制是为了提供 隐式纯文本块(Implicit Litaral Blocks) 功能。
doctype 5 html head title Page Title body p | Hello, Explicit Literal Block! p Hello, Implicit Literal Block!
不必在
style
andscript
标签中使用|
(管道符)。Plim 并不对结构控制和内嵌的过滤器之间加以区别。
在 Slim 中你需要写
-if
、-for
以及coffee:
,但是在 Plim 中你不可以在结尾添加冒号:-if
、-for
、-coffee
。和 Slim 不同,Plim 并不支持
/!
这样的 HTML 批量注释 ,在 Plim 中你只能使用原生 HTML 注释符。