Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seletor at the beginning of the ruleset #3

Open
s1738berger opened this issue Aug 23, 2016 · 0 comments
Open

Add seletor at the beginning of the ruleset #3

s1738berger opened this issue Aug 23, 2016 · 0 comments

Comments

@s1738berger
Copy link

s1738berger commented Aug 23, 2016

Hi, sometimes it is important to add a selector at the beginning of the css tree. In my case it is the universal seletor (_).
Here an idea to achieve this. This new sub routine _unshift_selector* is just a slightly modified version of the existing add_selector.
Would be nice to see this functionality in the next version of CSS::Simple
Regards, Stefan


=pod

=item unshift_selector( params )

Add a selector and associated properties to the stored rulesets on first place

In the event that this particular ruleset already exists, invoking this method will
simply replace the item. This is important - if you are modifying an existing rule
using this method than the previously existing selectivity will continue to persist.
Delete the selector first if you want to ignore the previous selectivity.

This method requires you to pass in a params hash that contains scalar
css data. For example:

$self->unshift_selector({selector => '.foo', properties => {color => 'red' }});

=cut

sub unshift_selector {
my ($self,$params) = @_;

$self->_check_object();

#if we existed already, invoke REPLACE to preserve selectivity
if ($self->check_selector({selector => $$params{selector}})) {
#we probably want to be doing this explicitely
my ($index) = $self->_ordered()->Indices( $$params{selector} );

$self->_ordered()->Replace($index,dclone($$params{properties}));

}
#new element, stick it onto the beginning of the rulesets
else {
#store the properties
$self->_ordered()->Unshift($$params{selector},dclone($$params{properties}));
}

return();
}


@s1738berger s1738berger changed the title Add seletor at the beginning of the list Add seletor at the beginning of the ruleset Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant