Any reason not to write my own HTML?

和自甴很熟 提交于 2019-12-24 07:10:26

问题


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

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.

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?


回答1:


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.




回答2:


I don't think there is a real downside to render static html pieces like that.

However, you might want to check out the Seaside integration of Twitter bootstrap: http://twitterbootstrap.seasidehosting.st/




回答3:


To rephrase one of Lukas' arguments: it basically is not DRY. If you're using it only once, there is no problem. If you have to use this multiple times, the canvas allows you to use all the clean reuse capabilities smalltalk offers you.



来源:https://stackoverflow.com/questions/10740597/any-reason-not-to-write-my-own-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!