roggeo/glance

Glance - PHP 网站主题管理器

dev-master 2016-03-04 02:59 UTC

This package is not auto-updated.

Last update: 2024-09-24 04:10:01 UTC


README

#Glance

###PHP APPs 主题管理器

##为什么使用?

使用主题管理器,您可以分离您的样式(如 CSS、JS、图片等)在您的 Web 应用程序中,无需过多担心模板文件(如 .tpl、.html、.phtml 等)中的 URI 变更。

例如,要获取样式文件,您只需使用

$theme->css("custom.css");

或者所有 CSS。

$theme->css();

查看几个示例查看一个演示

##安装

    1. 运行以下命令
$ mkdir your_project
$ cd your_project
$ php -r "readfile('https://composer.php.ac.cn/installer');" | php
    1. 创建一个文件 your_project/composer.json,内容如下
{
    "require": {
        "roggeo/glance": "dev-master"
    }
}
    1. 运行以下命令
$ php composer.phar update

或者(如果您已安装 Composer),在您的应用程序文件夹中运行以下命令

$ mkdir your_project
$ cd your_project
$ composer require roggeo/glance:dev-master

##如何使用?

    1. 创建一个文件 your-folder-themes/config.yml
# Name of the themes, if enabled tell true
themes:
    "sometheme1":
    "sometheme2":
    "sometheme3": true
    "sometheme4":
    1. 创建一个文件 your-folder-themes/your-theme/theme.yml
#Information of a specific theme
theme  : Litht
author : Geovani
email  : name@email.com
date   : 2015-11-08
license: https://open-source.org.cn/licenses/MIT
link   : https://yoursite.com
description: >
    Theme default for Glance
    1. 您的主题库应该有一个基本结构,例如:theme(保存所有主题的文件夹),lightdark 是主题示例。文件夹 light 中的文件是 Glance 主题的基本结构。请看一个图片

Glance Explorer

    1. 创建一个文件 public/theme/index.php,并插入以下代码
require_once __DIR__.'/../../vendor/autoload.php';
use Glance\Response;
Response::listenMessage();
    1. 创建一个文件 public/theme/.htaccess,并插入以下代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?get=$1 [L]
</IfModule>

##Glance 主题说明

主题,查看一个示例。

演示,查看如何使用。

##方法

...
//code configuration
...


//images
$theme->img("name-image", "png");
$theme->img(array("image-1","image-2"), "png");
$theme->img("name-image.jpg");


//css
$theme->css("custon.css");
$theme->css(array("custon", "main"));
$theme->css(array("custon.css", "main"));
$theme->css();


//javascript
$theme->js("custon.js");
$theme->js(array("custon", "main"));
$theme->js(array("custon.js", "main"));
$theme->js();


//Call files of another Theme
$theme->css('side','dark');
$theme->js('home', 'dark');
$theme->img('book','png','dark');
$theme->enqueue('img/book.png','dark');


//All
$theme->enqueue('image.png');
$theme->assets('style.css','bootstrap');

##在您的网页中

在您的项目根目录创建一个 index.php,内容如下

<?php
include "vendor/autoload.php";

use Glance\Glance,
    Glance\Config;

$conf = new Config();

// Defining folder repository of all yours themes
$conf->setFolderTheme('C:\\themes');

$theme = new Glance($conf);

?>

<html>
    <head>
        <title>Theme Light</title>
        <meta charset="UTF-8">
	<?php $theme->css();?>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>Theme Light default Glance</div>
        <?=$theme->enqueue('img/light.jpg')?>
        <br />
        <br />
        <?=$theme->img('light.jpg')?>
        <br />
        Or
        <br />
        <?=$theme->img('light')?>
        <br />
        <br />
        <br />
        <?php
        foreach($theme->img(array("books1","books2"), "png") as $book):            
            echo "$book<br/>";            
        endforeach;        
        ?>
        <?=$theme->js('light')?>
        
        <div>
            <p>Other theme</p>
            <ul>
                <li><?=$theme->css('side','dark')?></li>
                <li><?=$theme->js('home')?></li>
                <li><?=$theme->img('book','png','dark')?></li>
                <li><?=$theme->enqueue('img/book.png','dark')?></li>
            </ul>
            <?php
            foreach ($theme->enqueue(array('img/book.png'), 'dark') as $book):
                echo "$book<br/>";
            endforeach;
            ?>
            
        </div>
        <div>
            <?php echo $theme->img('books1')?>
            <br/>
            <?php echo $theme->assets('style.css','bootstrap')?>
        </div>
        
    </body>
</html>

##测试

使用 PHPUnit 进行测试,之后使用上述 Composer 建议进行

更多 PHPUnit 详情

    $ cd you_project/vendor/roggeo/glance
    $ phpunit

##贡献

如果您对此项目感兴趣,您可以帮助改进此项目。请查看如何

##许可