Пример #1
0
 public static function assets()
 {
     if (!self::$assets) {
         self::$assets = Rails\Assets\Assets::instance();
         $prefix = str_replace('\\', '/', self::$config->assets->prefix);
         $basePaths = [str_replace('\\', '/', Rails::config()->paths->application) . $prefix, str_replace('\\', '/', Rails::root() . '/lib') . $prefix, str_replace('\\', '/', Rails::root() . '/vendor') . $prefix];
         $paths = [];
         foreach ($basePaths as $basePath) {
             if (!is_dir($basePath)) {
                 continue;
             }
             $dir = new DirectoryIterator($basePath);
             foreach ($dir as $file) {
                 if ($file->isDot() || !$file->isDir()) {
                     continue;
                 }
                 $paths[] = $file->getPathname();
             }
         }
         $customPaths = Rails::application()->config()->assets->paths->toArray();
         $paths = array_merge($paths, $customPaths);
         self::$assets->addPaths($paths);
         self::$assets->addFilePatterns(self::config()->assets->patterns->toArray());
     }
     return self::$assets;
 }
Пример #2
0
 public function compileAssets()
 {
     $this->error = '';
     if ($this->request()->isPost()) {
         Rails::resetConfig('production');
         try {
             if ($this->params()->all) {
                 Rails::assets()->compileAll();
             } elseif ($this->params()->file) {
                 $file = $this->params()->file;
                 Rails::assets()->compileFile($file);
             }
         } catch (Rails\Assets\Parser\Javascript\ClosureApi\Exception\ErrorsOnCodeException $e) {
             Rails::log()->error(sprintf("[%s] Asset compilation error for file %s\n%s", date('Y-m-d H:i:s'), $file_path . '.' . $ext, $e->getMessage()));
             $message = sprintf("ClosureAPI reported an error - JS file was saved to %s for verfications, error was logged.<br /><pre>%s</pre>", Rails\Assets\Parser\Javascript\ClosureApi\ClosureApi::errorFile(), $e->getMessage());
             $this->error = $message;
         } catch (Throwable $e) {
             /** 
              * If another error occurs, it won't be properly shown because of production config.
              */
             Rails::resetConfig('development');
             throw $e;
         } catch (\Exception $e) {
             /** 
              * If another error occurs, it won't be properly shown because of production config.
              */
             Rails::resetConfig('development');
             throw $e;
         }
         Rails::resetConfig('development');
         Rails::application()->setPanelConfig();
     }
 }
Пример #3
0
 /**
  * Returns the asset path (i.e., the URL) for a file.
  * If the digest option is true, the path to the compiled file
  * (with fingerprint) will be returned, if found. Otherwise, $file
  * will just be appended to the assets path.
  * Note that $file could include path relative to assets path, if necessary,
  * like $this->assetPath('jquery-ui/loading.gif');
  */
 protected function assetPath($file, array $options = [])
 {
     if (!isset($options['digest'])) {
         $options['digest'] = true;
     }
     if ($options['digest']) {
         if ($path = \Rails::assets()->findCompiledFile($file)) {
             return $path;
         }
     }
     $root = \Rails::application()->router()->rootPath();
     if ($root == '/') {
         $root = '';
     }
     return $root . \Rails::assets()->prefix() . '/' . $file;
 }
Пример #4
0
 public function find_route_with_alias($alias, array $params = [])
 {
     if ($alias == 'root') {
         return $this->router()->rootPath();
     } elseif ($alias == "base") {
         return $this->router()->basePath();
     } elseif ($alias == "asset") {
         return \Rails::assets()->prefix() . '/';
     }
     if ($this->useCache()) {
         $key = 'Rails.routes.aliases.' . $alias;
         $index = Rails::cache()->read($key);
         if (null === $index) {
             $index = $this->findAliasedRoute($alias, $params);
             Rails::cache()->write($key, $index);
         }
         if ($index) {
             $route = $this->router()->routes()->routes()->offsetGet($index);
             if ($url = $this->buildUrl($route, $params)) {
                 return $url;
             }
         }
     } else {
         if ($index = $this->findAliasedRoute($alias, $params)) {
             $route = $this->router()->routes()->routes()->offsetGet($index);
             if ($url = $this->buildUrl($route, $params)) {
                 return $url;
             }
         }
     }
     # Build exception
     if ($params) {
         if (is_object($params[0])) {
             $inlineParams = '(object of class ' . get_class($params[0]) . ')';
         } else {
             $inlineParams = '( ';
             foreach ($params as $k => $v) {
                 $inlineParams .= $k . '=>' . $v;
             }
             $inlineParams .= ' )';
         }
     } else {
         $inlineParams = "(no parameters)";
     }
     throw new Exception\RuntimeException(sprintf("No route found with alias '%s' %s", $alias, $inlineParams));
 }
