pug-php / pug-symfony

Pug (Jade) template engine for Symfony
MIT License
44 stars 3 forks source link

"extends" keyword throws Extends should be very first statement in file #30

Closed coneforapine closed 5 years ago

coneforapine commented 5 years ago

I don't really know what causes it but here's my files

layout.pug

html
  head
    title My Site
  body
    block content
    footer
      p 
      | Some footer text

welcome.pug

extends layout

block content
    h1 Welcome #{name}

When I comment out if statement which throws the exception it works fine but I don't think it will catch unexpected "extends" keyword...

vendor\phug\parser\src\Phug\Parser\TokenHandler\ImportTokenHandler.php line 35

kylekatarnls commented 5 years ago

I think you have a BOM (hidden characters put by some editors) at the beginning of your welcome.pug file.

kylekatarnls commented 5 years ago

Can you check it, for example by dumping the 7 first letters of you file:

<?php
echo substr(file_get_contents('welcome.pug'), 0, 7);
coneforapine commented 5 years ago

I'm using vscode so I don't think that'll cause a BOM...

php -r "echo substr(file_get_contents('welcome.pug'), 0, 7)"

returns extends to my console...

coneforapine commented 5 years ago

Oh I thought It'll be nice to send the php version and symfony version

$ php -v

Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

$ php bin/console --version

Symfony 4.2.1 (env: dev, debug: true)
kylekatarnls commented 5 years ago

Hi, indeed this regression has been introduced by the last version. I will fix it, meanwhile, you can use the 2.5.0:

composer require pug-php/pug-symfony:2.5.0
kylekatarnls commented 5 years ago

You can now update to the last version to fix the problem:

composer require pug-php/pug-symfony "^2.6.1"

Thanks for your help!

coneforapine commented 5 years ago

Hi,

composer said there is no mathing version with ^2.6.1

Also there isn't any version called 2.6.1 at https://packagist.org/packages/pug-php/pug-symfony

image

Also installing with

composer require pug-php/pug-symfony "dev-master"

doesn't fixed the issue so i did go with version 2.5.0

kylekatarnls commented 5 years ago

The new hook to Packagist is synchronized, please retry (the version 2.6.0 enable a lot of Twig functions to be used directly inside pug templates).