cvs: peardoc /en/package/html html-css.xml /en/package/html/html-css parse.xml
| From: | Laurent Laville | Date: | Thu, 22 Jan 2009 10:37:03 +0000 |
| Subject: | cvs: peardoc /en/package/html html-css.xml /en/package/html/html-css parse.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-11461@lists.php.net to get a copy of this message | ||
farell Thu Jan 22 10:37:03 2009 UTC
Added files:
/peardoc/en/package/html/html-css parse.xml
Modified files:
/peardoc/en/package/html html-css.xml
Log:
phase4: continue to include my external doc (TDG) => Getting Started -> Parsing data sources
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-css.xml?r1=1.17&r2=1.18&diff_format=u
Index: peardoc/en/package/html/html-css.xml
diff -u peardoc/en/package/html/html-css.xml:1.17 peardoc/en/package/html/html-css.xml:1.18
--- peardoc/en/package/html/html-css.xml:1.17 Thu Jan 22 10:23:14 2009
+++ peardoc/en/package/html/html-css.xml Thu Jan 22 10:37:02 2009
@@ -122,6 +122,7 @@
&package.html.html-css.intro;
&package.html.html-css.group;
+ &package.html.html-css.parse;
</chapter>
<chapter xml:id="package.html.html-css.ref">
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-css/parse.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-css/parse.xml
+++ peardoc/en/package/html/html-css/parse.xml
<?xml version="1.0" encoding="utf-8"?>
<refentry xmlns="http://docbook.org/ns/docbook"
version="lillet" xml:id="package.html.html-css.parse">
<refnamediv>
<refname>Parsing data sources</refname>
<refpurpose>load existing style sheet from different data sources</refpurpose>
</refnamediv>
<refsection xml:id="package.html.html-css.parse.purpose">
<info><title>In brief</title></info>
<para>
One of the great features of HTML_CSS is to parse and load existing style sheet
from different data sources : (simple string, css file, combine).
We will see in detail all these possibilities with 3 methods :
<methodname>HTML_CSS::parseString()</methodname>,
<methodname>HTML_CSS::parseFile()</methodname> and
<methodname>HTML_CSS::parseData()</methodname>.
</para>
</refsection>
<refsection xml:id="package.html.html-css.parse.string">
<info><title>Parse a simple string</title></info>
<para>
A quick way to create multiple selector definitions in one step is to use the
<methodname>HTML_CSS::parseString()</methodname> function.
</para>
<para>
Let creates these definitions :
<programlisting role="css">
html, body {
margin: 2px;
padding: 0px;
border: 0px;
}
p, body {
margin: 4px;
}
</programlisting>
</para>
<para>
Very easy with such script :
<programlisting role="php">
<![CDATA[
<?php
require_once 'HTML/CSS.php';
$css = new HTML_CSS();
$strcss = '
html, body {
margin: 2px;
padding: 0px;
border: 0px;
}
p, body {
margin: 4px;
}
';
$css->parseString($strcss);
$css->display();
?>
]]>
</programlisting>
</para>
</refsection>
<refsection xml:id="package.html.html-css.parse.file">
<info><title>Parse a file contents</title></info>
<para>
Another quick way to create multiple selector definitions in one step is to use the
<methodname>HTML_CSS::parseFile()</methodname> function.
CSS file to load is supposed to be W3C/CSS compliant.
</para>
<para>
If previous selector definitions was into a file named 'styles.css', then to parse
and load contents will be done with such script :
<programlisting role="php">
<![CDATA[
<?php
require_once 'HTML/CSS.php';
$css = new HTML_CSS();
$css->parseFile('styles.css');
$css->display();
?>
]]>
</programlisting>
</para>
<para>
<tip>
<para>
If there are duplicate definitions into file contents, you should parse file
with call :
<programlisting role="php">
<![CDATA[
<?php
$css->parseFile('styles.css', true);
?>
]]>
</programlisting>
We will see next why we may find such duplicate definitions.
</para>
</tip>
</para>
</refsection>
<refsection xml:id="package.html.html-css.parse.data">
<info><title>Parse multi data sources </title></info>
<para>
We have already seen two single sources where CSS data could come from.
The last one allow to parse data from multiple sources at once.
<methodname>HTML_CSS::parseData()</methodname> function take an array
as first argument. Each item is either a filename (with .css extension) or
a string. Each source is merge to produce at end a unique style sheet.
</para>
<para>
In script below we load selector definitions from two independent sources:
a string and a css file which contents duplicate definitions (parseFile() 2nd
argument to set to true to catch this situation; see next section for explains).
Internet Explorer).
<programlisting role="php">
<![CDATA[
<?php
require_once 'HTML/CSS.php';
$css = new HTML_CSS();
// 1. a string to parse
$strcss = '
body, p { background-color: white; font: 1.2em Arial; }
p, div#black { color: black; }
div{ color: green; }
p { margin-left: 3em; }
';
$css->parseString($strcss);
// 2. a css file with duplicate definitions
$css->parseFile('iehack.css', true);
$css->display();
?>
]]>
</programlisting>
</para>
</refsection>
<refsection xml:id="package.html.html-css.parse.duplicate">
<info><title>Allow duplicate definitions</title></info>
<para>
Internet Explorer <= 6 does not handle box model in same way as others browsers that are
better W3C compliant. For this reason, we need to fix boxes size with a hack such as
this one you can find in example that follow. You can notice the duplicate
'voice-family' and 'height' properties.
</para>
<para>
To parse these definitions we need to activate the
<emphasis role="bold">duplicate</emphasis> option of HTML_CSS.
<programlisting role="css">
#header {
background-color: ivory;
font-family: "Times New Roman", Times, serif;
font-size: 5mm;
text-align: center;
/* IE 5.5 */
height:81px;
border-top:1px solid #000;
border-right:1px solid #000;
border-left:1px solid #000;
voice-family: "\"}\"";
voice-family: inherit;
/* IE 6 */
height: 99px;
}
</programlisting>
</para>
<para>
There are two ways :
<itemizedlist>
<listitem>
<para>
global to all functions: set option <emphasis
role="bold">allowduplicates</emphasis>
on class constructor
</para>
</listitem>
<listitem>
<para>
local to a function: set argument <emphasis
role="bold">duplicates</emphasis>
to TRUE
</para>
</listitem>
</itemizedlist>
</para>
<para>
For example here, we could wrote either (allow global duplicate) :
<programlisting role="php">
<![CDATA[
<?php
require_once 'HTML/CSS.php';
$attr = array('allowduplicates' => true);
$css = new HTML_CSS($attr);
$strcss = '
#header {
background-color: ivory;
font-family: "Times New Roman", Times, serif;
font-size: 5mm;
text-align: center;
/* IE 5.5 */
height:81px;
border-top:1px solid #000;
border-right:1px solid #000;
border-left:1px solid #000;
voice-family: "\"}\"";
voice-family: inherit;
/* IE 6 */
height: 99px;
}
';
$css->parseString($strcss);
$css->display();
?>
]]>
</programlisting>
or also (duplicate on local call) :
<programlisting role="php">
<![CDATA[
<?php
require_once 'HTML/CSS.php';
$css = new HTML_CSS();
$strcss = '
#header {
background-color: ivory;
font-family: "Times New Roman", Times, serif;
font-size: 5mm;
text-align: center;
/* IE 5.5 */
height:81px;
border-top:1px solid #000;
border-right:1px solid #000;
border-left:1px solid #000;
voice-family: "\"}\"";
voice-family: inherit;
/* IE 6 */
height: 99px;
}
';
$css->parseString($strcss, true);
$css->display();
?>
]]>
</programlisting>
</para>
</refsection>
</refentry>