コード例 #1
0
    def test_it(self):
        from statics.configuration import query_item_factory
        from statics.configuration import add_item_factory

        class ItemFactory(object):
            pass

        add_item_factory("ext", ItemFactory)
        self.assertEqual(query_item_factory("ext"), ItemFactory)
        self.assertEqual(query_item_factory("ext2"), None)
コード例 #2
0
ファイル: source.py プロジェクト: andreypopp/statics
 def _build(self, fileinfo):
     if self._belongs_to_exclude(fileinfo):
         return BinaryItem(fileinfo.name, filename=fileinfo.filename)
     factory = query_item_factory(fileinfo.extension)
     if factory is None:
         if text_file(fileinfo.filename):
             return ContentItem(fileinfo.name, fileinfo.filename)
         else:
             return BinaryItem(fileinfo.basename, fileinfo.filename)
     else:
         return factory(fileinfo.name, fileinfo.filename)
コード例 #3
0
ファイル: source.py プロジェクト: andreypopp/statics
    def _build(self, dirinfo):
        if self._belongs_to_exclude(dirinfo):
            return BinaryItem(dirinfo.name, filename=dirinfo.filename)
        files = OrderedDict((x.name, x) for x
            in unique_sorted_listing(dirinfo.filename,
                extension_priority=self.extension_priority))

        if self.directory_item_name in files \
          and text_file(files[self.directory_item_name].filename):
            info = files.pop(self.directory_item_name)
            factory = query_item_factory(info.extension, default=ContentItem)
            item = lambda children: factory(
                dirinfo.name, info.filename, info.extension, children=children)
        else:
            item = lambda children: Item(dirinfo.name, children=children)
        children = [self._build(x) for x in files.values()]
        return item(children)