Beispiel #1
0
class CompilerTest(unittest.TestCase):
    def setUp(self):
        self.compiler = SASSCompiler()

        self.env = Environment(root=OUTPUT_DIR,
                               public_assets=(r'.*\.css', ),
                               fingerprinting=False)
        self.env.finders.register(FileSystemFinder([SCSS_DIR]))
        self.env.compilers.register('.scss', self.compiler.as_handler())
        self.env.register_defaults()
        self.env.save()

    def test_syntax(self):
        scss, css, output = fixture_load('syntax')
        self.assertEqual(css, output)

    def test_variables(self):
        scss, css, output = fixture_load('variables')
        self.assertEqual(css, output)

    def test_mixin(self):
        scss, css, output = fixture_load('mixin')
        self.assertEqual(css, output)

    def test_import(self):
        scss, css, output = fixture_load('import')
        self.assertEqual(css, output)

    def test_image(self):
        scss, css, output = fixture_load('image')
        self.assertEqual(css, output)
Beispiel #2
0
class CompilerTest(unittest.TestCase):
    def setUp(self):
        self.compiler = SASSCompiler()

        self.env = Environment(root=OUTPUT_DIR, public_assets=(r".*\.css",), fingerprinting=False)
        self.env.finders.register(FileSystemFinder([SCSS_DIR]))
        self.env.compilers.register(".scss", self.compiler.as_handler())
        self.env.register_defaults()
        self.env.save()

    def test_syntax(self):
        scss, css, output = fixture_load("syntax")
        self.assertEqual(css, output)

    def test_variables(self):
        scss, css, output = fixture_load("variables")
        self.assertEqual(css, output)

    def test_mixin(self):
        scss, css, output = fixture_load("mixin")
        self.assertEqual(css, output)

    def test_import(self):
        scss, css, output = fixture_load("import")
        self.assertEqual(css, output)

    def test_image(self):
        scss, css, output = fixture_load("image")
        self.assertEqual(css, output)
Beispiel #3
0
class Assets(object):
    """
    Uses the gears package to compile all .scss and .coffee files into CSS and JS
    """

    def __init__(self):
        project_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
        app_dir = os.path.join(project_dir, 'app')
        public_dir = os.path.join(project_dir, 'public')

        self.gears = Environment(public_dir, fingerprinting=False,
            manifest_path=False)
        self.gears.finders.register(ExtFinder(
            [app_dir],
            ['.coffee', '.scss', '.handlebars', '.js', '.css'],
            ['app.handlebars', 'partials/header.handlebars', 'partials/footer.handlebars']
        ))

        self.gears.compilers.register('.scss', LibsassCompiler.as_handler())
        self.gears.compilers.register('.coffee', CoffeeScriptCompiler.as_handler())
        self.gears.compilers.register('.handlebars', CustomHandlebarsCompiler.as_handler())

        if env.is_prod():
            self.gears.compressors.register('text/css', CleanCSSCompressor.as_handler())

        self.gears.register_defaults()

    def compile(self):
        """
        Perform the cross-compile of the assets
        """

        self.gears.save()
Beispiel #4
0
class Assets(object):
    """
    Uses the gears package to compile all .scss and .coffee files into CSS and JS
    """
    def __init__(self):
        project_dir = os.path.abspath(
            os.path.dirname(os.path.dirname(__file__)))
        app_dir = os.path.join(project_dir, 'app')
        public_dir = os.path.join(project_dir, 'public')

        self.gears = Environment(public_dir,
                                 public_assets=[self._public_assets],
                                 fingerprinting=False,
                                 manifest_path=False)
        self.gears.finders.register(
            ExtFinder([app_dir], ['.coffee', '.scss', '.handlebars'], [
                'app.handlebars', 'partials/header.handlebars',
                'partials/footer.handlebars'
            ]))

        self.gears.compilers.register('.scss', SCSSCompiler.as_handler())
        self.gears.compilers.register('.coffee',
                                      CoffeeScriptCompiler.as_handler())
        self.gears.compilers.register('.handlebars',
                                      CustomHandlebarsCompiler.as_handler())

        if env.is_prod():
            self.gears.compressors.register('text/css',
                                            CleanCSSCompressor.as_handler())

        self.gears.register_defaults()

    def _public_assets(self, path):
        """
        Method is used by gears to determine what should be copied/published

        Allows only the app.js and app.css files to be compiled, filtering out
        all others since they should be included via require, require_tree,
        etc directives. Also, anything not js or css will be allowed through.

        :param path:
            The filesystem path to check

        :return:
            If the path should be copied to the public folder
        """

        if path in ['js/app.js', 'css/app.css']:
            return True
        return not any(path.endswith(ext) for ext in ('.css', '.js'))

    def compile(self):
        """
        Perform the cross-compile of the assets
        """

        self.gears.save()
