Giter VIP home page Giter VIP logo

stringbladecompiler's People

Contributors

adamgaskins avatar avengerweb avatar bretto36 avatar erik-ropez avatar gjm avatar jorgedroid avatar jpscharf avatar luukvdo avatar mikerogne avatar rrrhys avatar ryllaz avatar superseb92 avatar terreporter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

stringbladecompiler's Issues

Class 'StringCompilerException' not found

In Laravel 5 I'm getting the following error (obviously I understand why this is appearing)

FatalErrorException in StringView.php line 68:
Class 'StringCompilerException' not found in StringView.php line 68

Why not extend?

Hi,

I have started using this extension as a base for this one that I'm currently writing: https://github.com/delatbabel/viewpages

I have a question relating to your build, I'm currently using the 3.0 branch. Maybe I'm missing something so perhaps you can explain it to me a bit better.

Why aren't you making your classes extend the Laravel base classes and use the functionality that's already there? For example your Wpb\String_Blade_Compiler\Factory class could extend Illuminate\View\Factory and only change what is required.

If you did extend then, for example, your make() function could look like this:

        if (is_array($view)) {
            $engine = $this->engines->resolve('stringblade');
            $data = array_merge($mergeData, $this->parseData($data));
            $this->callCreator($view = new StringView($this, $engine, $view, 'not-used', $data));
            return $view;
        }
        // else
        return parent::make($view, $data, $mergeData);

... thus saving about half of the code that you need to create.

It seems so obvious to me that I think that I'm missing something as to why this can't be done.

Usage with barryvdh/laravel-debugbar

Just a note, here as a submitted patch has not been added to the main repo.

Related to StringBladeCompiler version 3.0 and 3.2.

If you use https://github.com/barryvdh/laravel-debugbar with StringBlade, you will get an error - "realpath() expects parameter 1 to be valid path, object given"

This is because the debugbar expects the view it receives to be a file string.

To fix you will need to manually update your vendor package (src/DataCollector/ViewCollector.php), at least until the submitted patch is accepted (if that ever happens).

See barryvdh/laravel-debugbar#422 for code changes.

Versions >3.6 are not available via Composer/Packagist

Hello,

I'm attempting to install the version 3.7 branch from Composer but I notice that on Packagist, only up to version 3.6 is included.

Is there a way to push the latest versions to Composer/Packagist? Thanks in advanced!

Best,
Ian

Still use old view() function ?

I have followed installation steps, but not work. Someone help pls?

(1/1) ErrorExceptionstrpos() expects parameter 1 to be string, array given

Laravel 8 support

Will you provide support for Laravel 8?

I'm currently unable to upgrade, since this library requires Laravel 6 or 7.

Blade::directive() does not seem to work.

When we use:

 Blade::directive('block', function($expression) {
            return "<?php echo "Hello world"; ?>";
        });

And have @block() in our string template, we import with.
$view = view(['template' => $template])->with($variables);

It does not seem to know the directive.
Even if we dd() inside the compileStatements function we get a empty $customDirectives.

Do i need to register the directive in a other way?

How do I run the tests?

How do you setup an run the test?

