1<?php
2/**
3 * Copyright (c) 2020. ComboStrap, Inc. and its affiliates. All Rights Reserved.
4 *
5 * This source code is licensed under the GPL license found in the
6 * COPYING  file in the root directory of this source tree.
7 *
8 * @license  GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html)
9 * @author   ComboStrap <support@combostrap.com>
10 *
11 */
12
13namespace ComboStrap;
14
15require_once(__DIR__ . '/StringUtility.php');
16
17class StyleUtility
18{
19
20    public static function getRule(array $styles, $selector)
21    {
22        $rule = $selector." {".DOKU_LF;
23        foreach ($styles as $key => $value){
24            $rule .= "    $key:$value;".DOKU_LF;
25        }
26        StringUtility::rtrim($rule,";");
27        return $rule.DOKU_LF."}".DOKU_LF;
28
29    }
30
31    /**
32     * @param array $array of property as key and value
33     * @return string a html inline style property
34     */
35    public static function createInlineValue(array $array)
36    {
37        $inline = "";
38        foreach ($array as $property => $value) {
39            if ($inline!="") {
40                $inline .= ";$property:$value";
41            } else {
42                $inline = "$property:$value";
43            }
44        }
45        return $inline;
46
47    }
48
49    /**
50     * Add class for user styling
51     * See
52     * https://combostrap.com/styling/userstyle#class
53     * @param TagAttributes $param
54     */
55    public static function addStylingClass(TagAttributes &$param)
56    {
57        $logicalTag = $param->getLogicalTag();
58        if ($logicalTag!==null && $param->getDefaultStyleClassShouldBeAdded() === true) {
59
60            $param->addClassName($logicalTag . "-combo");
61            if (!empty($param->getType())) {
62                $param->addClassName($logicalTag . "-" . $param->getType() . "-combo");
63            }
64        }
65    }
66}
67