more regarding CompileAssets

This commit is contained in:
Parziphal 2013-10-27 01:25:59 -05:00
parent afa393ba25
commit 114ce70d3a
2 changed files with 43 additions and 3 deletions

View File

@ -1,13 +1,16 @@
<?php
namespace ApplicationInstaller;
use Composer\Script\Event;
use Rails;
/**
* Post-install script ran when installing the system
* using composer. It compiles assets.
* using Composer to compile assets.
*/
class CompileAssets
{
static public function compile()
static public function compile(Event $event)
{
$railsRoot = __DIR__ . '/../..';
@ -16,8 +19,25 @@ class CompileAssets
$target = $railsRoot . '/config/config.php';
copy($file, $target);
# Load rails
require $railsRoot . '/config/boot.php';
\Rails::assets()->compileAll();
# Reset configuration to production, because Rails will load
# development by default when ran from CGI, and Assets won't
# set environment to production itself. Fix this later.
Rails::resetConfig('production');
# Load console
$console = new Console($event->getIO());
# Warn about compiling
$console->write("[Compiling assets]");
# Set console to assets
Rails::assets()->setConsole($console);
# Compile files
Rails::assets()->compileAll();
# Delete temporary config file.
unlink($target);

View File

@ -0,0 +1,20 @@
<?php
namespace ApplicationInstaller;
/**
* Console used by CompileAssets.
*/
class Console extends \Rails\Console\Console
{
private $io;
public function __construct($io)
{
$this->io = $io;
}
public function write($message, $n = 1)
{
$this->io->write($message . str_repeat("\n", $n));
}
}