public final class ConditionalAtRuleBlock extends AbstractAtRuleMember implements AtRuleBlock
Example of a conditional at-rule:
@if(ie7) { .test{color:red} }
This block will output its inner statements if its condition is contained
within the set of "true" condition strings, as specified by a
ConditionalsConfig
. Negation may be specified on conditions using
!
. Multiple conditions may be specified using ||
.
For more information on using and configuring conditionals see the main readme file.
Conditionals
,
ConditionalsRefiner
Constructor and Description |
---|
ConditionalAtRuleBlock(int line,
int column,
Iterable<Conditional> conditionals,
Iterable<Statement> statements,
ConditionalsConfig config)
Creates a new
ConditionalAtRuleBlock instance with the given conditions, statements and config object. |
Modifier and Type | Method and Description |
---|---|
com.google.common.collect.ImmutableList<Conditional> |
conditionals()
Gets the list of
Conditionals specified as arguments to this block. |
ConditionalAtRuleBlock |
copy()
For implementations: do not copy comments or orphaned comments, instead be sure to call
AbstractSyntax.copiedFrom(Syntax) on the
new copy. |
boolean |
isWritable()
Returns whether this unit should actually be written.
|
Iterator<Statement> |
iterator() |
boolean |
matches()
Returns true if at least one of the
Conditionals in this block matches any of the true conditions in the config at
the time of this method call. |
void |
propagateBroadcast(Broadcaster broadcaster,
Status status)
Broadcasts or rebroadcasts all child units using the given
Broadcaster . |
SyntaxCollection<StatementIterable,Statement> |
statements()
Gets the
SyntaxCollection of statements within this unit. |
void |
write(StyleWriter writer,
StyleAppendable appendable)
Outputs this
Writable 's string representation. |
parent, parent
annotate, annotateUnlessPresent, annotation, annotations, column, comment, comment, comments, comments, comments, copiedFrom, equals, hasAnnotation, hasAnnotation, hashCode, hasSourcePosition, id, line, orphanedComments, orphanedComments, orphanedComments, shouldBreakBroadcast, status, status, toString, toString, writesOwnComments, writesOwnOrphanedComments
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
parent, parent
annotate, annotateUnlessPresent, annotation, annotations, column, comment, comment, comments, comments, comments, hasAnnotation, hasAnnotation, hasSourcePosition, id, line, orphanedComments, orphanedComments, orphanedComments, toString, writesOwnComments, writesOwnOrphanedComments
shouldBreakBroadcast, status, status
public ConditionalAtRuleBlock(int line, int column, Iterable<Conditional> conditionals, Iterable<Statement> statements, ConditionalsConfig config)
ConditionalAtRuleBlock
instance with the given conditions, statements and config object.
The given config contains the set of strings that are the "true" values/conditions. During output of the CSS source, this block and its contents will only be written out if its condition matches what is in the config (or vice versa if the negation operator is used).
Note that this matching is case-sensitive (everything should be lower-cased).
It is acceptable for the given config to change its set of true conditions, allowing the outputting of multiple variations of the CSS source from a single parse operation. For example, set the true conditions, write out the source, change the true conditions, write out the source again, etc.
line
- The line number.column
- The column number.conditionals
- The list of conditionals.statements
- The inner statements of the block. These will be printed out if the condition is contained within the trueConditions
set.config
- The ConditionalsConfig
instance.public com.google.common.collect.ImmutableList<Conditional> conditionals()
Conditionals
specified as arguments to this block. There may be more than one if the
||
operator was used.public boolean matches()
Conditionals
in this block matches any of the true conditions in the config at
the time of this method call.public SyntaxCollection<StatementIterable,Statement> statements()
StatementIterable
SyntaxCollection
of statements within this unit.statements
in interface StatementIterable
public boolean isWritable()
Writable
Usually this should just return true, however some units that are detachable or otherwise potentially invalid should first check their state and respond appropriately.
isWritable
in interface Writable
isWritable
in class AbstractSyntax
public void write(StyleWriter writer, StyleAppendable appendable) throws IOException
Writable
Writable
's string representation.
Important notes for implementation:
Do not use the StyleWriter
in an attempt to write direct content (Strings, chars, etc...). Use the StyleAppendable
.
The StyleWriter
should be used to make decisions based on writer settings (e.g., compressed vs. verbose output
mode), as well as for writing inner or child Writable
s. Do not call the this method method directly on inner
or child Writable
s! That would bypass any overrides that are set on the StyleWriter
. Use StyleWriter.writeInner(Writable, StyleAppendable)
instead.
write
in interface Writable
writer
- Writer to use for output settings and for writing inner Writable
s.appendable
- Append direct content to this StyleAppendable
.IOException
- If an I/O error occurs.public void propagateBroadcast(Broadcaster broadcaster, Status status)
Broadcastable
Broadcaster
.
The broadcast will only occur for a unit if its Status
matches the given Status
.
Implementers should call this on child units and SyntaxCollection
s first, then use the broadcaster to broadcast
itself. All of this should be wrapped in a check to ensure the Status
matches.
propagateBroadcast
in interface StatementIterable
propagateBroadcast
in interface Broadcastable
propagateBroadcast
in class AbstractSyntax
broadcaster
- Use this Broadcaster
to broadcast all unbroadcasted child units.status
- Broadcast units that have this status.public ConditionalAtRuleBlock copy()
AbstractSyntax
AbstractSyntax.copiedFrom(Syntax)
on the
new copy.copy
in interface AtRuleBlock
copy
in interface Syntax
copy
in class AbstractSyntax
Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.