有什么理由不编写自己的HTML吗? [英] Any reason not to write my own HTML?

查看:113
本文介绍了有什么理由不编写自己的HTML吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Seaside中,在所有这些renderContentOn:方法中,我都可以使用HTML canvas对象来组装我的DOM树.

In Seaside, in all those renderContentOn: methods, I can use the HTML canvas object to assemble my DOM tree.

我目前正在为我的组件编写一堆帮助程序,因为我正在使用Twitter Bootstrap进行样式设置,并且不想一直写所有样板代码(<div> en mas).

I am writing a bunch of helpers for my components currently, because I'm using Twitter Bootstrap for the styling and don't want to write all that boilerplate code (<div>s en mas) all the time.

对于这种设置方式,对我而言,最简单的方法是简单地(我想避免在那些帮助器中使用with: aBlock)为包装DIV编写HTML,如下所示:

For the way this is setup, the easiest way for me is to simply (I want to avoid using with: aBlock in those helpers) write out the HTML for the wrapping DIVs like this:

html html: '<div class="control-group">'.

我是否有任何理由不这样做?有什么缺点吗?

Is there any reason for me not to do this? Any downsides?

推荐答案

使用HTML画布有很多优点:

There are various advantages in using the HTML canvas:

  • HTML画布确保有效的标签,有效的标签结构,正确关闭所有标签(在编译时)以及正确地转义内容.
  • HTML画布可确保有效的属性,所有属性均已正确关闭,并且内容已正确转义.
  • 由于上述两个原因,HTML画布自动避免了跨站点脚本(XSS)漏洞的可能性.
  • HTML画布通过启用标签(简单函数调用),演示者(对象中的renderOn:)和组件(组件的renderContentOn:)的组合来实现更好的可重用性.
  • HTML画布避免生成不必要的空格.
  • 使用HTML canvas可以使用Smalltalk IDE在HTML代码上提供的标准工具:发送者,实现者,重构引擎(提取为方法,提取为组件,内联方法,自动重写等),等等.
  • 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.

我同意在极少数情况下不值得使用HTML canvas:例如,当需要将来自外部来源的大型静态垃圾嵌入到页面中时.

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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