在海边,在所有这些renderContentOn:
方法,我可以使用HTML Canvas对象来组装我的DOM树。
我写了一堆帮手对我的组件目前,因为我使用Twitter的引导的造型和不想写所有的样板代码( <div>
小号带MAS)所有的时间。
对于这种方式是安装程序,对我来说最简单的方法是简单(我要避免使用with: aBlock
这些佣工)写出来供包装的DIV像这样的HTML:
html html: '<div class="control-group">'.
有什么理由让我不这样做呢? 任何缺点?
There are various advantages in using the HTML canvas:
- The HTML canvas ensures valid tags, a valid tag structure, that all tags are properly closed (at compile time), and that contents is properly escaped.
- The HTML canvas ensures valid attributes, that all attributes are properly closed, and that contents is properly escaped.
- As a consequence of the above two the HTML canvas automatically avoids the possibility of cross-site scripting (XSS) vulnerabilities.
- The HTML canvas enables better reusability by enabling composition of tags (simple function calls), presenters (
renderOn:
in Objects), and components (renderContentOn:
of components).
- The HTML canvas avoids generating unnecessary whitespaces.
- The use of HTML canvas enables one to use the standard tools the Smalltalk IDE provides on HTML code: senders, implementors, refactoring engine (extract to method, extract to component, inline method, automatic rewrite, ...), etc.
I agree that in some rare cases it is not worth to use HTML canvas: For example, when large static junks coming from an external source need to be embedded into a page.
我不认为这是一个真正的缺点来呈现静态html件这样的。
但是,您可能想看看Twitter的引导的海滨集成: http://twitterbootstrap.seasidehosting.st/
要改写的卢卡斯的论点之一:它基本上是不干燥。 如果你使用它只有一次,是没有问题的。 如果你有使用这个多次,画布允许你使用所有的清洁重用功能的Smalltalk为您提供。