2017 © Pedro Pelรกez
 

library steroids

Laravel 4 Blade on Steroids

image

pragmarx/steroids

Laravel 4 Blade on Steroids

  • Friday, July 21, 2017
  • by AntonioCarlosRibeiro
  • Repository
  • 9 Watchers
  • 103 Stars
  • 189 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

Steroids v0.7

Latest Stable Version License Build Status Latest Stable Version, (*1)

Laravel 4 Blade on Steroids

This package provides some aditional features to Laravel Blade:, (*2)

Automatic command generation

Create a file named <command>.blade.php in the templates directory and it automatically becomes a blade command., (*3)

Take the file, (*4)

default\css.blade.php

Whaving the contents:, (*5)

<link rel="stylesheet" type="text/css" media="screen" href="@_1">

Hackers can now use the command, (*6)

@css(/css/bootstrap.css)

In their blade templates to generate:, (*7)

<link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.css">

Subtemplating

Every sublevel in your template directory creates a level in command name. This tree:, (*8)

โ”œโ”€โ”€ default
โ”‚ย ย  โ”œโ”€โ”€ input.blade.php
โ”‚ย ย  โ”œโ”€โ”€ js.blade.php
โ”‚ย ย  โ””โ”€โ”€ php.blade.php
โ”‚ย ย  โ””โ”€โ”€ text.blade.php
โ”œโ”€โ”€ bs
โ”‚ย ย  โ””โ”€โ”€ v2
โ”‚ย ย  โ”‚   โ”œโ”€โ”€ input.blade.php
โ”‚ย ย  โ”‚   โ””โ”€โ”€ form.blade.php
โ”‚ย ย  โ”‚   โ””โ”€โ”€ model.blade.php
โ”‚ย ย  โ”œโ”€โ”€ input.blade.php
โ”‚ย ย  โ””โ”€โ”€ form.blade.php

Would give you the following commands:, (*9)

@input()
@js()
@php()
@text()

@bs.input()
@bs.form()

@bs.v2.input()
@bs.v2.form()
@bs.v2.model()

Block commands

Let's take the (silly, I know! :) @php (file php.blade.php) command as an example of a block:, (*10)

@php
    $title = 'subscribe';
@@

Note that a block ends with @@ and you can have as many nested blocks as you want. This is the @php command's source code:, (*11)

<?php 
    @_BODY;
?>

It's that simple, to create a block command you just have to add the @_BODY identifier in any part of your command., (*12)

Extending commands

You can create an @input command:, (*13)

<input type="@_1" @_ATTRIBUTES />

And use it to create a, (*14)

@text:, (*15)

@input(text,@_PARAMETERS)

@email:, (*16)

@input(email,@_PARAMETERS)

and @password commands:, (*17)

@input(password,@_PARAMETERS)

HTML Attributes, Local Variables and Positional Parameters

You can dynamically create and send any number of parameters to your commands:, (*18)

HTML Attributes

Take @input as an example:, (*19)

@input(type=email,class=form-control,id=example,placeholder=Enter email)

Having this template, (*20)

<input @_ATTRIBUTES />

It will generate this tag:, (*21)

<input type="email" class="form-control" id="example" placeholder="Enter email">

Local Variables

Use a hash to define a local variable:, (*22)

