hcard-example1-steps: Difference between revisions
No edit summary |
m (remove inapplicable prose re: "organization-name") |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<h1> hCard Example 1 Steps </h1> | |||
{{TOC-right}} | |||
This is a step by step explanation of the first example in the [[hCard]] specification. | This is a step by step explanation of the first example in the [[hcard|hCard]] specification. | ||
== | <h2> Example </h2> | ||
=== vCard example === | |||
Here is a sample vCard: | Here is a sample vCard: | ||
Line 12: | Line 15: | ||
FN:Tantek Çelik | FN:Tantek Çelik | ||
URL:http://tantek.com | URL:http://tantek.com | ||
END:VCARD | END:VCARD | ||
</nowiki></pre> | </nowiki></pre> | ||
=== hCard example iteration 0: literal === | |||
and an equivalent in literal hCard: | and an equivalent in literal hCard: | ||
Line 27: | Line 31: | ||
<span class="fn">Tantek Çelik</span> | <span class="fn">Tantek Çelik</span> | ||
</a> | </a> | ||
</div> | </div> | ||
</nowiki></pre> | </nowiki></pre> | ||
Line 33: | Line 36: | ||
Note that the "N" type, as defined in RFC2426, Section 3.1.2, has several components, and thus these components are defined using nested elements with a class name that is a direct equivalent of the component from the RFC, e.g. "given-name" and "family-name". | Note that the "N" type, as defined in RFC2426, Section 3.1.2, has several components, and thus these components are defined using nested elements with a class name that is a direct equivalent of the component from the RFC, e.g. "given-name" and "family-name". | ||
Both the vCard and the literal hCard violate the [http://c2.com/cgi/wiki?DontRepeatYourself DRY principle] by duplicating the name information. The hCard version compensates for this by hiding one occurence with CSS. | |||
=== hCard example iteration 1: DRY === | |||
However, structurally the same XHTML element could be reused for the "N" and "FN" types (since multiple class names can be placed in one class attribute by space separating them), and thus duplication of the name information itself can be eliminated: | |||
<pre><nowiki> | <pre><nowiki> | ||
Line 40: | Line 47: | ||
<span class="fn n"> | <span class="fn n"> | ||
<span class="given-name">Tantek</span> | <span class="given-name">Tantek</span> | ||
<span class=" | <span class="family-name">Çelik</span> | ||
</span> | </span> | ||
</a> | </a> | ||
</div> | </div> | ||
</nowiki></pre> | </nowiki></pre> | ||
Thus even with this first iteration we have made a significant improvement over the vCard, by avoiding the repeating of name information, and conforming to the [http://c2.com/cgi/wiki?DontRepeatYourself DRY principle]. | |||
=== hCard example iteration 2: element conservation === | |||
This can be even further optimized by placing the "fn" and "n" class names on the <a href>, and eliminating the intermediate span. | This can be even further optimized by placing the "fn" and "n" class names on the <a href>, and eliminating the intermediate span. | ||
Line 55: | Line 65: | ||
<span class="family-name">Çelik</span> | <span class="family-name">Çelik</span> | ||
</a> | </a> | ||
</div> | </div> | ||
</nowiki></pre> | </nowiki></pre> | ||
Finally, using the Implied "N | === hCard example iteration 3: implied optimizations === | ||
Finally, using the Implied "N" Optimization, we are able to omit the explicit given and family names markup as well as the explicit "n". | |||
<pre><nowiki> | <pre><nowiki> | ||
Line 66: | Line 77: | ||
Tantek Çelik | Tantek Çelik | ||
</a> | </a> | ||
</div> | </div> | ||
</nowiki></pre> | </nowiki></pre> | ||
=== hCard display === | |||
The display for all versions of this hCard is the same: | The display for all versions of this hCard is the same: | ||
[http://tantek.com/ Tantek Çelik] | [http://tantek.com/ Tantek Çelik] | ||
Back to the [[hCard]] specification. | Back to the [[hcard|hCard]] specification. |
Latest revision as of 22:41, 25 November 2007
hCard Example 1 Steps
This is a step by step explanation of the first example in the hCard specification.
Example
vCard example
Here is a sample vCard:
BEGIN:VCARD VERSION:3.0 N:Çelik;Tantek FN:Tantek Çelik URL:http://tantek.com END:VCARD
hCard example iteration 0: literal
and an equivalent in literal hCard:
<div class="vcard"> <a class="url" href="http://tantek.com/"> <span class="n" style="display:none"> <!-- hide this from display with CSS --> <span class="family-name">Çelik</span> <span class="given-name">Tantek</span> </span> <span class="fn">Tantek Çelik</span> </a> </div>
Note that the "N" type, as defined in RFC2426, Section 3.1.2, has several components, and thus these components are defined using nested elements with a class name that is a direct equivalent of the component from the RFC, e.g. "given-name" and "family-name".
Both the vCard and the literal hCard violate the DRY principle by duplicating the name information. The hCard version compensates for this by hiding one occurence with CSS.
hCard example iteration 1: DRY
However, structurally the same XHTML element could be reused for the "N" and "FN" types (since multiple class names can be placed in one class attribute by space separating them), and thus duplication of the name information itself can be eliminated:
<div class="vcard"> <a class="url" href="http://tantek.com/"> <span class="fn n"> <span class="given-name">Tantek</span> <span class="family-name">Çelik</span> </span> </a> </div>
Thus even with this first iteration we have made a significant improvement over the vCard, by avoiding the repeating of name information, and conforming to the DRY principle.
hCard example iteration 2: element conservation
This can be even further optimized by placing the "fn" and "n" class names on the <a href>, and eliminating the intermediate span.
<div class="vcard"> <a class="url fn n" href="http://tantek.com/"> <span class="given-name">Tantek</span> <span class="family-name">Çelik</span> </a> </div>
hCard example iteration 3: implied optimizations
Finally, using the Implied "N" Optimization, we are able to omit the explicit given and family names markup as well as the explicit "n".
<div class="vcard"> <a class="url fn" href="http://tantek.com/"> Tantek Çelik </a> </div>
hCard display
The display for all versions of this hCard is the same:
Back to the hCard specification.