Skip to content

Commit

Permalink
Improved and added to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamldavis committed Mar 11, 2019
1 parent cd18c1e commit d7af532
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/main/groovy/org/groocss/Color.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ import java.math.MathContext

/**
* Controls Color for CSS styles and has methods for brighter, darker, etc.
*
* <p>Colors can be created using many different methods:
* <li>{@link ColorMethods#rgb},
* <li>{@link ColorMethods#rgba}, <li>{@link ColorMethods#clr},
* <li>{@link ColorMethods#hsl}, <li>{@link ColorMethods#hsla},
* <li>or using {@link org.groocss.ext.StringExtension#getColor(java.lang.String)} or 'hex'.toColor(), among others.
*
* <p>The final CSS result from a Color depends on how it was created and what methods were called on it.
* For example, if {@link Color#alpha(double)} is used, the output color uses rgba.
*
* <p>Methods from {@link ColorMethods} are available to modify Colors.
*
* @see ColorMethods
*/
@EqualsAndHashCode
class Color {
Expand Down
10 changes: 9 additions & 1 deletion src/main/groovy/org/groocss/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import groovy.transform.builder.Builder
import org.groocss.valid.Processor

/**
* Configuration for GrooCSS conversions.
* Configuration for GrooCSS conversions. There are at least four different ways to configure GrooCSS:
*
* <li>Using the groovy constructor: new Config(compress: true)
* <li>Using the builder syntax: Config.builder().compress(true).build()
* <li>Using the DSL: GrooCSS.withConfig { noExts().compress().utf8() }...
* <li>Using StringExtension with config use: 'main.css'.groocss(new Config()) { ... }.
*
* @see GrooCSS
* @see org.groocss.ext.StringExtension
*/
@MapConstructor
@Canonical
Expand Down
6 changes: 3 additions & 3 deletions src/main/groovy/org/groocss/Measurement.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import org.codehaus.groovy.util.HashCodeHelper

/**
* Represents some type of number value with a unit, such as 2 seconds or 20 pixels.
*
* <p>
* Measurements are created using the DSL syntax such as:
* <code>2.s //== two seconds
* <PRE>2.s //== two seconds
* 20.px //== 20 pixels
* 20.deg //== 20 degrees</code>
* 20.deg //== 20 degrees</PRE>
*
* @see org.groocss.ext.NumberExtension
* @see org.groocss.valid.DefaultValidator
Expand Down
7 changes: 7 additions & 0 deletions src/main/groovy/org/groocss/PseudoClass.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import groovy.transform.*

/**
* Represents a CSS pseudo-class such as :active, :focus, or :nthChild(odd).
* <p>
* Pseudo classes are appended to selectors using the % operator. They are chainable as well meaning
* the following is possible: <code>a %active %hover</code> becomes a:active:hover.
* <p>
* Special abbreviations exist such as "odd" for ":nthChild(odd)" and "even" for :nthChild(even).
*
* @see GrooCSS
*/
@TypeChecked
@TupleConstructor
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/org/groocss/Raw.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import groovy.transform.EqualsAndHashCode
import groovy.transform.TupleConstructor

/**
* Created by adavis on 8/9/17.
* Raw contains unescaped CSS that will be output in final CSS. Created by adavis on 8/9/17.
*/
@TupleConstructor
@EqualsAndHashCode
Expand Down
2 changes: 0 additions & 2 deletions src/main/groovy/org/groocss/valid/AbstractValidator.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.groocss.valid

import groovy.transform.AutoImplement
import groovy.transform.CompileStatic
import org.groocss.CSSPart

Expand All @@ -10,7 +9,6 @@ import org.groocss.CSSPart
* @see Processor
* @see DefaultValidator
*/
@AutoImplement(exception = Processor.NotImplementedException)
@CompileStatic
abstract class AbstractValidator<T extends CSSPart> implements Processor<T> {

Expand Down
5 changes: 5 additions & 0 deletions src/main/groovy/org/groocss/valid/DefaultValidator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import org.groocss.Style

/**
* Does default GrooCSS validation of Measurements.
* <p>Makes sure that time values are time Measurements and size values (such as top, left, width, and fontSize)
* are size values such as 1.px or 1.em or 10%.
*
* @see org.groocss.Config
* @see RequireMeasurements
*/
@CompileStatic
class DefaultValidator extends AbstractValidator<Style> implements Processor<Style> {
Expand Down
22 changes: 17 additions & 5 deletions src/main/groovy/org/groocss/valid/Processor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ package org.groocss.valid
import groovy.transform.CompileStatic
import org.groocss.CSSPart

/** Interface for defining a custom Processor that can modify or validate GrooCSS input. */
/**
* Interface for defining a custom Processor that can modify or validate GrooCSS input.
* <p>
* By extending this interface you can write your own custom validators and add them via {@link org.groocss.Config}.
* <p>
* You could also write your own Processor that modifies values in the PRE_VALIDATE phase or any other Phase.
* For example:<pre><code>
* class ConvertAllIntsToPixels implements Processor< Style > {
* Optional<String> process(Style style, Phase phase) {
* if (phase == Phase.PRE_VALIDATE && style.value instanceof Integer) {
* style.value = new Measurement(style.value, 'px')
* }
* return Optional.empty();
* }
* } </code></pre>
* @see org.groocss.Config
* */
@CompileStatic
interface Processor<T extends CSSPart> {

/** Thrown for methods that are not implemented by the processor. */
class NotImplementedException extends RuntimeException {
}

/** Enum of phases for which this Processor should be called. */
enum Phase { PRE_VALIDATE, VALIDATE, POST_VALIDATE }

Expand Down
9 changes: 8 additions & 1 deletion src/main/groovy/org/groocss/valid/RequireMeasurements.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ import groovy.transform.CompileStatic
import org.groocss.Measurement
import org.groocss.Style

/** Validates that every value that can be a Measurement is one.
/**
* Validates that every value that can be a Measurement is one. In conjunction with the
* {@link DefaultValidator} this has the effect of making sure that many values are correct.
* <p>
* You can write your own custom validators and add them via {@link org.groocss.Config}.
*
* @see Measurement
* @see org.groocss.Config
* @see DefaultValidator
*/
@CompileStatic
class RequireMeasurements extends AbstractValidator<Style> implements Processor<Style> {
Expand Down

0 comments on commit d7af532

Please sign in to comment.