Trying to run tests…

  1. Checkout the repository.
  2. Run composer install
  3. phpunit is not a dependency
  4. composer require -dev phpunit:^8
  5. vendor/bin/phpunit
  • PHP Warning: require(/Users/jscharf/Workspace/test/StringBladeCompiler-fork/tests/../../../vendor/autoload.php): failed to open stream: No such file or directory in /Users/jscharf/Workspace/test/StringBladeCompiler-fork/tests/bootstrap.php on line 15
  1. So I modify tests/bootstrap.php changing require __DIR__.'/../../../vendor/autoload.php'; -> `require DIR.'/../vendor/autoload.php';
  2. vendor/bin/phpunit
  • HP Fatal error: Uncaught Error: Class 'Wpb\String_Blade_Compiler\Tests\Blade\AbstractBladeTestCase' not found in /Users/jscharf/Workspace/test/StringBladeCompiler-fork/tests/View/Blade/BladeAppendTest.php:5

  • Are the tests up tp date?

  • How am I supposed to run them?

Works in Laravel 7

FYI. Just forked and bumped dep to Laravel 7, seems to work fine! 👍

Support for Custom Directives.

Hey,

Great package :) How I can add support for custom directive?

The directive registered at AppServiceProvider in the Boot function.

        Blade::directive('flash', function ($expression) {
            if (str_contains($expression, ',')) {

                $expression = collect(explode(',', $expression))->map(function ($item) {
                    return trim($item);
                });

                return  "<?php if (isset({$expression->get(0)}) && (bool) {$expression->get(0)} === true) : ?>".
                        "<?php echo {$expression->get(1)}; ?>".
                        '<?php endif; ?>';
            }
            return "<?php if (isset({$expression}) && (bool) {$expression} === true) : ?>";
        });

Thanks!

Problem getting it to autload in Laravel 7

Hi there,

I have added this package to my project successfully:

  • Laravel version: 7
  • In my composer.json: "wpb/string-blade-compiler": "^5.0"

When I try and render the example though I get:

return view (['template' => '{{$token}}'], ['token' => 'I am the token value']);

Error: strpos() expects parameter 1 to be string, array given
...
vendor/laravel/framework/src/Illuminate/View/ViewName.php:17

It looks to me like the package is not auto loading and replacing the view class?

If I run composer dump-autoload I get:

Deprecation Notice: Class Wpb\String_Blade_Compiler\Facades\StringBlade located in ./vendor/wpb/string-blade-compiler/src/Facade/StringBlade.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:185

Any help much appreciated.

[Version 4.0] Requires restrictive version of Laravel 6.x

This package is great -- however, I hit a snag when trying to upgrade to Laravel 6.x:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires wpb/string-blade-compiler 4 -> satisfiable by wpb/string-blade-compiler[4.0.0].
    - wpb/string-blade-compiler 4.0.0 requires laravel/framework 6.0.* -> found laravel/framework[v6.0.0, ..., v6.0.4] but the package is fixed to v6.20.12 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

The only way to install it is to downgrade from Laravel v6.20.12 to Laravel v6.0.4, which I can't do because it will cause conflicts with some of my other vendor packages.

EDIT: When I tried upgrading to v5.0, composer installs as expected, though I'm seeing errors... will follow up after testing.

Laravel 5.5

Any plans to support Laravel 5.5?

This seems to work:
3.4...IT-swap:3.5
but it's probably a good idea to create 3.5 branch, but Pull Request doesn't seem to allow to do that

Do not compile view file

Hi, we are using your package for sending email using templates that are entered using the database. However, these views will always be different and our views directory is getting huge, and it's starting to give problems for the server.

Can you disable the creating of this compiled view file, or return the view path so we can immediately delete it, or create an option to delete it after usage.

Livewire support

Not sure if this is intended, but livewire components aren't working.

{{ view(["template" => "<livewire:my-component />"], ["test" => "ABC"]) }}

I am getting "Undefined variable: _instance". Same livewire component inside a regular blade.php template is working.

Doesn't seem to work in Mailable

Hello,
In an ordinary controller, this works fine, but when I call the exact same code in a Mailable class, it doesn't do the substitution, as:
$results = view(['template' => $body], ['unsubscribe' => 'click this link to unsubscribe']);
Any ideas?
Thanks

Blade:extend

How do you get the blade::extend to work?

I have a file containing several Blade:extend that is loaded in my global.php.
I've also tried to do it in my controller juste above the call to StringView::make but it doesn't take the blade extends into account.

Note that it works fine when working with the default Blade compiler...
Thx!

Extending string layout

Hi
Is it possible to extend a layout from string.
That is providing a layout as string and extending from it

FatalErrorException Declaration of ...\StringBladeCompiler::compile($viewData)

hi,
I tried to build a mail the way you described in #21, but I get the error:

Symfony\Component\Debug\Exception\FatalErrorException: Declaration of Wpb\String_Blade_Compiler\Compilers\StringBladeCompiler::compile($viewData) must be compatible with Illuminate\View\Compilers\BladeCompiler::compile($path = NULL) in /.../vendor/wpb/string-blade-compiler/src/Compilers/StringBladeCompiler.php:8
Stack trace:
#0 {main}

I couldn't figure out the problem as the stack trace wasn't helpful.

can't install it with laravel 5.5.14

Hello,
I can't install it...
composer require "wpb/string-blade-compiler"
Using version ^3.5 for wpb/string-blade-compiler
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for wpb/string-blade-compiler ^3.5 -> satisfiable by wpb/string-blade-compiler[3.5.1].
- Conclusion: remove laravel/framework v5.5.14
- Conclusion: don't install laravel/framework v5.5.14
- wpb/string-blade-compiler 3.5.1 requires illuminate/view 5.1.* -> satisfiable by illuminate/view[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8].
- don't install illuminate/view v5.1.1|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.13|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.16|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.2|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.20|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.22|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.25|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.28|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.30|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.31|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.41|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.6|don't install laravel/framework v5.5.14
- don't install illuminate/view v5.1.8|don't install laravel/framework v5.5.14
- Installation request for laravel/framework (locked at v5.5.14, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.14].

Installation failed, reverting ./composer.json to its original content.

Not working for mailables

I am using the new version 3.6.0

When returning a view in a controller:

return view (['template' => '{{$token}}'], ['token' => 'I am the child template']);

Works fine, but when trying to create a Mailable:

return $this->view (['template' => '{{$token}}'], ['token' => 'I am the child template']);

Creates an empty mail. When I set a file as template, it works fine.

Laravel 6 version 4 fresh install results in: strpos() expects parameter 1 to be string, array given

After installing multiple versions of this package with Laravel 6, I cannot seem to get it to work.

As stated in the docs I've most recently tried version 4 of this package for laravel 6.

Trying the example:

// string blade template load return view (['template' => '{{$token}}'], ['token' => 'I am the token value']);

I am confronted with the error from the title. Some other issues seem to be open with this error as well, however there they seem to occur on laravel 7

Any ideas on how to patch this?

Simplest template gives "StringView::_toString()" must not throw an exception when using variables

 StringView::make(
            array(
                // this actual blade template
                'template' => '{{ $img-src-one }}',
                'cache_key' => "somename",
                'updated_at' => 0
            ),
            array( "img-src-one" => "TEST")
    );

Is the exact code I am using to test this, The error returned (fairly useless) is:

FatalErrorException in Editorial.php line 0: Method Wpb\StringBladeCompiler\StringView::__toString() must not throw an exception
  in Editorial.php line 0
   at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Method      Wpb\StringBladeCompiler\StringView::__toString() must not throw an exception', 'file' =>     '/home/vagrant/Code/app/Editorial.php', 'line' => '0')) in HandleExceptions.php line 116
    at HandleExceptions->handleShutdown()

I am using Laravel 5.0 with branch 2.0

Breaks other packages that contain custom blade directives

I installed spatie/laravel-ray which has a @ray() directive for debug output, however the only way I can get this directive to work is by:

  1. Adding spatie/laravel-ray to my composer.json's dont-discover:
    "extra": {
        "laravel": {
            "dont-discover": [
                "spatie/laravel-ray"
            ]
        }
    },
  1. Add the StringBladeCompilerServiceProvider to my app.php directly after the standard ViewServiceProvider (and I comment it out too because it seems to be more consistent that way):
//        Illuminate\View\ViewServiceProvider::class,
        \Wpb\String_Blade_Compiler\StringBladeServiceProvider::class,
  1. Add the RayServiceProvider at the end of my app.php
  2. Run php artisan view:clear

Can I use this in a resource to parse custom directives?

A solution I found is:
$parsedContent = \View::make(['template' => Blade::compileString($this->content)], ['token' => 'I am the child template'])->render();


Hi,

I am trying to use this package in a Resource like below

$this->content has a custom directive:
<p>@tv('test') Error voluptate</p>

The blade directive is:

Blade::directive('tv', function ($tv) {
            return "<?php echo $tv . '-works'; ?>";
        });

What would it take to have something like this working:
'parsedContent' => StringBlade::compileString($this->content)

Thank you.

class ResourceResource extends JsonResource
{
    public function toArray($request)
    {
        return array_merge(
            parent::toArray($request),
            [
                'template' => $this->template,
                'type' => $this->type,
                'parsedContent' => StringBlade::compileString($this->content)
            ]
        );
    }
}

Class view does not exist

"wpb/string-blade-compiler": "^3.5.5",
Laravel 5.5
Change app.php: remove Illuminate\View\ViewServiceProvider::class, and add Wpb\String_Blade_Compiler\ViewServiceProvider::class,
result:
Class view does not exist

Call to undefined method Wpb\String_Blade_Compiler\Factory::renderWhen()

Hi,
it seems that here haven't been implemented all methods and when I am calling @includeWhen from my blade template, I am getting this error.

Could you have a look?

Update: I have added the renderWhen function from Iluminate/View/Factory class and everythign works just great.

Could you add to the repository please?

Engine [stringblade] not found.

Hello all,
I am trying to run one of your basic examples -
return view (['template' => '{{$token}}'], ['token' => 'I am the token value']);

And no matter what I tried, I keep getting this error which resolved in vendor/wpb/string-blade-compiler/src/Factory.php:114

protected function stringViewInstance($view, $data)
{
   return new StringView($this, $this->engines->resolve('stringblade'), $view, null, $data);
}

laravel 9 support

I have been very much helped by this library for some time.
I also want to use string-blade-compiler in my laravel9 project.
Do you have any plans for support?

Compiler not working in queues

Hi terreporter, great package! There's a problem i'm facing and don't know how to solve it.
I'm using compiled strings in my mailables like this:

$template->body = view (['template' => $template->body], ['member' => $member->toArray()]);

this works fine when sending mail like this:

Mail::to($member->email)->send(new MemberMail($member));

however the variables in the template are not rendered when sending the mail using queues like this

Mail::to($member->email)->queue(new MemberMail($member));

Any solutions?

Composer 2 support

Is this package supporting composer 2? If not, Do you consider to support it?
Thanks.

Call to undefined method Wpb\String_Blade_Compiler\Factory::startPush()

After updating laravel I've got this error:
Call to undefined method Wpb\String_Blade_Compiler\Factory::startPush() in [project_root]/storage/framework/views/956a4ed4204425c97c4b7ea75a71ed70b9dcbd67.php on line 3

After some digging around I've found this pull request in laravel repos: laravel/framework#12808

If you look at the file changes of this pull request: https://github.com/laravel/framework/pull/12808/files. There are four methods added: startPush, stopPush, extendPush and yieldPushContent.

These methods needs to be added to the factory. Otherwise you can't update laravel.

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.