Commit 0e319dd8 by Crisu83

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

parent 5e3fec4d
// IMPORTS
@import "../../lib/bootstrap/less/mixins.less";
@import "../css/highlight.css";
@import "highlight.less";
// VARIABLES
......
......@@ -6,8 +6,12 @@
* @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
{
/**
......@@ -19,9 +23,9 @@ class LessCompiler extends CApplicationComponent
*/
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.
*/
......@@ -30,29 +34,26 @@ class LessCompiler extends CApplicationComponent
* @var boolean whether to compress css or not.
*/
public $compress = false;
/**
* @var \Less\Parser the less parser.
*/
protected $_parser;
/**
* Initializes the component.
* @throws CException if the base path does not exist
*/
public function init()
{
if (!isset($this->basePath))
if ($this->basePath === null)
$this->basePath = Yii::getPathOfAlias('webroot');
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->compress = $this->compress;
$env->debug = $this->debug;
$env->setDebug($this->debug);
$env->setCompress($this->compress);
$this->_parser = new \Less\Parser($env);
if ($this->autoCompile/* && $this->hasChanges()*/)
if ($this->forceCompile || $this->hasChanges())
$this->compile();
}
......@@ -70,17 +71,16 @@ class LessCompiler extends CApplicationComponent
if (file_exists($fromPath))
file_put_contents($toPath, $this->parse($fromPath));
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();
}
}
/**
* Parses the less code to css.
* Parses the less code to CSS.
* @param string $filename the file path to the less file
* @return string the css
* @throws CException
* @return string the CSS
*/
public function parse($filename)
{
......@@ -90,7 +90,7 @@ class LessCompiler extends CApplicationComponent
}
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;
......@@ -100,16 +100,18 @@ class LessCompiler extends CApplicationComponent
* Returns whether any of files configured to be compiled has changed.
* @return boolean the result
*/
public function hasChanges()
protected function hasChanges()
{
$dirs = array();
foreach ($this->paths as $source => $destination)
{
$destination = realpath($destination);
$compiled = $this->getLastModified($destination);
if (!isset($lastCompiled) || $compiled < $lastCompiled )
$lastCompiled = $compiled;
if (!in_array(dirname($source), $dirs))
$source = realpath($source);
if (!in_array($source, $dirs))
$dirs[] = $source;
}
......@@ -142,20 +144,19 @@ class LessCompiler extends CApplicationComponent
{
$lastModified = null;
/** @var Directory $dir */
$dir = dir($path);
while ($entry = $dir->read())
{
if (strpos($entry, '.') === 0)
continue;
$path .= '/'.$entry;
$entry = $path.'/'.$entry;
if( is_dir($path) )
$modified = $this->getLastModified($path);
if( is_dir($entry) )
$modified = $this->getLastModified($entry);
else
{
$stat = stat($path);
$stat = stat($entry);
$modified = $stat['mtime'];
}
......
......@@ -305,7 +305,7 @@ class Parser {
if ($this->peek('/', 1)) {
return new \Less\Node\Comment($this->match('/^\/\/.*/'), true);
} else {
if ($comment = $this->match('/^\\/\*(?:[^*]|\*+[^\\/*])*\*+\\/\n?/')) {
if ($comment = $this->match('/\/\*.*?\*\//s')) {
return new \Less\Node\Comment($comment, false);
}
}
......
......@@ -86,19 +86,18 @@
<div class="container">
<?php $this->widget('bootstrap.widgets.BootHero', array(
<?php $this->beginWidget('bootstrap.widgets.BootHero', array(
'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 $this->widget('bootstrap.widgets.BootBreadcrumbs', array(
......
......@@ -1190,13 +1190,12 @@ $('#buttonStateful').click(function() {
<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!',
'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>
......@@ -1204,11 +1203,16 @@ $('#buttonStateful').click(function() {
[php]
<?php \$this->widget('bootstrap.widgets.BootHero', array(
'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>
......
......@@ -12,6 +12,7 @@ Yii::import('bootstrap.widgets.BootWidget');
/**
* Modest bootstrap hero widget.
* Thanks to Christphe Boulain for suggesting content capturing.
*/
class BootHero extends BootWidget
{
......@@ -20,10 +21,6 @@ class BootHero extends BootWidget
*/
public $heading;
/**
* @var string the content text.
*/
public $content;
/**
* @var boolean indicates whether to encode the heading.
*/
public $encodeHeading = true;
......@@ -41,6 +38,9 @@ class BootHero extends BootWidget
if ($this->encodeHeading)
$this->heading = CHtml::encode($this->heading);
ob_start();
ob_implicit_flush(false);
}
/**
......@@ -48,9 +48,13 @@ class BootHero extends BootWidget
*/
public function run()
{
$content = ob_get_clean();
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>';
}
}
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