Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estilos de la aplicación #14

Closed
neozoe opened this issue Dec 19, 2011 · 12 comments
Closed

Estilos de la aplicación #14

neozoe opened this issue Dec 19, 2011 · 12 comments

Comments

@neozoe
Copy link

neozoe commented Dec 19, 2011

Hola Javier,

Estoy probando tu aplicación, y he visto en el directorio de ficheros que la carpeta css está vacía. No aparece ningún estilo y al navegar por la aplicación, evidentemente aparece totalmente plana, con texto...
Una vez levantados los servicios de Apache y MySQL... accedo a la aplicación, pero haciendo click en oferta del día, o mi perfil, no termina de cargar la siguiente página... va lento....

Gracias de antemano por tu ayuda...

@javiereguiluz
Copy link
Owner

Hola neozoe,

Lo de los estilos es normal, porque esta es la forma de trabajar con Symfony2. Para solucionarlo, tienes que ejecutar la instrucción número 5 de la guía de uso:

Genera los web assets con Assetic: php app/console assetic:dump --env=dev --no-debug y php app/console assetic:dump --env=prod --no-debug

Sobre el rendimiento no sabría que decirte, porque no conozco tu instalación. Lo que sí que te puedo decir es que en mi modesto portátil de hace 2 años consigo generar 300 portadas completas por segundo, gracias a la cache de HTTP y ESI.

@neozoe
Copy link
Author

neozoe commented Dec 19, 2011

La instalación es sobre un xampplite 1.7.7 (Apache 2.2.21, MySQL 5.5.16, PHP 5.3.8, phpMyAdmin 3.4.5)

Me da éste mensaje de error, cuando lo ejecuto para --env=dev, para --env=prod no me indica ningún mensaje

C:\xampplite\htdocs\cupon>php app/console assetic:dump --env=dev --no-debug
Dumping all dev assets.
Debug mode is off.

[file+] C:\xampplite\htdocs\cupon\app/../web/css/backend.css



  [RuntimeException]
  El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos.



assetic:dump [--watch] [--force] [--period="..."] [write_to]

C:\xampplite\htdocs\cupon>php app/console assetic:dump --env=prod --no-debug

C:\xampplite\htdocs\cupon>

@hastaelsur
Copy link

tengo el mismo error que neozoe con el xampp full instalado.
les agradeceria que me cuenten como lo solucionaron.
en mi caso el servidor lo configure en otra ubicación, pero el resto del error es todo igual

felices fiestas
Fer

@ejosvp
Copy link

ejosvp commented Dec 27, 2011

se que no les ayudara mucho, pero la solución es usar linux ;)

@hastaelsur
Copy link

BUAAAAAaaaaaaaaaaaaaaaaaaaaaa
Gracias,, si ya lo estoy evaluando

@javiereguiluz
Copy link
Owner

Sigo sin entender qué es lo que hace Xampp Lite para que Assetic no funcione como debería. En cualquier caso, si ves el código fuente del archivo vendor/bundles/Symfony/Bundle/AsseticBundle/Command/DumpCommand.php observa lo que incluye al final del todo:

<?php

/*
 * This file is part of the Symfony framework.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Symfony\Bundle\AsseticBundle\Command;

use Assetic\Asset\AssetInterface;
use Assetic\Factory\LazyAssetManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Dumps assets to the filesystem.
 *
 * @author Kris Wallsmith <kris@symfony.com>
 */
class DumpCommand extends ContainerAwareCommand
{
    private $basePath;
    private $verbose;
    private $am;

    protected function configure()
    {
        $this
            ->setName('assetic:dump')
            ->setDescription('Dumps all assets to the filesystem')
            ->addArgument('write_to', InputArgument::OPTIONAL, 'Override the configured asset root')
            ->addOption('watch', null, InputOption::VALUE_NONE, 'Check for changes every second, debug mode only')
            ->addOption('force', null, InputOption::VALUE_NONE, 'Force an initial generation of all assets (used with --watch)')
            ->addOption('period', null, InputOption::VALUE_REQUIRED, 'Set the polling period in seconds (used with --watch)', 1)
        ;
    }

    protected function initialize(InputInterface $input, OutputInterface $output)
    {
        parent::initialize($input, $output);

        $this->basePath = $input->getArgument('write_to') ?: $this->getContainer()->getParameter('assetic.write_to');
        $this->verbose = $input->getOption('verbose');
        $this->am = $this->getContainer()->get('assetic.asset_manager');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
        $output->writeln(sprintf('Debug mode is <comment>%s</comment>.', $input->getOption('no-debug') ? 'off' : 'on'));
        $output->writeln('');

        if (!$input->getOption('watch')) {
            foreach ($this->am->getNames() as $name) {
                $this->dumpAsset($name, $output);
            }

            return;
        }

        if (!$this->am->isDebug()) {
            throw new \RuntimeException('The --watch option is only available in debug mode.');
        }

        $this->watch($input, $output);
    }

    // ...