Пример #5
0
 public function assetPath($source, array $options = [])
 {
     if (strpos($source, '/') !== 0 && strpos($source, 'http') !== 0) {
         if (!isset($options['digest'])) {
             $options['digest'] = true;
         }
         if (\Rails::config()->assets->enabled) {
             if (\Rails::config()->serve_static_assets && $options['digest']) {
                 if ($url = \Rails::assets()->findCompiledFile($source)) {
                     return $url;
                 }
             }
             if ($file = \Rails::assets()->findFile($source)) {
                 return $file->url();
             }
         }
         return \Rails::application()->router()->rootPath() . $source;
     } else {
         return $source;
     }
 }
Пример #6
0
 public function run()
 {
     switch ($this->mainArgv) {
         case 'generate':
             $gen = new Generators\Generator($this);
             $gen->parseCmd();
             break;
         case 'assets':
             $rules = ['assets' => '', 'action' => ''];
             $opts = new Zend\Console\Getopt($rules);
             $argv = $opts->getArguments();
             if (empty($argv[1])) {
                 $this->terminate("Missing argument 2");
             }
             \Rails::resetConfig('production');
             switch ($argv[1]) {
                 case 'compile:all':
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileAll();
                     break;
                 case strpos($argv[1], 'compile:') === 0:
                     $parts = explode(':', $argv[1]);
                     if (empty($parts[1])) {
                         $this->terminate("Missing asset name to compile");
                     }
                     \Rails::assets()->setConsole($this);
                     \Rails::assets()->compileFile($parts[1]);
                     break;
                 default:
                     $this->terminate("Unknown action for assets");
                     break;
             }
             break;
         case 'routes':
             $routes = $this->createRoutes();
             $rules = ['routes' => '', 'f-s' => ''];
             $opts = new Zend\Console\Getopt($rules);
             if ($filename = $opts->getOption('f')) {
                 if (true === $filename) {
                     $logFile = \Rails::config()->paths->log->concat('routes.log');
                 } else {
                     $logFile = \Rails::root() . '/' . $filename;
                 }
                 file_put_contents($logFile, $routes);
             }
             $this->write($routes);
             break;
             /**
              * Install database.
              */
         /**
          * Install database.
          */
         case 'db:create':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->loadSchema();
             break;
             /**
              * Run all/pending migrations.
              * Creates migrations table as well.
              */
         /**
          * Run all/pending migrations.
          * Creates migrations table as well.
          */
         case 'db:migrate':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->run();
             break;
             /**
              * Runs seeds.
              */
         /**
          * Runs seeds.
          */
         case 'db:seed':
             $m = new \Rails\ActiveRecord\Migration\Migrator();
             $m->runSeeds();
             break;
         case 'db:schema:dump':
             $dumper = new \Rails\ActiveRecord\Schema\Dumper(\Rails\ActiveRecord\ActiveRecord::connection());
             $dumper->export(\Rails::root() . '/db/schema.sql');
             break;
     }
 }
Пример #7
0
 public function initialize()
 {
     \Rails::assets()->addPaths([realpath(__DIR__ . '/../../../vendor/assets/javascripts'), realpath(__DIR__ . '/../../../vendor/assets/stylesheets'), realpath(__DIR__ . '/../../../vendor/assets/images')]);
     \Rails\ActionView\ViewHelpers::addHelper('Rails\\Bootstrap2\\ViewHelper');
 }
Пример #8
0
        mkdir($path);
    }
}
/**
 * Compile assets
 */
$c->put("\n");
$c->put("Compiling assets", null, Color::BLUE);
# Set console to assets
Rails::assets()->setConsole($c);
# Compile files
# CSS minifier Toopay/Assetic-Minifier uses /e modifier in its
# preg_replace() calls, which is deprecated as of PHP 5.5. Change
# error_reporting to avoid triggering the deprecation warning.
set_error_handler('nullErrorHandler');
Rails::assets()->compileAll();
$c->put("done");
/**
 * Finish
 */
$c->put();
$c->put("Installation finished.", Color::GREEN);
$c->put("You may delete this install.php file.");
$c->put();
function nullErrorHandler()
{
}
function getAdminData($c)
{
    $adminName = $c->input("Account name: ");
    $adminPass = $c->input("Password: ");
Пример #9
0
 public function initialize()
 {
     \Rails::assets()->addPaths([realpath(__DIR__ . '/../../../vendor/assets/javascripts'), realpath(__DIR__ . '/../../../vendor/assets/stylesheets'), realpath(__DIR__ . '/../../../vendor/assets/fonts')]);
     \Rails::assets()->addFilePatterns(['*.eot', '*.svg', '*.ttf', '*.woff']);
     \Rails\ActionView\ViewHelpers::addHelper('Rails\\Bootstrap3\\ViewHelper');
 }
Пример #10
0
 public function initialize()
 {
     \Rails::assets()->addPaths([realpath(__DIR__ . '/../../../vendor/assets/javascripts')]);
     \Rails::assets()->addFilePatterns(['.map']);
 }