fritak/nette-dynamic-loader

Dynamic loader for nette, using bower.

1.2.2 2015-06-01 12:07 UTC

This package is not auto-updated.

Last update: 2024-04-27 14:38:40 UTC


README

This is a dummy dynamic loader for nette.

##Getting started

  1. Download all plugins via bower, install in PATH: PLUGIN_NAME/css and PLUGIN_NAME/js (Unfortunately, there is currently no other path possible) You can do it nicely with Bower installer (bower.json):
  "dependencies": {
    "jquery": "~2.1.3",
    "jquery-ui": "~1.11.4",
    "bootstrap": "~3.3.4",
  },
  "install": {
    "path": {
        "css": "plugins/{name}/css",
        "js": "plugins/{name}/js",
        "/[sc|le]ss$/": "plugins/{name}/css",
        "eot": "plugins/{name}/fonts",
        "svg": "plugins/{name}/fonts",
        "ttf": "plugins/{name}/fonts",
        "woff": "plugins/{name}/fonts",
        "woff2": "plugins/{name}/fonts",
        "otf": "plugins/{name}/fonts",
        "png":  "plugins/{name}/css/images"
    }
  1. Prefered install method is via composer
composer require fritak/nette-dynamic-loader
  1. Register at config.neon with parameters a for caching
parameters:
    loader:
        bowerJson:  '/var/www/bower.json' # Path to your bower file
        pluginPath: '/var/www/plugins/'   # Path to installed plugins (see item 0)
services:
	- DynamicLoader\Loader(%loader%, @cacheStorage)
  1. Create component (eg. in BasePresenter)
    use DynamicLoader\Loader;

    public function createComponentHeadLoader() 
    {
        $component = clone $this->context->getByType('DynamicLoader\Loader');
        $component->renderPosition = Loader::POSITION_HEAD;
        return $component;
    }
    
    public function createComponentBottomLoader() 
    {
        $component = clone $this->context->getByType('DynamicLoader\Loader');
        $component->renderPosition = Loader::POSITION_BOTT;
        return $component;
    }
  1. Add control to a template (eg. @layout)
{control dynamicLoader}
  1. And that's it! You can control it with following config:
parameters:
    loader:
        defaultCSS: DynamicLoader\Loader::POSITION_HEAD #Defaut CSS position
        defaultJS:  DynamicLoader\Loader::POSITION_BOTT #Defaut JS  position
        renderAll:  1                                   # Render ALL added plugins
        bowerJson:  '/var/project/www/bower.json'       # Path to your bower file
        basePath:   '/project/www'                      # If you have different basePath than is default
        pluginPath: '/var/project/www/plugins/'         # Path to installed plugins (see item 0)
        disableBar: 1                                   # You can disable debug bar
        positionsHead:                                  # You can set plugins positions in HEAD OR BOTT directly:
            - 'bootstrap.min.css'
        positionsBott:
            - 'bootstrap.min.js'
  1. You can set default plugins global
        defaultPlugins:                                 
            - 'jquery'
            - 'jquery-ui'
            - 'bootstrap'
  1. Or in groups. But then you have to set GROUP to a component.
        defaultPlugins:                                 
            front:
                - 'jquery'
            backEnd: 
                - 'jquery'
                - 'jquery-ui'
                - 'bootstrap'
  1. If you set defaultPlugins, others won't be loaded. So you have to set them manually in presenters (eg. in HomepagePresenter):
    public function __construct() 
    {
        $this->enablePlugins = ['jquery-ui'];
        parent::__construct();
    }
  1. And edit basePresenter:
    public $enablePlugins = [];

    public function createComponentHeadLoader() 
    {
        $component = clone $this->context->getByType('\DynamicLoader\Loader');
        $component->renderPosition = Loader::POSITION_HEAD;
        $component->enablePlugins = $this->enablePlugins;
        $component->group = 'front';
        return $component;
    }
    
    public function createComponentBottomLoader() 
    {
        $component = clone $this->context->getByType('\DynamicLoader\Loader');
        $component->renderPosition = Loader::POSITION_BOTT;
        $component->enablePlugins = $this->enablePlugins;
        $component->group = 'front';
        return $component;
    }

Links