Beispiel #5
0
class Assets(object):
    """
    Uses the gears package to compile all .scss and .coffee files into CSS and JS
    """

    def __init__(self):
        project_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
        app_dir = os.path.join(project_dir, "app")
        public_dir = os.path.join(project_dir, "public")

        self.gears = Environment(
            public_dir, public_assets=[self._public_assets], fingerprinting=False, manifest_path=False
        )
        self.gears.finders.register(
            ExtFinder(
                [app_dir],
                [".coffee", ".scss", ".handlebars"],
                ["app.handlebars", "partials/header.handlebars", "partials/footer.handlebars"],
            )
        )

        self.gears.compilers.register(".scss", SCSSCompiler.as_handler())
        self.gears.compilers.register(".coffee", CoffeeScriptCompiler.as_handler())
        self.gears.compilers.register(".handlebars", CustomHandlebarsCompiler.as_handler())

        if env.is_prod():
            self.gears.compressors.register("text/css", CleanCSSCompressor.as_handler())

        self.gears.register_defaults()

    def _public_assets(self, path):
        """
        Method is used by gears to determine what should be copied/published

        Allows only the app.js and app.css files to be compiled, filtering out
        all others since they should be included via require, require_tree,
        etc directives. Also, anything not js or css will be allowed through.

        :param path:
            The filesystem path to check

        :return:
            If the path should be copied to the public folder
        """

        if path in ["js/app.js", "css/app.css"]:
            return True
        return not any(path.endswith(ext) for ext in (".css", ".js"))

    def compile(self):
        """
        Perform the cross-compile of the assets
        """

        self.gears.save()
Beispiel #6
0
class Assets(object):
    """
    Uses the gears package to compile all .scss and .coffee files into CSS and JS
    """

    def __init__(self):
        project_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
        app_dir = os.path.join(project_dir, 'app')
        public_dir = os.path.join(project_dir, 'public')

        self.gears = Environment(public_dir, public_assets=[self._public_assets])
        self.gears.finders.register(ExtFinder([app_dir], ['.coffee', '.scss', '.handlebars']))

        self.gears.compilers.register('.scss', SCSSCompiler.as_handler())
        self.gears.compilers.register('.coffee', CoffeeScriptCompiler.as_handler())
        self.gears.compilers.register('.handlebars', CustomHandlebarsCompiler.as_handler())

        if env.is_prod():
            self.gears.compressors.register('application/javascript', UglifyJSCompressor.as_handler())
            self.gears.compressors.register('text/css', CleanCSSCompressor.as_handler())

        self.gears.register_defaults()


    def _public_assets(self, path):
        """
        Method is used by gears to determine what should be copied/published

        Allows only the app.js and app.css files to be compiled, filtering out
        all others since they should be included via require, require_tree,
        etc directives. Also, anything not js or css will be allowed through.

        :param path:
            The filesystem path to check

        :return:
            If the path should be copied to the public folder
        """

        if path in ['js/app.js', 'js/package.js', 'css/app.css']:
            return True
        return not any(path.endswith(ext) for ext in ('.css', '.js'))

    def compile(self):
        """
        Perform the cross-compile of the assets
        """

        self.gears.save()
Beispiel #7
0
class CompilerTest(unittest.TestCase):

    def setUp(self):
        self.compiler = JSXCompiler()

        self.env = Environment(root=OUTPUT_DIR, public_assets=(r'.*\.js',),
                               fingerprinting=False)
        self.env.finders.register(FileSystemFinder([JSX_DIR]))
        self.env.compilers.register('.jsx', self.compiler.as_handler())
        self.env.register_defaults()
        self.env.save()

    def test_transform(self):
        jsx, js, output = fixture_load('transform')
        self.assertEqual(js, output)
Beispiel #8
0
class Assets(object):
    """
    Uses the gears package to compile all .scss and .coffee files into CSS and JS
    """
    def __init__(self):
        project_dir = os.path.abspath(
            os.path.dirname(os.path.dirname(__file__)))
        app_dir = os.path.join(project_dir, 'app')
        public_dir = os.path.join(project_dir, 'public')

        self.gears = Environment(public_dir,
                                 fingerprinting=False,
                                 manifest_path=False)
        self.gears.finders.register(
            ExtFinder([app_dir],
                      ['.coffee', '.scss', '.handlebars', '.js', '.css'], [
                          'app.handlebars', 'partials/header.handlebars',
                          'partials/footer.handlebars'
                      ]))

        self.gears.compilers.register('.scss', LibsassCompiler.as_handler())
        self.gears.compilers.register('.coffee',
                                      CoffeeScriptCompiler.as_handler())
        self.gears.compilers.register('.handlebars',
                                      CustomHandlebarsCompiler.as_handler())

        if env.is_prod():
            self.gears.compressors.register('text/css',
                                            CleanCSSCompressor.as_handler())

        self.gears.register_defaults()

    def compile(self):
        """
        Perform the cross-compile of the assets
        """

        self.gears.save()
Beispiel #9
0
import os

from gears.environment import Environment
from gears.finders import FileSystemFinder

from gears_handlebars import HandlebarsCompiler


ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
ASSETS_DIR = os.path.join(ROOT_DIR, 'assets')
STATIC_DIR = os.path.join(ROOT_DIR, 'static')

env = Environment(STATIC_DIR)
env.finders.register(FileSystemFinder([ASSETS_DIR]))
env.compilers.register('.hbs', HandlebarsCompiler.as_handler())
env.register_defaults()


if __name__ == '__main__':
    env.save()
Beispiel #10
0
      path = path.lstrip('/')
      fingerprint_path = env.manifest.files[path]

      asset[path_type] = fingerprint_path

  with open(filename, 'wb') as f:
    f.write(unicode(soup.prettify()))


def delete_dest():
  if os.path.exists(DEST_DIR):
    shutil.rmtree(DEST_DIR)


if __name__ == '__main__':
  #clean slate
  delete_dest()

  #defines where files will be emitted
  env = Environment(DEST_DIR, public_assets=(
    lambda path: any(path.endswith(ext) for ext in ('.css', '.js', '.html')),
    lambda path: any(path.startswith(ext) for ext in ('fonts', 'images')))
  )

  env.finders.register(FileSystemFinder([SOURCE_DIR]))
  env.register_defaults()

  env.save()
  reference_fingerprinted_files(env)
  delete_unused_files(env.manifest)