當前位置: 首頁>>代碼示例>>Python>>正文


Python environment.Environment類代碼示例

本文整理匯總了Python中gears.environment.Environment的典型用法代碼示例。如果您正苦於以下問題:Python Environment類的具體用法?Python Environment怎麽用?Python Environment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Environment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Assets

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()
開發者ID:wbond,項目名稱:packagecontrol.io,代碼行數:33,代碼來源:assets.py

示例2: CompilerTest

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)
開發者ID:ChillyBwoy,項目名稱:gears-sass,代碼行數:29,代碼來源:test_compiler.py

示例3: EnvironmentListTests

class EnvironmentListTests(TestCase):
    def setUp(self):
        self.environment = Environment(STATIC_DIR)
        self.environment.register_defaults()
        self.environment.finders.register(FileSystemFinder([ASSETS_DIR]))

    def test_list(self):
        items = list(self.environment.list("js/templates", "application/javascript"))
        self.assertEqual(len(items), 3)
        for i, item in enumerate(sorted(items, key=lambda x: x[1])):
            path = "js/templates/%s.js.handlebars" % "abc"[i]
            asset_attributes, absolute_path = item
            self.assertIsInstance(asset_attributes, AssetAttributes)
            self.assertEqual(asset_attributes.path, path)
            self.assertEqual(absolute_path, os.path.join(ASSETS_DIR, path))

    def test_list_recursively(self):
        items = list(self.environment.list("js/templates", "application/javascript", recursive=True))
        self.assertEqual(len(items), 4)
        for i, item in enumerate(sorted(items, key=lambda x: x[1])):
            path = "js/templates/%s.js.handlebars" % ("a", "b", "c", "d/e")[i]
            asset_attributes, absolute_path = item
            self.assertIsInstance(asset_attributes, AssetAttributes)
            self.assertEqual(asset_attributes.path, path)
            self.assertEqual(absolute_path, os.path.join(ASSETS_DIR, path))
開發者ID:jjay,項目名稱:gears,代碼行數:25,代碼來源:test_environment.py

示例4: AbstractSassCompilerTestCase

class AbstractSassCompilerTestCase(unittest.TestCase):

    def setUp(self):
        self.output_files = []
        self.addCleanup(self.remove_output_files)

    def remove_output_files(self):
        output_glob = path.join(fixtures_dir, "output", "*")
        for output_file in glob.glob(output_glob):
            if path.isdir(output_file):
                shutil.rmtree(output_file)
            else:
                os.remove(output_file)

    def setup_environment(self, directory):
        os.chdir(directory)
        self.environment = Environment(
            root=path.join(fixtures_dir, "output"),
            public_assets=(r".*\.css",),
            fingerprinting=False,
        )
        self.compiler = SASSCompiler()
        self.environment.compilers.register(".scss", self.compiler)
        self.environment.finders.register(FileSystemFinder(directories=(directory,)))
        self.environment.register_defaults()
開發者ID:alexjg,項目名稱:gears-libsass,代碼行數:25,代碼來源:test_compiles.py

示例5: Assets

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()
開發者ID:joneshf,項目名稱:sublime.wbond.net,代碼行數:49,代碼來源:assets.py

示例6: CompilerTest

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)
開發者ID:ChillyBwoy,項目名稱:gears-jsx,代碼行數:15,代碼來源:test_compiler.py

示例7: EnvironmentListTests

class EnvironmentListTests(TestCase):

    def setUp(self):
        self.environment = Environment(STATIC_DIR)
        self.environment.register_defaults()
        self.environment.finders.register(FileSystemFinder([ASSETS_DIR]))

    def test_list(self):
        items = list(self.environment.list('js/templates', ['.js', '.handlebars']))
        self.assertEqual(len(items), 3)
        for i, item in enumerate(sorted(items, key=lambda x: x[1])):
            path = 'js/templates/%s.js.handlebars' % 'abc'[i]
            asset_attributes, absolute_path = item
            self.assertIsInstance(asset_attributes, AssetAttributes)
            self.assertEqual(asset_attributes.path, path)
            self.assertEqual(absolute_path, os.path.join(ASSETS_DIR, path))
開發者ID:xobb1t,項目名稱:gears,代碼行數:16,代碼來源:test_environment.py

示例8: EnvironmentTests

class EnvironmentTests(TestCase):
    def setUp(self):
        self.environment = Environment(STATIC_DIR)

    def test_suffixes(self):
        self.environment.mimetypes.register(".css", "text/css")
        self.environment.mimetypes.register(".txt", "text/plain")
        self.environment.compilers.register(".styl", FakeCompiler("text/css"))
        self.assertItemsEqual(self.environment.suffixes.find(), [".css", ".styl", ".css.styl", ".txt"])

    def test_register_defaults(self):
        self.environment.mimetypes = Mock()
        self.environment.preprocessors = Mock()
        self.environment.register_defaults()
        self.environment.mimetypes.register_defaults.assert_called_once_with()
        self.environment.preprocessors.register_defaults.assert_called_once_with()
開發者ID:jjay,項目名稱:gears,代碼行數:16,代碼來源:test_environment.py

示例9: setUp

    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()
開發者ID:ChillyBwoy,項目名稱:gears-sass,代碼行數:8,代碼來源:test_compiler.py

示例10: init_environment

 def init_environment(self, app):
     environment = Environment(
         root=self.get_static_folder(app),
         public_assets=self.get_public_assets(app),
         cache=self.get_cache(app),
         gzip=self.gzip,
     )
     if self.defaults:
         environment.register_defaults()
         environment.finders.register(self.get_default_finder(app))
     if self.compilers is not None:
         for extension, compiler in self.compilers.items():
             environment.compilers.register(extension, compiler)
     if self.compressors is not None:
         for mimetype, compressor in self.compressors.items():
             environment.compressors.register(mimetype, compressor)
     app.extensions['gears']['environment'] = environment
開發者ID:adellahlou,項目名稱:hpit_services,代碼行數:17,代碼來源:flask_gears.py

示例11: setUp

    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()
開發者ID:ChillyBwoy,項目名稱:gears-jsx,代碼行數:9,代碼來源:test_compiler.py

示例12: setup_environment

 def setup_environment(self, directory):
     os.chdir(directory)
     self.environment = Environment(
         root=path.join(fixtures_dir, "output"),
         public_assets=(r".*\.css",),
         fingerprinting=False,
     )
     self.compiler = SASSCompiler()
     self.environment.compilers.register(".scss", self.compiler)
     self.environment.finders.register(FileSystemFinder(directories=(directory,)))
     self.environment.register_defaults()
開發者ID:alexjg,項目名稱:gears-libsass,代碼行數:11,代碼來源:test_compiles.py

示例13: EnvironmentTests

class EnvironmentTests(TestCase):

    def setUp(self):
        self.environment = Environment(STATIC_DIR)

    def test_suffixes(self):
        self.environment.mimetypes.register('.css', 'text/css')
        self.environment.mimetypes.register('.txt', 'text/plain')
        self.environment.compilers.register('.styl', FakeCompiler('text/css'))
        self.assertItemsEqual(self.environment.suffixes.find(),
                              ['.css', '.css.styl', '.txt'])

    def test_register_defaults(self):
        self.environment.compilers = Mock()
        self.environment.mimetypes = Mock()
        self.environment.public_assets = Mock()
        self.environment.preprocessors = Mock()
        self.environment.register_defaults()
        self.environment.compilers.register_defaults.assert_called_once_with()
        self.environment.mimetypes.register_defaults.assert_called_once_with()
        self.environment.public_assets.register_defaults.assert_called_once_with()
        self.environment.preprocessors.register_defaults.assert_called_once_with()
開發者ID:xobb1t,項目名稱:gears,代碼行數:22,代碼來源:test_environment.py

示例14: __init__

    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()
開發者ID:joneshf,項目名稱:sublime.wbond.net,代碼行數:17,代碼來源:assets.py

示例15: __init__

    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()
開發者ID:wbond,項目名稱:packagecontrol.io,代碼行數:21,代碼來源:assets.py


注:本文中的gears.environment.Environment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。