예제 #1
0
 def test_list(self):
     finder = FileSystemFinder([ASSETS_DIR])
     self.assertItemsEqual(finder.list('js/templates/*'), (
         ('js/templates/readme.txt', os.path.join(ASSETS_DIR, 'js/templates/readme.txt')),
         ('js/templates/a.js.handlebars', os.path.join(ASSETS_DIR, 'js/templates/a.js.handlebars')),
         ('js/templates/b.js.handlebars', os.path.join(ASSETS_DIR, 'js/templates/b.js.handlebars')),
         ('js/templates/c.js.handlebars', os.path.join(ASSETS_DIR, 'js/templates/c.js.handlebars')),
     ))
예제 #2
0
    def test_find_all_if_does_not_exist(self):
        finder = FileSystemFinder(('/first', '/second', '/third'))
        finder.find_location = Mock(return_value=False)

        self.assertEqual(list(finder.find_all('js/script.js')), [])
        self.assertEqual(finder.find_location.call_args_list, [
            (('/first', 'js/script.js'), {}),
            (('/second', 'js/script.js'), {}),
            (('/third', 'js/script.js'), {})])
예제 #3
0
    def test_find_all_if_does_not_exist(self):
        finder = FileSystemFinder(('/first', '/second', '/third'))
        finder.find_location = Mock(return_value=False)

        self.assertEqual(list(finder.find_all('js/script.js')), [])
        self.assertEqual(finder.find_location.call_args_list,
                         [(('/first', 'js/script.js'), {}),
                          (('/second', 'js/script.js'), {}),
                          (('/third', 'js/script.js'), {})])
예제 #4
0
    def test_find_all_if_does_not_exist(self):
        finder = FileSystemFinder(("/first", "/second", "/third"))
        finder.find_location = Mock(return_value=False)

        self.assertEqual(list(finder.find_all("js/script.js")), [])
        self.assertEqual(
            finder.find_location.call_args_list,
            [(("/first", "js/script.js"), {}), (("/second", "js/script.js"), {}), (("/third", "js/script.js"), {})],
        )
예제 #5
0
 def test_find(self):
     finder = FileSystemFinder([ASSETS_DIR])
     self.assertItemsEqual(
         finder.list("js/templates"),
         (
             ("js/templates/readme.txt", os.path.join(ASSETS_DIR, "js/templates/readme.txt")),
             ("js/templates/a.js.handlebars", os.path.join(ASSETS_DIR, "js/templates/a.js.handlebars")),
             ("js/templates/b.js.handlebars", os.path.join(ASSETS_DIR, "js/templates/b.js.handlebars")),
             ("js/templates/c.js.handlebars", os.path.join(ASSETS_DIR, "js/templates/c.js.handlebars")),
         ),
     )
예제 #6
0
    def test_find_all_if_exists(self):
        def find_location(root, path):
            if root != "/first":
                return os.path.join(root, path)

        finder = FileSystemFinder(("/first", "/second", "/third"))
        finder.find_location = Mock(side_effect=find_location)

        paths = list(finder.find_all("js/script.js"))
        self.assertEqual(paths, ["/second/js/script.js", "/third/js/script.js"])
        self.assertEqual(
            finder.find_location.call_args_list,
            [(("/first", "js/script.js"), {}), (("/second", "js/script.js"), {}), (("/third", "js/script.js"), {})],
        )
예제 #7
0
    def test_find_all_if_exists(self):

        def find_location(root, path):
            if root != '/first':
                return os.path.join(root, path)

        finder = FileSystemFinder(('/first', '/second', '/third'))
        finder.find_location = Mock(side_effect=find_location)

        paths = list(finder.find_all('js/script.js'))
        self.assertEqual(paths, ['/second/js/script.js', '/third/js/script.js'])
        self.assertEqual(finder.find_location.call_args_list, [
            (('/first', 'js/script.js'), {}),
            (('/second', 'js/script.js'), {}),
            (('/third', 'js/script.js'), {})])
예제 #8
0
    def test_find_all_if_exists(self):
        def find_location(root, path):
            if root != '/first':
                return os.path.join(root, path)

        finder = FileSystemFinder(('/first', '/second', '/third'))
        finder.find_location = Mock(side_effect=find_location)

        paths = list(finder.find_all('js/script.js'))
        self.assertEqual(paths,
                         ['/second/js/script.js', '/third/js/script.js'])
        self.assertEqual(finder.find_location.call_args_list,
                         [(('/first', 'js/script.js'), {}),
                          (('/second', 'js/script.js'), {}),
                          (('/third', 'js/script.js'), {})])
예제 #9
0
    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()
예제 #10
0
 def test_find_if_exists(self):
     finder = FileSystemFinder(('/first', '/second', '/third'))
     finder.find_all = Mock(return_value=('/second/js/script.js',
                                          '/third/js/script.js'))
     self.assertEqual(finder.find('js/script.js'), '/second/js/script.js')
     finder.find_all.assert_called_once_with('js/script.js')
