Skip to content

Scripter allows you to load CSS and JavaScript files for Nette Framework

License

Notifications You must be signed in to change notification settings

DIPcms/scripter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scripter for Nette Framework

Scripter allows you to load CSS and JavaScript files for Nette Framework.

Installation

The best way to install DIPcms/Scripter is using Composer:

$ composer require dipcms/scripter

Minimal configuration

extensions:
    scripter: DIPcms\Scripter\DI\ScripterExtension

Settings

#Default settings
scripter:
    temp_dir: %tempDir% 
    url_path_name: 'getsource'
    default_syntax: 'asp' #synatxe: latte, double, asp, python, off

Rendering CSS and JS

Rendering is performed by Nette Latte (template engine) Macros are written with the help of ASP tags. It depends on the settings. You can also use:

  • latte: { ... }
  • double: {{ ... }}
  • asp: <% ... %>
  • python: {% ... %} and {{ ... }}

Details on how you can find syntax

Macros

  • <%file "font.ttf"%> Save the file to cahce and creates a link to the file.
  • <%img "images.jpg"%> Save the image to cahce and creates a link to the image.

Default macro can be found Latte

Functionality

Adding Parameters to file

   # use DIPcms\Scripter\Scripter;

   $scripter->parameter_name = "value"; 
    

Add file

   # use DIPcms\Scripter\Scripter;

   $scripter->addFile(__DIR__ . "/style.css"); 

Use

Create css file style.css

    body{
        background: <%img "bg.jpg"%>;
        width: <%$width%>px;
    }

Your application

    namespace App\Presenters;
    
    use Nette;
    use DIPcms\Scripter\Scripter;

    class HomepagePresenter extends Nette\Application\UI\Presenter{
    
        /**
        * @var Scripter @inject
        */
        public $scripter;
    
        public function renderDefault(){
            $this->scripter->width = 50;
            $this->scripter->addFile(__DIR__.'/style.css');
        }
    }

Scripter automatically add a link in the header to the CSS and JS file.

    <head>
	<meta charset="utf-8">  
        #............
        <script type="text/javascript" src="/getsource/6666cd76f96956469e7be39d750cc7d9/js"></script>
        <link rel="stylesheet" href="/getsource/6666cd76f96956469e7be39d750cc7d9/css">
    </head>

About

Scripter allows you to load CSS and JavaScript files for Nette Framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages