Skip to content

Commit

Permalink
Space-separated attributes are allowed now
Browse files Browse the repository at this point in the history
Corrected the README
Added some more attribute tests
Added a mixin test thats quite interesting (.classes and #ids are just
normal attributes, even in mixins!)
Fixed: #33
  • Loading branch information
Torben Köhn committed Jan 5, 2016
1 parent 2f14f42 commit 8f0428b
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Compiler.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -91,7 +91,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Compiler.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Compiler.Exception.html
* @since File available since Release 1.0
*/
Expand All @@ -35,7 +35,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Compiler.Exception.html
* @since File available since Release 1.0
*/
Expand Down
2 changes: 2 additions & 0 deletions Compiler/functions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Tale\Jade\Compiler {
//We use the bracket-style here to be able to compile
//this file into compiled jade templates for valid PHP

if (!function_exists(__NAMESPACE__.'\\build_value')) {

Expand Down
4 changes: 2 additions & 2 deletions Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Filter.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -53,7 +53,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Filter.html
* @since File available since Release 1.0
*/
Expand Down
14 changes: 9 additions & 5 deletions Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Lexer.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -60,7 +60,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Lexer.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -1684,14 +1684,18 @@ protected function scanAttributes()
$this->read('ctype_space');
}

$token['value'] = $this->readBracketContents([',']);
$token['value'] = $this->readBracketContents([',', ' ', "\r", "\n", "\t"]);
}

if ($this->peek() === ',') {
if ($this->peek() === ',' || ctype_space($this->peek())) {

$this->consume();
$this->read('ctype_space');
$continue = true;

if ($this->peek() !== ')')
$continue = true;
else
$continue = false;
} else {

$continue = false;
Expand Down
4 changes: 2 additions & 2 deletions Lexer/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Lexer.Exception.html
* @since File available since Release 1.0
*/
Expand All @@ -34,7 +34,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Lexer.Exception.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Parser.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -57,7 +57,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Parser.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Parser/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Parser.Exception.html
* @since File available since Release 1.0
*/
Expand All @@ -34,7 +34,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Parser.Exception.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Parser/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Parser.Node.html
* @since File available since Release 1.0
*/
Expand All @@ -40,7 +40,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Parser.Node.html
* @since File available since Release 1.0
*/
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ echo $renderer->render('your-jade-file');
```

This way, the renderer will search for `your-jade-file.jade` in your `get_include_path()`-paths.
Notice that the path passed to `render` needs to be relative, *always*.
Notice that the path passed to `render` should be relative. You can give it absolute paths, but it will make caching harder.
Use absolute paths for testing only.
We show you how to add alternative search paths further in the **Basic configuration** section below.

When the Jade-file gets rendered, a `./cache/views`-directory is created automatically and the compiled PHTML will be stored in that directory.
Expand Down
4 changes: 2 additions & 2 deletions Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Renderer.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -51,7 +51,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Renderer.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Renderer/Adapter/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Renderer.Adapter.File.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -58,7 +58,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Renderer.Adapter.File.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Renderer/Adapter/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Renderer.Adapter.Stream.html
* @since File available since Release 1.0
*/
Expand Down Expand Up @@ -70,7 +70,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Renderer.Adapter.Stream.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Renderer/Adapter/Stream/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Renderer.Adapter.Stream.Wrapper.html
* @since File available since Release 1.0
*/
Expand All @@ -40,7 +40,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Renderer.Adapter.Stream.Wrapper.html
* @since File available since Release 1.0
*/
Expand Down
4 changes: 2 additions & 2 deletions Renderer/AdapterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/Renderer.AdapterBase.html
* @since File available since Release 1.0
*/
Expand All @@ -40,7 +40,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/classes/Tale.Jade.Renderer.AdapterBase.html
* @since File available since Release 1.0
*/
Expand Down
30 changes: 30 additions & 0 deletions Test/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Tale\Jade\Compiler;
use Tale\Jade\Renderer;
use Tale\Jade\Parser;

class AttributeTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -133,4 +134,33 @@ public function attributeValueProvider()
[(object)['one', 'two', 'three'], '<a href="onetwothree"></a>']
];
}

public function testUnnamedAttributed()
{

$this->setExpectedException(Parser\Exception::class);
$this->assertEquals('', $this->_renderer->compile('a(="some value")'));
}

public function testExpectedButNotGivenValue()
{

$this->assertEquals('<a href=""></a>', $this->_renderer->compile('a(href=)'));
}

public function testSpaceSeparated()
{

$this->assertEquals('<meta name="viewport" content="some viewport content"><a href="google.de" target="_blank" title="Some link title"></a>', $this->_renderer->render(
'space-separated'
));
}

public function testIssue33()
{

$this->assertEquals('<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"><meta http-equiv="X-UA-Compatible" content="chrome=1"><link rel="shortcut icon" href="/favicon.ico"><link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600"><link rel="stylesheet" href="/style.css">', $this->_renderer->render(
'issue-33'
));
}
}
12 changes: 11 additions & 1 deletion Test/MixinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class MixinTest extends \PHPUnit_Framework_TestCase
{

/** @var \Tale\Jade\Compiler */
/** @var \Tale\Jade\Renderer */
private $_renderer;

public function setUp()
Expand Down Expand Up @@ -52,4 +52,14 @@ public function testBlock()
'block'
));
}



public function testIdAndClassForwarding()
{

$this->assertEquals('<button class="btn btn-default" id="someId"></button>', $this->_renderer->render(
'id-and-class-forwarding'
));
}
}
8 changes: 8 additions & 0 deletions Test/views/attributes/issue-33.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

meta(name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0")
meta(http-equiv="X-UA-Compatible" content="chrome=1")

link(rel="shortcut icon" href="/favicon.ico")
link(rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600")

link(rel="stylesheet" href="/style.css")
6 changes: 6 additions & 0 deletions Test/views/attributes/space-separated.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


meta(name='viewport' content='some viewport content')

//- Mixed test
a(href='google.de' target='_blank', title='Some link title')
7 changes: 7 additions & 0 deletions Test/views/mixins/id-and-class-forwarding.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

mixin button(label)
button.btn(id=$id, class=$class)= $label



+button.btn-default#someId('My Button Label')
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": ">=4.0"
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Talesoft <[email protected]>
* @copyright Copyright (c) 2015 Talesoft (http://talesoft.io)
* @license http://licenses.talesoft.io/2015/MIT.txt MIT License
* @version 1.3.0
* @version 1.3.1
* @link http://jade.talesoft.io/docs/files/functions.html
* @since File available since Tag 1.0.1
*/
Expand Down
2 changes: 1 addition & 1 deletion tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'./.git'
];

$newVersion = '1.3.0';
$newVersion = '1.3.1';


if (!$newVersion) {
Expand Down

0 comments on commit 8f0428b

Please sign in to comment.