예제 #11
0
 def test_find_location_if_does_not_exist(self, exists):
     exists.return_value = False
     finder = FileSystemFinder(('/assets', ))
     self.assertIsNone(finder.find_location('/assets', 'js/script.js'))
     exists.assert_called_once_with('/assets/js/script.js')
예제 #12
0
 def test_find_location_if_exists(self, exists):
     exists.return_value = True
     finder = FileSystemFinder(('/assets', ))
     location = finder.find_location('/assets', 'js/script.js')
     self.assertEqual(location, '/assets/js/script.js')
     exists.assert_called_once_with('/assets/js/script.js')
예제 #13
0
 def test_if_directories_is_not_iterable(self):
     with self.assertRaises(ImproperlyConfigured):
         finder = FileSystemFinder('/first')
예제 #14
0
 def test_initialization(self):
     finder = FileSystemFinder(('/first', '/second', '/third', '/first'))
     self.assertEqual(finder.locations, ['/first', '/second', '/third'])
예제 #15
0
 def get_default_finder(self, app):
     return FileSystemFinder(directories=(self.get_assets_folder(app), ))
예제 #16
0
 def test_find_if_exists(self):
     finder = FileSystemFinder(("/first", "/second", "/third"))
     finder.find_all = Mock(return_value=("/second/js/script.js", "/third/js/script.js"))
     self.assertEqual(finder.find("js/script.js"), "/second/js/script.js")
     finder.find_all.assert_called_once_with("js/script.js")
예제 #17
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)
예제 #18
0
 def test_list_empty_if_path_isnt_dir(self):
     finder = FileSystemFinder([ASSETS_DIR])
     self.assertItemsEqual(finder.list('js/templates/readme.txt'), ())
예제 #19
0
 def test_find_if_does_not_exist(self):
     finder = FileSystemFinder(('/first', '/second', '/third'))
     finder.find_all = Mock(return_value=())
     with self.assertRaises(FileNotFound):
         finder.find('js/script.js')
     finder.find_all.assert_called_once_with('js/script.js')
예제 #20
0
 def test_find_if_does_not_exist(self):
     finder = FileSystemFinder(('/first', '/second', '/third'))
     finder.find_all = Mock(return_value=())
     with self.assertRaises(FileNotFound):
         finder.find('js/script.js')
     finder.find_all.assert_called_once_with('js/script.js')
예제 #21
0
 def test_find_if_exists(self):
     finder = FileSystemFinder(('/first', '/second', '/third'))
     finder.find_all = Mock(return_value=(
         '/second/js/script.js', '/third/js/script.js'))
     self.assertEqual(finder.find('js/script.js'), '/second/js/script.js')
     finder.find_all.assert_called_once_with('js/script.js')
예제 #22
0
 def test_find_location_if_does_not_exist(self, exists):
     exists.return_value = False
     finder = FileSystemFinder(('/assets',))
     self.assertIsNone(finder.find_location('/assets', 'js/script.js'))
     exists.assert_called_once_with('/assets/js/script.js')
예제 #23
0
 def test_find_location_if_exists(self, exists):
     exists.return_value = True
     finder = FileSystemFinder(('/assets',))
     location = finder.find_location('/assets', 'js/script.js')
     self.assertEqual(location, '/assets/js/script.js')
     exists.assert_called_once_with('/assets/js/script.js')
예제 #24
0
 def test_list_empty_if_path_isnt_dir(self):
     finder = FileSystemFinder([ASSETS_DIR])
     self.assertItemsEqual(finder.list('js/templates/readme.txt'), ())
예제 #25
0
 def setUp(self):
     self.environment = Environment(STATIC_DIR)
     self.environment.register_defaults()
     self.environment.finders.register(FileSystemFinder([ASSETS_DIR]))
예제 #26
0
 def test_list_empty_if_path_doesnt_exist(self):
     finder = FileSystemFinder([ASSETS_DIR])
     self.assertItemsEqual(finder.list('js/views'), ())
예제 #27
0
 def test_find_if_does_not_exist(self):
     finder = FileSystemFinder(("/first", "/second", "/third"))
     finder.find_all = Mock(return_value=())
     with self.assertRaises(FileNotFound):
         finder.find("js/script.js")
     finder.find_all.assert_called_once_with("js/script.js")
예제 #28
0
 def get_finder(self, fixture):
     fixture_path = self.get_fixture_path(fixture)
     return FileSystemFinder([fixture_path])
예제 #29
0
 def test_list_empty_if_path_doesnt_exist(self):
     finder = FileSystemFinder([ASSETS_DIR])
     self.assertItemsEqual(finder.list('js/views/*'), ())
예제 #30
0
 def get_finder(self, fixture):
     return FileSystemFinder([self.get_fixture_path(fixture)])
예제 #31
0
import os

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

from gears_babel import Babel6to5Compiler

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('.jsx', Babel6to5Compiler.as_handler())
env.register_defaults()

if __name__ == '__main__':
    env.save()