« Adaption des Javadoc-Standards in CSS The Starfish and the Spider: The Unstoppable Power of Leaderless Organizations »

Javadoc for CSS

17. Mai 2007 von Tom

This article is about the idea to adopt the concept of documentation comments like for Javadoc in CSS. It is a follower to my article in german: Adaption des Javadoc-Standards in CSS.

Javadoc is a writing convention of how to write comments into the sourcecode, please refer to the Wikipedia article if you need some of the basics. Since this is comming from the Programming and the OOP world in specific, all concepts related to programming do not match CSS. But since javadoc has a mature and widely accepted concept in structure and styling comments, even CSS can benefit from so called javadoc-styled comment-blocks (also named DocBlock) within it’s code.

This creates an intra-language / intra-code streamlined view on comments resulting in better readable and exchange-able files. Open Source Projects can benefit from these “coding-guidelines” because this helps a lot even in cases the guidelines are not the best ones. Additionally javadoc-styled comments are well readable and some projects might benefit from existing parsers from the programming world (javadoc; phpdocumentor etc.) even if this is not intended in the first place. Another Idea is to generate a better Readable “Documentation view” of your CSS files with crossreferences between sections and such.

Since it is clear that OOP related stuff from javadoc – and that is much – makes no sense to be used in a CSS-file (javadoc is used to automatically generate a API documentation where in a CSS file the commentblocks and tags are used for the documentation itself), the following general usage concept is proposed:

Comment-Types: File-, Section- and Hackcomment

Each CSS-File has a Filecomment-block on top which contains all major information about the file. After this first block zero or more Sections can be created by an according Sectioncomment-Block that is defined and named by an @section tag. This concept of structuring can already be found in many CSS files so this should reflect current practices very well.

One special thing for CSS are so called CSS-Hacks. You first write down the main CSS-Code and then it is extended with often only some but very special rules only to circumvent special display bugs in certain browsers. Wether you like it or not but it’s always good to mark these very special areas in your CSS document because these stylerules are important by the time of major changes or later problem solving. For these cases a so called Hackcomment-Block can be defined and named with an @hack tag. It comes with an @hackfor tag to write down for which useragent(s) and bug(s) the following style rules were written down.

“backward compability”

Some files within applications contain information within their CSS files that are used by the application itself. A Wordpress Theme for example contains metadata like the name of the theme and its author inside the CSS-file. Shure it would be nice if those themes would adopt a javadoc-styled-notation for these purposes as well (by parsing @author or introducing specific tags like @wp-theme-name or @wp-theme-uri) but an example implementation for javadoc-styled-comments in CSS should leave enough space for backward compability and common practices. That can be easily achieved by not forcing the first file-comment-block to be at the physical beginning of the file.

Javadoc Tags for CSS

This is an example set of Tagnames suggested for the usage of Javadoc-Styled-Comments in CSS. Feedback is greatly appreciated to make this list best fitting and a starting point for every CSS-Writer.

Tag Description Location
@author Name of the CSS-Author, on top of the file. Multiple Authors require multiple tags. Keep in mind that by putting your email address into this line it might be easily parsed by spiders and misused for spam. file
@version Provides the version number of the stylesheet. file
@site Name of the website this Stylesheet is associated with. file
@style Name of the Style this file is associated with. If the site has no specific one, just use default because you should use this Tag once per file. file
@info Opens a “comment-space” for a one- or multiline text. Maybe this tag is not necessary because normal comments can be put into the docblock comment without any tags. file, section
@media Reference to the CSS Media types for which this file was written for. Multiple values can be separated by comma. file, section
Note about location section of the @media tag: This tag is allowed on a per section basis in case the whole file contains a section that is specific for a certain media only. This is the case by using the CSS2 @media rule for example.
@section Opens a new section within the document. For example a reset section at the Beginning of the file, then a layout section containing the major positioning rules etc. section
@layout Opens comment-space to leave some notes on how the space is divided, a general positioning concept and such. Might be a place to ascii-paint a reduced DOM-Model of the associated htmldocument or similar as well. file, section
@see Reference a URL or another File or Section (or Section in another File) that contains important information to help understand the following CSS-Rules. Use one tag per one reference.
Note: It looks like it will be important that this value can be parsed by a machine and that’s why it’s a need to create a Notation how this value can be written down. Ideas wanted.
file, section, hack
@todo Todo Reminder on a per file/per section/per hack basis. file, section, hack
@tested Use to leave a note for which useragent a section or file has been tested. UAs are seperated by comma or you an additional tag. file, section
@hack starts another “section” with it’s sole aim to circumvent specific display bugs within specific browsers. These hacks are following then. hack
@hackfor To write down for which Useragent (e.g. internet explorer 5.5) and maybe even which type of Bug (e.g. 3px margin bug). There are no rules how to write down the name of a useragent or how to name a certain typo of bug. hack
@colordef Define a named color value. Might be usefull to support automatic styleguide creation. Notation: name = value; where value can be any css color value ( rgb() / #123456 / named color). file

Eine Reaktion zu “Javadoc for CSS”

  1. PHPUGFFM » Blog Archiv » Adaption des Javadoc-Standards in CSS

    [...] ION Meet 2 Javadoc for CSS [...]

Einen Kommentar schreiben

5.0 Jahre Badge