    /**
     * Performs the asset dump.
     *
     * @param AssetInterface  $asset  An asset
     * @param OutputInterface $output The command output
     *
     * @throws RuntimeException If there is a problem writing the asset
     */
    private function doDump(AssetInterface $asset, OutputInterface $output)
    {
        $target = rtrim($this->basePath, '/').'/'.str_replace('_controller/', '', $asset->getTargetPath());
        if (!is_dir($dir = dirname($target))) {
            $output->writeln('<info>[dir+]</info>  '.$dir);
            if (false === @mkdir($dir, 0777, true)) {
                throw new \RuntimeException('Unable to create directory '.$dir);
            }
        }

        $output->writeln('<info>[file+]</info> '.$target);
        if ($this->verbose) {
            if ($asset instanceof \Traversable) {
                foreach ($asset as $leaf) {
                    $root = $leaf->getSourceRoot();
                    $path = $leaf->getSourcePath();
                    $output->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
                }
            } else {
                $root = $asset->getSourceRoot();
                $path = $asset->getSourcePath();
                $output->writeln(sprintf('        <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
            }
        }

        if (false === @file_put_contents($target, $asset->dump())) {
            throw new \RuntimeException('Unable to write file '.$target);
        }
    }
}

La línea $output->writeln('<info>[file+]</info> '.$target); sí que se está ejecutando bien, pero luego se produce el RuntimeException, por lo que parece que file_put_contents($target, $asset->dump()) es false, lo que significa que algo está impidiendo crear el archivo.

Si puedes, añade algún echo, var_dump o cualquier otra cosa para comprobar si el código llega bien a ese punto y tiene listos los contenidos del archivo. Después, comprueba si se ejecuta bien o no la instrucción file_put_contents.

@tacheshun
Copy link

Hola,

A mi me pasa lo mismo en Windows(Wamp Server).
En mac no tengo ningun problema.

@javiereguiluz
Copy link
Owner

@tacheshun ¿ has probado lo que se comenta en #14 (comment) ?

@mprizmic
Copy link

Hola Javier:
según el libro los css están en
github.com/javiereguiluz/Cupon/blob/master/src/Cupon//Resources ......

bajé la aplicación y la ubicación sería sin "/blob/master"
Un saludo

@javiereguiluz
Copy link
Owner

@mprizmic en el libro se indica lo siguiente:

"[...] añade los siguientes archivos y copia los estilos de los archivos que se indican [...]":

Primero se indica el nombre del archivo de la aplicación (que como bien dices, no incluye blob/master) y después se indica la URL de Github desde donde te puedes bajar, si quieres, el CSS completo de la aplicación (al ser una URL de Github, esta sí que incluye blob/master)

@reposhat
Copy link

El problema está en el parametro $asset->dump().

Porque si creo una variable, que contenga un texto cualquiera, y lo reemplazo por $asset->dump(). Se generan todos los archivos dentro de web/css y web/js. (Obviamente todos los archivos tienen como contenido el string asignado a la variable....)

$actual = "Contenido";

if (false === @file_put_contents($target, $actual)) {
            throw new \RuntimeException('Unable to write file '.$target);
}

Habria que ver porque $asset->dump() no esta funcionando en Windows 7 + IIS7 + PHP 5.3.8

Nota: Nunca se llega a lanzar la excepcion new \RuntimeException('Unable to write file '.$target). El error que sale es [RuntimeException]
El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos.

@reposhat
Copy link

Bueno, por suerte ya pude solucionar el problema. Aparentemente es un problema que afecta a Windows.

Buscando un poco por stackoverlflow me encontre con el siguiente hilo. http://stackoverflow.com/questions/8195114/symfony2-assetics-yui-compressor-on-windows-path-syntax

Si siguen los pasos de Boo (Nov 19 '11 at 22:53), ya van a poder generar los archivos css y js. Y ver la aplicacion Cupon sin problemas.

A mi especificamente el archivo config.yml en la seccion assetic me quedo asi:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    java: C:\Program Files (x86)\Java\jre7\bin\java.exe
    filters:
        cssrewrite: ~
        yui_css:
            jar:      %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar
            apply_to: \.css$
        yui_js:
            jar:      %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar
            apply_to: \.js$

Luego modifiquen el metodo getProcess dentro del archivo \vendor\assetic\src\Assetic\Util\ProcessBuilder.php (Tal como dice bob en stackoverflow)

    public function getProcess()
    {
        if (!count($this->arguments)) {
            throw new \LogicException('You must add() command arguments before calling getProcess().');
        }

        $options = $this->options;

//Modificar
        if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
            $options += array('bypass_shell' => true);

            $args = $this->arguments;
            $cmd = array_shift($args);

            $script = '"'.$cmd.'"';
            if ($args) {
 //Modificar
                $script .= ' '.implode(' ', array_map('escapeshellarg', $args));
            }
        } else {
            $script = implode(' ', array_map('escapeshellarg', $this->arguments));
        }
        $env = $this->inheritEnv ? ($this->env ?: array()) + $_ENV : $this->env;

//Modificar
        return new Process($script, $this->cwd, null, $this->stdin, $this->timeout, $options);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants