Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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/

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top