Subversion Repositories PHPX

Rev

Rev 37 | Blame | Compare with Previous | Last modification | View Log | RSS feed

1
<?php

namespace de\pointedears\css\least;

/**
 * Mix-ins for the LEAST CSS preprocessor
 *
 * @author Thomas 'PointedEars' Lahn &lt;php@PointedEars.de&gt;
 */

abstract class Mixins
{
        /** @section General functions */
       
  /**
   * Generates a CSS section for each keyword prefix.
   *
   * @param string $keyword
   *  Section keyword
   * @param string $params
   *   Section parameters (name, medium, etc.)
   * @param string $content
   *   Section content
   * @param array[string] $prefixes
   *   Keyword prefixes
   */

        public static function prefix_section ($keyword, $params,
          $content, array $prefixes)
  {
    ob_start();
    foreach ($prefixes as $prefix)
    {
      echo "@{$prefix}{$keyword} {$params} {\n  {$content}\n}\n";
    }
    ob_end_flush();
        }
 
  /**
   * Generates a CSS property declaration whose value is a
   * function call, for each function name prefix.
   *
   * @param string $property
   *   Property to be declared
   * @param string $function
   *   CSS function to be called
   * @param string $args
   *   Arguments to the function
   * @param array[string] $prefixes
   *   Function name prefixes
   */

  public static function prefix_function ($property, $function, $args,
    array $prefixes)
  {
    ob_start();
    foreach ($prefixes as $prefix)
    {
      echo "{$property}: {$prefix}{$function}({$args});\n";
    }
    ob_end_flush();
  }
 
  /**
   * Generates a CSS property declaration for each
   * property name prefix.
   *
   * @param string $suffix
   *   Property name suffix
   * @param string $value
   *   Property value
   * @param array[string] $prefixes
   *   Property name prefixes
   */

  public static function prefix_property ($property, $suffix, $value,
    array $prefixes)
  {
    ob_start();
    foreach ($prefixes as $prefix)
    {
      echo "{$prefix}{$property}{$suffix}: {$value};\n";
    }
    ob_end_flush();
  }
 
        /** @section Gradients */
       
  /**
   * Generates a CSS property declaration whose value is a
   * <code>linear-gradient()</code> function call for
   * each function name prefix.
   *
   * @param string $property
   *   Property to be declared
   * @param string $args
   *   Arguments to the <code>linear-gradient()</code> function
   * @param array[string] $prefixes (optional)
   *   Pass to override supported function name prefixes
   * @see self::prefix_function()
   */

  public static function linear_gradient ($property, $args,
    array $prefixes = array('-moz-', '-o-', '-webkit-', ''))
  {
    self::prefix_function($property, 'linear-gradient', $args, $prefixes);
        }

  /**
   * Generates a CSS property declaration whose value is a
   * <code>radial-gradient()</code> function call for each
   * function name prefix.
   *
   * @param string $property
   *   Property to be declared
   * @param string $args
   *   Arguments to the <code>radial-gradient()</code> function
   * @param array[string] $prefixes (optional)
   *   Pass to override supported function name prefixes
   * @see self::prefix_function()
   */

        public static function radial_gradient ($property, $args,
    array $prefixes = array('-moz-', '-webkit-'))
  {
    self::prefix_function($property, 'radial-gradient', $args, $prefixes);
        }
       
  /**
   * Generates a CSS <code>transition</code> property declaration
   * for each property name prefix.
   *
   * @param string $suffix
   *   Property name suffix
   * @param string $value
   *   Property value
   * @param array[string] $prefixes (optional)
   *   Pass to override supported property name prefixes
   * @see self::prefix_property()
   */

        public static function transition ($suffix, $value,
    array $prefixes = array('-moz-', '-webkit-', ''))
  {
    self::prefix_property('transition', $suffix, $value, $prefixes);
        }

        /** @section Animations */
       
  /**
   * Generates a CSS <code>@keyframes</code> section for
   * each keyword prefix.
   *
   * @param string $name
   *   Animation name as referred by an <code>animation-name</code>
   *   property value.
   * @param string $data
   *   Keyframes data
   * @param array[string] $prefixes (optional)
   *   Pass to override supported keyword prefixes
   * @see self::prefix_section()
   */

        public static function keyframes ($name, $data,
    array $prefixes = array('-moz-', '-webkit-', ''))
  {
    self::prefix_section('keyframes', $name, $data, $prefixes);
        }

  /**
   * Generates a CSS <code>animation</code> property declaration
   * for each property name prefix.
   *
   * @param string $suffix
   *   Property name suffix, e.g. <tt>"-name"</tt> for
   *   <code>animation-name</code>
   * @param string $value
   *   Property value
   * @param array[string] $prefixes (optional)
   *   Pass to override supported property name prefixes
   * @see self::prefix_property()
   */

        public static function animation ($suffix, $value,
    array $prefixes = array('-moz-', '-webkit-', ''))
  {
    self::prefix_property('animation', $suffix, $value, $prefixes);
        }
}