Coder Social home page Coder Social logo

laravel-theme-system's Introduction

Laravel Theme System

In this repository, you can find the theme system for the framework PHP, Laravel 7

Installation

  • firstly run composer require isaeken/laravel-theme-system in your project folder

  • migrate new tables to your database using php artisan migrate

  • create a theme

    .
    ├── assets            <- Your asset folder
    │   ├── css
    │   │   └── app.css
    │   └── js
    │       └── app.js
    ├── views             <- Your view folder
    │   └── home.blade.php
    ├── details.json      <- Your theme details
    └── settings.json     <- Your theme settings
    
    • in details.json
      {
          "name": "Your Theme Name",
          "description": "This is your first!",
          "version": "1.0",
          "authors": [
              {
                  "name": "İsa Eken",
                  "email": "[email protected]"
              }
          ]
      }
    • Note: You can blank to settings.json but this file is required.
    • Convert to zip these files.
  • Install your default theme to your project using php

    /**
     * Install a theme file to project
     * @param string $themeFile
     * @param bool $setDefault
     * @return object
     */
    \IsaEken\ThemeSystem\ThemeSystem::install('/your/theme/file.zip', true);

Usage

Show a view from controller

<?php
namespace App\Http\Controllers;
use IsaEken\ThemeSystem\ThemeSystem;

class HomeController extends Controller
{
    public function index()
    {
        $yourData = time();
        $yourSecondData = date(time());
        return ThemeSystem::view('index', compact('yourData', 'yourSecondData'));
    }
}

Change theme for client

$theme = \IsaEken\ThemeSystem\Models\Theme::where('name', 'theme_name')->first();
\IsaEken\ThemeSystem\ThemeSystem::change($theme);

Check theme is installed

if (\IsaEken\ThemeSystem\ThemeSystem::isInstalled('theme_name')) echo 'installed';
else echo 'not installed';

Change default theme

$theme = \IsaEken\ThemeSystem\Models\Theme::where('name', 'theme_name')->first();
\IsaEken\ThemeSystem\ThemeSystem::setDefault($theme);

Uninstall theme

/**
 * @param string $themeName
 * @param bool $withFiles = false
 * @param bool $forceDelete = false
 * @return bool
 */
\IsaEken\ThemeSystem\ThemeSystem::uninstall('theme_name', true, true);

Get current theme for client

/**
 * @return \IsaEken\ThemeSystem\Models\Theme|null
 */
\IsaEken\ThemeSystem\ThemeSystem::theme();

Helpers

/**
 * Get url of client theme asset.
 *
 * @param string $asset
 * @return string
 */
theme_asset('css/app.css');

/**
 * Get setting of client theme.
 *
 * @param string $key
 * @return mixed
 */
theme_setting('key.in.settings.json');

/**
 * Get detail of client theme.
 *
 * @param string $key
 * @return mixed
 */
theme_detail('name');

/**
 * Check current page is $page.
 *
 * @param string $page
 * @return bool
 */
ispage('your.route.name');

/**
 * Minify StyleSheet
 *
 * @param string $css
 * @return string
 */
minifyCSS(<<<EOF
body {
    background-color: red;
}
EOF
);

/**
 * Minify JavaScript
 *
 * @param string $javascript
 * @return string
 */
minifyJS(<<<EOF
$(document).ready(() => {
    console.log('Document is ready!');
});
EOF
);

Blade helpers

@themeSetting('key.in.settings.json')
    YES
@else
    NO
@endif

@page('your.route.name')
    current page is first page
@elsepage('your.second.route.name')
    current page is second page
@else
    unknown page
@endpage

Other

/**
 * Set caching for assets is enabled or disabled. (Recommended for production)
 */
\IsaEken\ThemeSystem\ThemeSystem::$cacheAssets = false;

/**
 * Set compress assets is enabled or disabled. (If enabled check your assets running correctly!)
 */
\IsaEken\ThemeSystem\ThemeSystem::$compressAssets = false;

laravel-theme-system's People

Contributors

isaeken avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.