PHP Classes

Theme Roller: Generate CSS stylesheets with color palette themes

Recommend this page to a friend!
  Info   View files Example   Demos   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 163 This week: 1All time: 8,919 This week: 571Up
Version License PHP version Categories
themeroller 1.1MIT/X Consortium ...5HTML, PHP 5
Description 

Author

This class can generate CSS style sheets with color palette themes.

It can compose CSS style sheets by adding selectors and rules, as well default values for theme colors.

The class comes with a short themes list that are associated with year seasons with multiple styles for color palette values values.

The default theme may be taken from session variables.

The class can also generate an select form input to let the user pick the preferred theme.

The generated CSS is returned as a string but can be written to a debug file.

Picture of Gerry Danen
  Performance   Level  
Name: Gerry Danen <contact>
Classes: 3 packages by
Country: Australia Australia
Age: 74
All time rank: 219631 in Australia Australia
Week rank: 420 Up3 in Australia Australia Up

Example

<?php
// chosen theme is stored in a session variable
session_start();

require_once
'generalFunctions.inc.php';
require_once
'themeRoller.class.php';
require_once
'buildUrl.inc.php'; // prepares $themeCSS and set session variable

require_once 'themeContent.php'; // this does the same thing as theme.php, except that certain vars are now exposed

$options = ThemeRoller::themeOptionSelect();
$chosenTheme = $_SESSION['theme']['choice'];

echo <<<EOX
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico">
    <title>ThemeRoller: Danen-Dev</title>
    <link rel="stylesheet" type="text/css" href="
$themeCSS"/>
</head>
<body>
<p class="taCenter bold under">A note outside the panel-body div.</p>
<div class="panel-body">
    <h1>ThemeRoller Demo</h1>
    <p id="introText">ThemeRoller provides a simple way to manage CSS themes without the need for a pre-processor.</p>
    <p>The theme.php file calls on themeContent.php, which can be modified to add additional colours, selectors, and
        rules.</p>
    <div style="margin: 6px;padding: 8px 12px;" class="reverse-panel-body">
        <h2>Theme Palette Code:
$chosenTheme (this div uses reverse-panel-body)</h2>
       
$paletteListSelectedTheme
    </div>
    <form action="sample.php" method="get" class="rollerSpecial">
        <label for="themename">Select a theme colour:</label>
        <select name="themename" id="themename" style="width: 200px;">
           
$options
        </select>
        <button type="submit"> Go</button>
    </form>
    <p class="taRight"><a style="padding:2px 4px;background-color:#FFF;" href="sample2.php?
$queryParameters">Load sample 2</a></p>
    <div style="margin: 6px 6px 16px 6px;padding: 8px 12px 18px 12px;" class="grnDark yelLightBackground">
        <h2>Palette</h2>
       
$paletteList
    </div>
    <div style="margin: 6px;padding: 8px 12px;" class="themeColorDark themeColorLightBackground">
        <h2>CSS generated and used</h2>
        <pre class="themeColorDark themeColorLightBackground">
$rollerCSS</pre>
    </div>
    <br>
</div>
</body>
</html>
EOX;


Details

Theme Roller

Version 1.0.1 23 May 2016

Theme Roller creates CSS style sheets on the fly. Palettes for the chosen theme are created, as well as "all-color" palettes.

Components to make Theme Roller work: * themeRoller.class.php - the class file * sample.php - sample script to test functionality * sample2.php - sample script to test functionality * theme.php - the generated CSS style sheet (output as a CSS string) * themeStrings.php - like theme.php, but this file exposes certain variables that may come in handy in debugging * themeContent.php - the CSS directives go here; used by theme.php and themeStrings.php * readme.md - instructions

themeRoller.class.php

There are 2 static functions for use: * selectTheme() - checks $_SESSION['theme']['choice'] to get the desired theme code; if not found, the designated default code is returned. * themeOptionSelect() - returns a list of theme options to select from

Instantiate the Theme Roller object like this:

> $roller = new ThemeRoller($theme, 'Colour theme: {{theme-title}}');

where $theme is the theme code (can be obtained from selectTheme() or set specifically) and the second parameter is the title that will go in the CSS file.

Functions available:

  • ->addSelector(selector, comment) * selector, like 'body', '.className', or '#idName' * comment (optional), selector comment
  • ->addRule(rule, value) * rule, like 'color', or 'background-color' * value, like '#E8ECFF'
  • ->getThemeDefValue(definition) * definition, like 'color', or 'background-color'
  • ->generateCSS() * generates CSS, and palette files

themeContent.php

This file contains the rules to generate the CSS styles.

Debug functionality

Comprehensive debug functionality is built in. This is also useful for learning how the class works internally. Make sure the debug directory is writeable. Currently set to /data/debug/, you may change that to suit your needs.

License

The MIT License (MIT)

Copyright (c) 2016 Gerry Danen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


  theme_rollerExternal page  

Open in a separate window

  Files folder image Files  
File Role Description
Accessible without login Plain text file buildUrl.inc.php Appl. Helper script
Accessible without login Plain text file generalFunctions.inc.php Aux. Helper script
Accessible without login Plain text file readme.md Doc. documentation
Accessible without login Plain text file sample.php Example Sample usage
Accessible without login Plain text file sample2.php Example Example file
Accessible without login Plain text file theme.php Appl. Generated CSS
Accessible without login Plain text file themeContent.php Appl. CSS rules
Plain text file themeRoller.class.php Class Class file
Accessible without login Plain text file themeStrings.php Aux. Helper script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:163
This week:1
All time:8,919
This week:571Up