1CSS::Tiny(3)          User Contributed Perl Documentation         CSS::Tiny(3)
2
3
4

NAME

6       CSS::Tiny - Read/Write .css files with as little code as possible
7

SYNOPSIS

9           # In your .css file
10           H1 { color: blue }
11           H2 { color: red; font-family: Arial }
12           .this, .that { color: yellow }
13
14           # In your program
15           use CSS::Tiny;
16
17           # Create a CSS stylesheet
18           my $CSS = CSS::Tiny->new();
19
20           # Open a CSS stylesheet
21           $CSS = CSS::Tiny->read( 'style.css' );
22
23           # Reading properties
24           my $header_color = $CSS->{H1}->{color};
25           my $header2_hashref = $CSS->{H2};
26           my $this_color = $CSS->{'.this'}->{color};
27           my $that_color = $CSS->{'.that'}->{color};
28
29           # Changing styles and properties
30           $CSS->{'.newstyle'} = { color => '#FFFFFF' }; # Add a style
31           $CSS->{H1}->{color} = 'black';                # Change a property
32           delete $CSS->{H2};                            # Delete a style
33
34           # Save a CSS stylesheet
35           $CSS->write( 'style.css' );
36
37           # Get the CSS as a <style>...</style> tag
38           $CSS->html;
39

DESCRIPTION

41       "CSS::Tiny" is a perl class to read and write .css stylesheets with as
42       little code as possible, reducing load time and memory overhead. CSS.pm
43       requires about 2.6 meg or ram to load, which is a large amount of over‐
44       head if you only want to do trivial things.  Memory usage is normally
45       scoffed at in Perl, but in my opinion should be at least kept in mind.
46
47       This module is primarily for reading and writing simple files, and any‐
48       thing we write shouldn't need to have documentation/comments. If you
49       need something with more power, move up to CSS.pm. With the increasing
50       complexity of CSS, this is becoming more common, but many situations
51       can still live with simple CSS files.
52
53       CSS Feature Support
54
55       "CSS::Tiny" supports grouped styles of the form "this, that { color:
56       blue }" correctly when reading, ungrouping them into the hash struc‐
57       ture. However, it will not restore the grouping should you write the
58       file back out. In this case, an entry in the original file of the form
59
60           H1, H2 { color: blue }
61
62       would become
63
64           H1 { color: blue }
65           H2 { color: blue }
66
67       "CSS::Tiny" handles nested styles of the form "P EM { color: red }" in
68       reads and writes correctly, making the property available in the form
69
70           $CSS->{'P EM'}->{color}
71
72       "CSS::Tiny" ignores comments of the form "/* comment */" on read cor‐
73       rectly, however these comments will not be written back out to the
74       file.
75

CSS FILE SYNTAX

77       Files are written in a relatively human-orientated form, as follows:
78
79           H1 {
80               color: blue;
81           }
82           .this {
83               color: red;
84               font-size: 10px;
85           }
86           P EM {
87               color: yellow;
88           }
89
90       When reading and writing, all property descriptors, for example "color"
91       and "font-size" in the example above, are converted to lower case. As
92       an example, take the following CSS.
93
94           P {
95               Font-Family: Verdana;
96           }
97
98       To get the value 'Verdana' from the object $CSS, you should reference
99       the key "$CSS->{P}->{font-family}".
100

METHODS

102       new
103
104       The constructor "new" creates and returns an empty "CSS::Tiny" object.
105
106       read $filename
107
108       The "read" constructor reads a CSS stylesheet, and returns a new
109       "CSS::Tiny" object containing the properties in the file.
110
111       Returns the object on success, or "undef" on error.
112
113       read_string $string
114
115       The "read_string" constructor reads a CSS stylesheet from a string.
116
117       Returns the object on success, or "undef" on error.
118
119       clone
120
121       The "clone" method creates an identical copy of an existing "CSS::Tiny"
122       object.
123
124       write
125
126       The "write $filename" generates the stylesheet for the properties, and
127       writes it to disk. Returns true on success. Returns "undef" on error.
128
129       write_string
130
131       Generates the stylesheet for the object and returns it as a string.
132
133       html
134
135       The "html" method generates the CSS, but wrapped in a "style" HTML tag,
136       so that it can be dropped directly onto a HTML page.
137
138       xhtml
139
140       The "html" method generates the CSS, but wrapped in a "style" XHTML
141       tag, so that it can be dropped directly onto an XHTML page.
142
143       errstr
144
145       When an error occurs, you can retrieve the error message either from
146       the $CSS::Tiny::errstr variable, or using the "errstr" method.
147

SUPPORT

149       Bugs should be reported via the CPAN bug tracker at
150
151       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CSS-Tiny>
152
153       For other issues, or commercial enhancement or support, contact the
154       author.
155

AUTHOR

157       Adam Kennedy <cpan@ali.as>
158

SEE ALSO

160       CSS, <http://www.w3.org/TR/REC-CSS1>, Config::Tiny, <http://ali.as/>
161
163       Copyright 2002 - 2006 Adam Kennedy. All rights reserved.
164
165       This program is free software; you can redistribute it and/or modify it
166       under the same terms as Perl itself.
167
168       The full text of the license can be found in the LICENSE file included
169       with this module.
170
171
172
173perl v5.8.8                       2006-09-03                      CSS::Tiny(3)
Impressum