@input(#type=email,class=form-control,id=example,placeholder=Enter email)

And you access it by using the variable identifier @_:, (*23)

<input type="@_type" @_ATTRIBUTES />

Positional Parameters

You also can access any of yours parameter by the number, let's set the type of input as the first one:, (*24)

@input(email,class=form-control,id=example,placeholder=Enter email)

Then you just have to use the variable identifier followed by the parameter number:, (*25)

<input type="@_1" @_ATTRIBUTES />

Another example is the Form::model(), provided by @model, this is the template, (*26)

{{ Form::model(@_1, $options) }}
    @_BODY
{{ Form::close() }}

And in your view you just have to:, (*27)

@model($user,url=/profile)
    ... your controls ...
@@

Assignment and Multi Assignment

You assign values to local (#) variables by using the equal sign:, (*28)

@text(#label=form-control)

You assign values to html attributes by doing the same, just don't put the hash sign:, (*29)

@text(class=form-control)

And you can also do multi assignments:, (*30)

@text(#label=title=First Name,class=form-control)

Superglobals (licentia poetica)

@_BODY: will be replaced by your command body, (*31)

@_ATTRIBUTES: all HTML attributes generated by your command, (*32)

@_PARAMETERS: it's a raw list of parameters, you can use it to pass them forward to an extended command, this is the source of @text, which extends @input:, (*33)

@if (@_name->has)
    @input(text,name=@_1,@_PARAMETERS)
@else
    @input(text,@_PARAMETERS)
@endif

@_SINGLE: if you have a command that accepts only one parameter, (*34)

@h1(Hi There!)

You can use this superglobal:, (*35)

<h1>@_SINGLE</h1>

But you can still use the positional variable:, (*36)

<h1>@_1</h1>

Special functions

->has

If you need to know if a variable was set you can use the ->has function:, (*37)

@if (@_label->has) 
    <label class="label">@_label</label>
@endif
<input type="@_1" @_ATTRIBUTES />

The ->has function will return true or false, and then your view (in PHP) would probably look like this:, (*38)

<?php if (false): ?>
    <label class="label"></label>
<?php endif; ?>
<input type="email" ... />

Steroids comes with some examples:, (*39)

->bare

If you need to access one of your HTML attributes you can use the ->bare function:, (*40)

<input type="@_1" class="@_class->bare" />

Delimiters and Quotation marks

As delimiters of your parameters you can use , or ;:, (*41)

@input(email,class=form-control,id=example,placeholder=Enter email)

@input(email;class=form-control;id=example;placeholder=Enter email)

You don't need to use quotation marks (single ' or double "), unless you need to use any of those delimiters in your strings:, (*42)

@input(email,placeholder="Hello, World!")

Examples

Steroids comes with some examples, but you can get crazy and create as many as you wish:, (*43)

โ”œโ”€โ”€ default
โ”‚ย ย  โ”œโ”€โ”€ css.blade.php
โ”‚ย ย  โ”œโ”€โ”€ form.blade.php
โ”‚ย ย  โ”œโ”€โ”€ h.blade.php
โ”‚ย ย  โ”œโ”€โ”€ input.blade.php
โ”‚ย ย  โ”œโ”€โ”€ js.blade.php
โ”‚ย ย  โ”œโ”€โ”€ model.blade.php
โ”‚ย ย  โ”œโ”€โ”€ p.blade.php
โ”‚ย ย  โ”œโ”€โ”€ php.blade.php
โ”‚ย ย  โ”œโ”€โ”€ row.blade.php
โ”‚ย ย  โ””โ”€โ”€ text.blade.php
โ”œโ”€โ”€ bs
โ”‚ย ย  โ”œโ”€โ”€ md.blade.php
โ”‚ย ย  โ””โ”€โ”€ xs.blade.php

Easy creation of partials

Sometimes creating s simple box can be as complicated as:, (*44)

<div class="row">
    <article class="col-sm-12 col-md-12 col-lg-12">
            <div>
                <div class="jarviswidget-editbox">
                    @editbox('your name goes here')
                </div>

                <div class="widget-body no-padding">
                    @_BODY
                </div>
            </div>
        </div>
    </article>
</div>

But after Steroids, you just need to do this in your code:, (*45)

@box
    And do whatever you need inside it!
@@

Artisan Commands

Steroids has two artisan commands:, (*46)

steroids:templates - to copy the examples to your app/config/package folder, (*47)

php artisan steroids:templates

steroids:list - list all of your Steroids commands, (*48)

php artisan steroids:list

view:clear - to clear you views cache, (*49)

php artisan view:clear

Using the Facade directly

To compile a view using Steroids, you just have to:, (*50)

 return Steroids::inject('@input(type=email,name=email,class=form-control)')

Installation

Requirements

  • Laravel 4.1+
  • Composer >= 2014-01-07 - This is a PSR-4 package

Installing

Require the Steroids package:, (*51)

composer require pragmarx/steroids dev-master

Add the service provider to your app/config/app.php:, (*52)

'PragmaRX\Steroids\Vendor\Laravel\ServiceProvider',

To publish the configuration file you'll have to:, (*53)

php artisan config:publish pragmarx/steroids

Copy the templates examples to your app folder:, (*54)

php artisan steroids:templates

Tests

  • Steroids Tests Coverage is at 100%

TODO

  • Invalidate main templates when a Steroids command changes

Author

Antonio Carlos Ribeiro, (*55)

License

Steroids is licensed under the BSD 3-Clause License - see the LICENSE file for details, (*56)

Contributing

Pull requests and issues are more than welcome., (*57)

The Versions

21/07 2017

dev-master

9999999-dev

Laravel 4 Blade on Steroids

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel template blade view

21/07 2017

v0.8.3

0.8.3.0

Laravel 4 Blade on Steroids

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel template blade view

21/07 2017

v0.8.2

0.8.2.0

Laravel 4 Blade on Steroids

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel template blade view

18/02 2015

v0.8.1

0.8.1.0

Laravel 4 Blade on Steroids

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

laravel template blade view

19/03 2014

v0.8.0

0.8.0.0

Laravel 4 Blade on Steroids

  Sources   Download

MIT

The Requires

 

The Development Requires

by eRobin

laravel blacklist whitelist steroids

05/03 2014

v0.7.3

0.7.3.0

Laravel 4 Blade on Steroids

  Sources   Download

MIT

The Requires

 

The Development Requires

by eRobin

laravel blacklist whitelist steroids

03/03 2014

v0.7.2

0.7.2.0

Laravel 4 Blade on Steroids

  Sources   Download

MIT

The Requires

 

The Development Requires

by eRobin

laravel blacklist whitelist steroids

02/03 2014

v0.7.1

0.7.1.0

Laravel 4 Blade on Steroids

  Sources   Download

MIT

The Requires

 

The Development Requires

by eRobin

laravel blacklist whitelist steroids

28/02 2014

v0.7.0

0.7.0.0

Laravel 4 Blade on Steroids

  Sources   Download

MIT

The Requires

 

The Development Requires

by eRobin

laravel blacklist whitelist steroids