Commit 0e319dd8 by Crisu83

added support for hero content capturing (thanks Christophe Boulain) and updated the less compiler

parent 5e3fec4d
// IMPORTS // IMPORTS
@import "../../lib/bootstrap/less/mixins.less"; @import "../../lib/bootstrap/less/mixins.less";
@import "../css/highlight.css"; @import "highlight.less";
// VARIABLES // VARIABLES
......
...@@ -6,8 +6,12 @@ ...@@ -6,8 +6,12 @@
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*/ */
Yii::setPathOfAlias('Less', realpath(dirname(__FILE__).'/../lib/lessphp/lib/Less')); Yii::setPathOfAlias('Less', dirname(__FILE__).'/../lib/lessphp/lib/Less');
/**
* Less compiler application component.
* Preload the component to enable auto compiling.
*/
class LessCompiler extends CApplicationComponent class LessCompiler extends CApplicationComponent
{ {
/** /**
...@@ -19,9 +23,9 @@ class LessCompiler extends CApplicationComponent ...@@ -19,9 +23,9 @@ class LessCompiler extends CApplicationComponent
*/ */
public $paths = array(); public $paths = array();
/** /**
* @var boolean whether to auto compile * @var boolean indicates whether to force compiling.
*/ */
public $autoCompile = false; public $forceCompile = false;
/** /**
* @var boolean compiler debug mode. * @var boolean compiler debug mode.
*/ */
...@@ -30,29 +34,26 @@ class LessCompiler extends CApplicationComponent ...@@ -30,29 +34,26 @@ class LessCompiler extends CApplicationComponent
* @var boolean whether to compress css or not. * @var boolean whether to compress css or not.
*/ */
public $compress = false; public $compress = false;
/**
* @var \Less\Parser the less parser.
*/
protected $_parser; protected $_parser;
/** /**
* Initializes the component. * Initializes the component.
* @throws CException if the base path does not exist
*/ */
public function init() public function init()
{ {
if (!isset($this->basePath)) if ($this->basePath === null)
$this->basePath = Yii::getPathOfAlias('webroot'); $this->basePath = Yii::getPathOfAlias('webroot');
if (!file_exists($this->basePath)) if (!file_exists($this->basePath))
throw new CException(__CLASS__.': Failed to initialize compiler. Base path does not exist!'); throw new CException(__CLASS__.': Failed to initialize compiler. Base path does not exist.');
$env = new \Less\Environment(); $env = new \Less\Environment();
$env->compress = $this->compress; $env->setDebug($this->debug);
$env->debug = $this->debug; $env->setCompress($this->compress);
$this->_parser = new \Less\Parser($env); $this->_parser = new \Less\Parser($env);
if ($this->autoCompile/* && $this->hasChanges()*/) if ($this->forceCompile || $this->hasChanges())
$this->compile(); $this->compile();
} }
...@@ -70,17 +71,16 @@ class LessCompiler extends CApplicationComponent ...@@ -70,17 +71,16 @@ class LessCompiler extends CApplicationComponent
if (file_exists($fromPath)) if (file_exists($fromPath))
file_put_contents($toPath, $this->parse($fromPath)); file_put_contents($toPath, $this->parse($fromPath));
else else
throw new CException(__CLASS__.': Failed to compile less file. Source path does not exist!'); throw new CException(__CLASS__.': Failed to compile less file. Source path does not exist.');
$this->_parser->clearCss(); $this->_parser->clearCss();
} }
} }
/** /**
* Parses the less code to css. * Parses the less code to CSS.
* @param string $filename the file path to the less file * @param string $filename the file path to the less file
* @return string the css * @return string the CSS
* @throws CException
*/ */
public function parse($filename) public function parse($filename)
{ {
...@@ -90,7 +90,7 @@ class LessCompiler extends CApplicationComponent ...@@ -90,7 +90,7 @@ class LessCompiler extends CApplicationComponent
} }
catch (\Less\Exception\ParserException $e) catch (\Less\Exception\ParserException $e)
{ {
throw new CException(__CLASS__.': Failed to compile less file with message: "'.$e->getMessage().'".'); throw new CException(__CLASS__.': Failed to parse less file. "'.$e->getMessage().'".');
} }
return $css; return $css;
...@@ -100,16 +100,18 @@ class LessCompiler extends CApplicationComponent ...@@ -100,16 +100,18 @@ class LessCompiler extends CApplicationComponent
* Returns whether any of files configured to be compiled has changed. * Returns whether any of files configured to be compiled has changed.
* @return boolean the result * @return boolean the result
*/ */
public function hasChanges() protected function hasChanges()
{ {
$dirs = array(); $dirs = array();
foreach ($this->paths as $source => $destination) foreach ($this->paths as $source => $destination)
{ {
$destination = realpath($destination);
$compiled = $this->getLastModified($destination); $compiled = $this->getLastModified($destination);
if (!isset($lastCompiled) || $compiled < $lastCompiled ) if (!isset($lastCompiled) || $compiled < $lastCompiled )
$lastCompiled = $compiled; $lastCompiled = $compiled;
if (!in_array(dirname($source), $dirs)) $source = realpath($source);
if (!in_array($source, $dirs))
$dirs[] = $source; $dirs[] = $source;
} }
...@@ -142,20 +144,19 @@ class LessCompiler extends CApplicationComponent ...@@ -142,20 +144,19 @@ class LessCompiler extends CApplicationComponent
{ {
$lastModified = null; $lastModified = null;
/** @var Directory $dir */
$dir = dir($path); $dir = dir($path);
while ($entry = $dir->read()) while ($entry = $dir->read())
{ {
if (strpos($entry, '.') === 0) if (strpos($entry, '.') === 0)
continue; continue;
$path .= '/'.$entry; $entry = $path.'/'.$entry;
if( is_dir($path) ) if( is_dir($entry) )
$modified = $this->getLastModified($path); $modified = $this->getLastModified($entry);
else else
{ {
$stat = stat($path); $stat = stat($entry);
$modified = $stat['mtime']; $modified = $stat['mtime'];
} }
......
...@@ -305,7 +305,7 @@ class Parser { ...@@ -305,7 +305,7 @@ class Parser {
if ($this->peek('/', 1)) { if ($this->peek('/', 1)) {
return new \Less\Node\Comment($this->match('/^\/\/.*/'), true); return new \Less\Node\Comment($this->match('/^\/\/.*/'), true);
} else { } else {
if ($comment = $this->match('/^\\/\*(?:[^*]|\*+[^\\/*])*\*+\\/\n?/')) { if ($comment = $this->match('/\/\*.*?\*\//s')) {
return new \Less\Node\Comment($comment, false); return new \Less\Node\Comment($comment, false);
} }
} }
......
...@@ -86,19 +86,18 @@ ...@@ -86,19 +86,18 @@
<div class="container"> <div class="container">
<?php $this->widget('bootstrap.widgets.BootHero', array( <?php $this->beginWidget('bootstrap.widgets.BootHero', array(
'heading'=>Yii::app()->name, 'heading'=>Yii::app()->name,
'content'=>"
<p>
Bringing together the ".CHtml::link('Yii PHP framework', 'http://www.yiiframework.com')." and
".CHtml::link('Bootstrap', 'http://twitter.github.com/bootstrap/').", Twitter's new web development toolkit.
Now with support for Bootstrap 2!
".CHtml::link('Yii-Bootstrap', 'http://www.yiiframework.com/extension/bootstrap/')."
is an extension for Yii that provides a wide range of server-side widgets that allow you to easily use Bootstrap with Yii.
All widgets have been developed following Yii's conventions and work seemlessly together with Bootstrap and its jQuery plugins.
</p>
",
)); ?> )); ?>
<p>
Bringing together the <?php echo CHtml::link('Yii PHP framework', 'http://www.yiiframework.com'); ?> and
<?php echo CHtml::link('Bootstrap', 'http://twitter.github.com/bootstrap/'); ?> Twitter's new web development toolkit.
Now with support for Bootstrap 2!
<?php echo CHtml::link('Yii-Bootstrap', 'http://www.yiiframework.com/extension/bootstrap/'); ?>
is an extension for Yii that provides a wide range of server-side widgets that allow you to easily use Bootstrap with Yii.
All widgets have been developed following Yii's conventions and work seamlessly together with Bootstrap and its jQuery plugins.
</p>
<?php $this->endWidget(); ?>
<?php if (!empty($this->breadcrumbs)):?> <?php if (!empty($this->breadcrumbs)):?>
<?php $this->widget('bootstrap.widgets.BootBreadcrumbs', array( <?php $this->widget('bootstrap.widgets.BootBreadcrumbs', array(
......
...@@ -1190,13 +1190,12 @@ $('#buttonStateful').click(function() { ...@@ -1190,13 +1190,12 @@ $('#buttonStateful').click(function() {
<h2>Hero unit <small>Coming in version 0.9.10</small></h2> <h2>Hero unit <small>Coming in version 0.9.10</small></h2>
<?php $this->widget('bootstrap.widgets.BootHero', array( <?php $this->beginWidget('bootstrap.widgets.BootHero', array(
'heading'=>'Hello, world!', 'heading'=>'Hello, world!',
'content'=>"
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class=\"btn btn-primary btn-large\">Learn more</a></p>
",
)); ?> )); ?>
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class="btn btn-primary btn-large">Learn more</a></p>
<?php $this->endWidget(); ?>
<h4>Source code</h4> <h4>Source code</h4>
...@@ -1204,11 +1203,16 @@ $('#buttonStateful').click(function() { ...@@ -1204,11 +1203,16 @@ $('#buttonStateful').click(function() {
[php] [php]
<?php \$this->widget('bootstrap.widgets.BootHero', array( <?php \$this->widget('bootstrap.widgets.BootHero', array(
'heading'=>'Hello, world!', 'heading'=>'Hello, world!',
'content'=>\"
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class=\"btn btn-primary btn-large\">Learn more</a></p>
\",
)); ?> )); ?>
~~~
~~~
[html]
<p>This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<p><a class=\"btn btn-primary btn-large\">Learn more</a></p>
~~~
~~~
[php]
<?php \$this->endWidget(); ?>
~~~"); ?> ~~~"); ?>
<a class="top" href="#top">Back to top &uarr;</a> <a class="top" href="#top">Back to top &uarr;</a>
......
...@@ -12,6 +12,7 @@ Yii::import('bootstrap.widgets.BootWidget'); ...@@ -12,6 +12,7 @@ Yii::import('bootstrap.widgets.BootWidget');
/** /**
* Modest bootstrap hero widget. * Modest bootstrap hero widget.
* Thanks to Christphe Boulain for suggesting content capturing.
*/ */
class BootHero extends BootWidget class BootHero extends BootWidget
{ {
...@@ -20,10 +21,6 @@ class BootHero extends BootWidget ...@@ -20,10 +21,6 @@ class BootHero extends BootWidget
*/ */
public $heading; public $heading;
/** /**
* @var string the content text.
*/
public $content;
/**
* @var boolean indicates whether to encode the heading. * @var boolean indicates whether to encode the heading.
*/ */
public $encodeHeading = true; public $encodeHeading = true;
...@@ -41,6 +38,9 @@ class BootHero extends BootWidget ...@@ -41,6 +38,9 @@ class BootHero extends BootWidget
if ($this->encodeHeading) if ($this->encodeHeading)
$this->heading = CHtml::encode($this->heading); $this->heading = CHtml::encode($this->heading);
ob_start();
ob_implicit_flush(false);
} }
/** /**
...@@ -48,9 +48,13 @@ class BootHero extends BootWidget ...@@ -48,9 +48,13 @@ class BootHero extends BootWidget
*/ */
public function run() public function run()
{ {
$content = ob_get_clean();
echo CHtml::openTag('div', $this->htmlOptions); echo CHtml::openTag('div', $this->htmlOptions);
echo CHtml::tag('h1', array(), $this->heading);
echo $this->content; if (isset($this->heading))
echo CHtml::tag('h1', array(), $this->heading);
echo $content;
echo '</div>'; echo '</div>';
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment