• Stars
    star
    125
  • Rank 285,455 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 3 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library that makes it simple to parse, analyze, and manipulate Blade templates. Designed with tool makers in mind ❤️

Blade Parser is library for Laravel that makes it easy to parse, analyze, and manipulate Blade templates.

The library is composed of many major components:

  • Parser: A Blade parser that produces a list of nodes, which can be analyzed to help make decisions surrounding a template.
  • Documents: A powerful abstraction that makes it much simpler to interact with the details of a single parsed Blade template.
  • Workspaces: A simple set of APIs that make it effortless to work with multiple parsed Blade templates at once.
  • Compiler: A highly configurable Blade compiler implementation, with support for precompilers, extensions, and existing third-party packages.
  • Validator: An extensible system for validating Blade documents, with default validators capable of detecting unpaired conditions, invalid component parameter spacing, and much more.

Simple to Use

Parsing Blade templates is incredibly simple using the Documents API. As an example, this is all that is needed to parse a template:

<?php
 
use Stillat\BladeParser\Document\Document;
 
$template = <<<'BLADE'
    Hello, {{ $world }}
BLADE;
 
$document = Document::fromText($template);

The Document class provides a powerful abstraction, making it simple to quickly retrieve information about a template.

For instance, if we wanted to extract all the components from our template we could do this:

<?php

// Do something with all component tags in the template.
$document->getComponents()
          ->each(fn($node) => ...);

If we were only interested in a component named alert, we could instead use:

<?php

// Find all "alert" components.
$document->findComponentsByTagName('alert')
         ->each(fn($node) => ...);

These examples hardly scratch the surface, and you are encouraged to read through the Documentation.

Built-in Validation Command

This library also ships with a configurable blade:validate Artisan command which can be used to validate all Blade templates within a project.

To configure the command, you will need to publish its configuration files using the following command:

php artisan vendor:publish --tag=blade

To run the validation against your project, you can issue the following Artisan command:

php artisan blade:validate

If any validation issues were detected they will be displayed in your terminal.

There are many configuration options available, and if you'd like to learn more you can find them documented in the Configuring the Validate Command article.

License

This parser library is open-sourced software licensed under the MIT license.

More Repositories

1

blade-parser-typescript

A Laravel Blade parser, compiler, and static analyzer written in TypeScript.
TypeScript
81
star
2

vscode-antlers-language-server

Provides rich language features for Statamic's Antlers templating language, including code completions, syntax highlighting, and more.
TypeScript
36
star
3

relationships

Provides automated bi-directional @statamic entry relationships
PHP
18
star
4

antlers-components

Makes it easy to integrate Blade and Livewire components into an Antlers template, and create isolated, reusable Antlers components utilizing partials.
PHP
16
star
5

proteus

A library to read, modify, and write Laravel-style PHP configuration files.
PHP
9
star
6

statamic-site-essentials

A collection of features to rapidly build and deploy @statamic sites.
PHP
7
star
7

the-agency-starter-kit

The Agency is a free Statamic Starter Kit designed as an example of utilizing various techniques to implement a highly customized Statamic experience.
PHP
7
star
8

hybrid-cache-system-for-statamic

An example custom cache implementation for Statamic, providing near static-HTML response times while preserving text editor based workflows.
PHP
6
star
9

the-hook-template-for-statamic-3

An example Statamic 3 project that implements multiple layouts, infinite scrolling, and more.
PHP
5
star
10

Collection

A reusable standalone Collection class, pulled from Laravel.
PHP
5
star
11

meerkat-statamic3

Meerkat 2 is an extremely powerful and easy-to-use comment platform for Statamic 3.
PHP
5
star
12

social-media-image-kit

Social Media Image Kit is a @statamic addon that provides a framework to help generate social media images for collection entries using Antlers or Blade templates.
PHP
4
star
13

blade-directives

A package that makes writing Laravel Blade directives easier when requiring multiple parameters.
PHP
4
star
14

kode-template-for-statamic-3

A simple, single-author programming blog sample project, built using Statamic 3.
PHP
3
star
15

antlers-translation-strings-exporter

Provides utilities for exporting translation strings from both Antlers and Blade template files.
PHP
2
star
16

tidal-multisite

Tidal Multi-site is a free, open-source, documentation-focused starter kit for @statamic. Tidal supports multiple projects, multiple versions per-project, and entry localization.
PHP
2
star
17

Common

Useful features 'commonly' used in other larger packages and applications
PHP
1
star
18

docs

Documentation for Stillat
1
star
19

Menu

Laravel 4 component for menus with fast rendering times.
PHP
1
star
20

tanager

A free @Statamic theme.
CSS
1
star
21

statamic-bard-heading-permalinks

Provides a permalink extension for Bard that is compatible with Statamic's markdown settings.
PHP
1
star
22

laravel-volt-precompiler-example

Example repository containing an experimental Blade precompiler, which compiles custom component syntax to class-based Livewire Volt components.
PHP
1
star
23

primitives

Converts string input into PHP runtime values.
PHP
1
star
24

documentation-search

Documentation Search provides a custom Statamic Search provider, targeted at documentation websites.
PHP
1
star