Недавно прочел очень интересный срач спор о том, как вообще true-программеры генерят html. Я даже не ожидал, что могу не знать такого интересного способа, хотя он лежит буквально на виду.
Основные тезисы дискуссии ниже (оппонента так затроллили, что он от стыда удалил все свои комменты, и теперь там по сути одна гневная проповедь weavejester'a).
1. Html и css -- дизайнерам, код -- кодерам. И смотри не перепутай, Кутузау!
Weavejester: "The problem with using HTML templating languages is that they quickly become impractical as the complexity of the page increases. Maintaining a file that's a mishmash of HTML from a designer and code from a developer is, in my experience, far more trouble than it's worth."
2. Html только для контента, весь look-n-feel делает CSS.
Weavejester: "Secondly, I'm of the opinion that if the presentation of your HTML page cannot be easily changed through CSS alone, then your HTML is probably not well-designed. Rather than trying to construct HTML purely based around a particular presentation layout, perhaps a better approach would be to construct the HTML independent of the presentation, and then to iteratively tweak this purely semantic structure into something that can be easily altered by CSS into the desired design.
...
That's not to say all our HTML is perfectly formed straight off the bat. Far from it. But when we find a part of our design can't easily be altered by CSS alone, we try to fix the HTML so that it can be. Eventually one gets to the point where the HTML rarely needs to be altered, except when new content or features are added."
3. Дизайнер делает только layout. Весь контент, все внутренности html-а делает программист.
Weavejester: "I don't disagree that the UI can change; I'm just of the opinion that written correctly, you can (more or less) isolate the content from the presentation. If anything, it's easier to change a set of well defined functions, or a file of CSS, than it is to alter a clunky mashup of HTML and inline code."
vagif: "...designers make changes to html as opposed to developers by saying that they are familiar with html and have the necessary tools.
But this is awfully wrong. When you change html it is either look'n'feel (colors,background,fonts,layout,icons,banners,etc) or structural change (add / remove some elements like buttons, dropdowns, edit boxes etc.)
In first case it is never continuous work. You usually decide and finish look'n'feel as one unit of work, and then just utilize the result of designer's work by wrapping it in libraries/templates/includes so developers would not waste their time to deal with those settings in each particular page.
Structural change on the other hand is where the actual bulk of changes happens. And it is NEVER a designer's work, but always a developer's. SO i was very surprised when you told that your designers often change things "in a middle". What the heck do they change ? Color schemes ? new banners every week ? you could not decide upon the layout of your web site, so you change it that often ?"
4. True-way: дизайнер делает html-страницу, программер преобразовывает ее в набор функций, генерирующих этот самый html. После этого программер может редактировать полученный результат как код, а не как html.
Weavejester: "As a developer, I'd much rather the designer send me a file of HTML I can convert into a concise set of functions."
То есть я в корне неверно воспринимал hiccup! Этот движок темплейтов не используется для генерации страницы вручную. Дизайнерское поделие переводится в формат, который воспринимает hiccup, а затем программер может его редактировать как код, а не как html! Вот уж действительно true-разделение логики и представления!
Пример:
В файле проекта должно быть:
Надо сказать, что хотя результат незначительно отличался по размеру, в броузере сгенерированная html-страница выглядела абсолютно идентичной оригиналу.
Основные тезисы дискуссии ниже (оппонента так затроллили, что он от стыда удалил все свои комменты, и теперь там по сути одна гневная проповедь weavejester'a).
1. Html и css -- дизайнерам, код -- кодерам. И смотри не перепутай, Кутузау!
Weavejester: "The problem with using HTML templating languages is that they quickly become impractical as the complexity of the page increases. Maintaining a file that's a mishmash of HTML from a designer and code from a developer is, in my experience, far more trouble than it's worth."
2. Html только для контента, весь look-n-feel делает CSS.
Weavejester: "Secondly, I'm of the opinion that if the presentation of your HTML page cannot be easily changed through CSS alone, then your HTML is probably not well-designed. Rather than trying to construct HTML purely based around a particular presentation layout, perhaps a better approach would be to construct the HTML independent of the presentation, and then to iteratively tweak this purely semantic structure into something that can be easily altered by CSS into the desired design.
...
That's not to say all our HTML is perfectly formed straight off the bat. Far from it. But when we find a part of our design can't easily be altered by CSS alone, we try to fix the HTML so that it can be. Eventually one gets to the point where the HTML rarely needs to be altered, except when new content or features are added."
3. Дизайнер делает только layout. Весь контент, все внутренности html-а делает программист.
Weavejester: "I don't disagree that the UI can change; I'm just of the opinion that written correctly, you can (more or less) isolate the content from the presentation. If anything, it's easier to change a set of well defined functions, or a file of CSS, than it is to alter a clunky mashup of HTML and inline code."
vagif: "...designers make changes to html as opposed to developers by saying that they are familiar with html and have the necessary tools.
But this is awfully wrong. When you change html it is either look'n'feel (colors,background,fonts,layout,icons,banners,etc) or structural change (add / remove some elements like buttons, dropdowns, edit boxes etc.)
In first case it is never continuous work. You usually decide and finish look'n'feel as one unit of work, and then just utilize the result of designer's work by wrapping it in libraries/templates/includes so developers would not waste their time to deal with those settings in each particular page.
Structural change on the other hand is where the actual bulk of changes happens. And it is NEVER a designer's work, but always a developer's. SO i was very surprised when you told that your designers often change things "in a middle". What the heck do they change ? Color schemes ? new banners every week ? you could not decide upon the layout of your web site, so you change it that often ?"
4. True-way: дизайнер делает html-страницу, программер преобразовывает ее в набор функций, генерирующих этот самый html. После этого программер может редактировать полученный результат как код, а не как html.
Weavejester: "As a developer, I'd much rather the designer send me a file of HTML I can convert into a concise set of functions."
То есть я в корне неверно воспринимал hiccup! Этот движок темплейтов не используется для генерации страницы вручную. Дизайнерское поделие переводится в формат, который воспринимает hiccup, а затем программер может его редактировать как код, а не как html! Вот уж действительно true-разделение логики и представления!
Пример:
(ns webtest.core (:require [pl.danieljanus.tagsoup :as ts] [hiccup.core :as h] [clojure.contrib.duck-streams :as io])) (def data (slurp "data/data.html")) (def parsed (ts/parse-string data)) (def generated (h/html parsed)) (io/spit "data/output.html" generated)
В файле проекта должно быть:
(defproject webtest "1.0.0-SNAPSHOT" :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.2.1"] [org.clojure/clojure-contrib "1.2.0"] [clj-tagsoup "0.2.6"] [hiccup "0.3.6"]])
Надо сказать, что хотя результат незначительно отличался по размеру, в броузере сгенерированная html-страница выглядела абсолютно идентичной оригиналу.