NAME
CSS::Object::Builder - CSS Object Oriented Builder
SYNOPSIS
use CSS::Object;
my $css = CSS::Object->new( debug => 3 ) ||
die( CSS::Object->error );
ny $b = $css->builder;
$b->select( ['#main_section > .article', 'section .article'] )
->display( 'none' )
->font_size( '+0.2rem' )
->comment( ['Some multiline comment', 'that are made possible with array reference'] )
->text_align( 'center' )
->comment( 'Making it look pretty' )
->padding( 5 );
$b->charset( 'UTF-8' );
$b->at( _webkit_keyframes => 'error' )
->frame( 0, { _webkit_transform => 'translateX( 0px )' })
->frame( 25, { _webkit_transform => 'translateX( 30px )' })
->frame( 45, { _webkit_transform => 'translateX( -30px )' })
->frame( 65, { _webkit_transform => 'translateX( 30px )' })
->frame( 82, { _webkit_transform => 'translateX( -30px )' })
->frame( 94, { _webkit_transform => 'translateX( 30px )' })
->frame( [qw( 35 55 75 87 97 100 )], { _webkit_transform => 'translateX( 0px )' } );
VERSION
v0.1.1
DESCRIPTION
CSS::Object::Builder is a dynamic object oriented CSS builder
CONSTRUCTOR
new
To instantiate a new CSS::Object::Builder object you need to pass it a CSS::Object object and that's it.
Optional argument are:
- debug
-
This is an integer. The bigger it is and the more verbose is the output.
METHODS
as_string
This is a shorthand for calling "as_string" in CSS::Object using our "css" method.
at
This takes an at-mark type parameter as first argument, and the name of the at-mark rule. It returns an object from the proper class. For example, a @keyframes
rule would return a CSS::Object::Rule::Keyframes.
charset
This takes an encoding as unique argument, and no matter when it is called in the chain of method calls, this will always be placed at the top of the stylesheet.
comment
Provided with a string or an array reference of comment lines, and this will return an CSS::Object::Comment object.
css
This sets or gets the required CSS::Object for this parser. The parser uses this method and the underlying object to access CSS::Object methods and store css rules using "add_element" in CSS::Object
current_rule
Returns the last added rule from CSS::Object list of rules by calling "last" in Module::Generic::Array on "elements" in CSS::Object which returns a Module::Generic::Array object.
elements
Sets or gets the list of css elements. This is a Module::Generic::Array, but is not used. I should remove it.
new_at_rule
This creates and returns a new CSS::Object::Builder::AtRule object. This should be moved under CSS::Object
new_keyframes_rule
This creates and returns a new CSS::Object::Builder::KeyframesRule- object. This should be moved under CSS::Object
new_rule
This creates and returns a new CSS::Object::Builder::Rule object. CSS::Object::Builder::Rule class allos for dynamic method call to create and add css properties inside a css rule.
select
This takes either a css selector as a string or an array reference of css selectors. It then returns a CSS::Object::Builder::Rule, which is a special class with dynamic method using AUTOLOAD. This makes it possible to call the hundred of css property as method.
Since those css properties are called as perl method, dashes have to be expressed as underline, such as:
$b->select( '.my-class' )->_moz_transition( 'all .25s ease' );
This would be interpreted as:
.my-class
{
-moz-transition: all .25s ease;
}
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
COPYRIGHT & LICENSE
Copyright (c) 2020 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.