Beispiel #1
0
class Resource(TwistedResource):
    """
    Mamba resources base class. A web accessible resource that add common
    properties for scripts in Mamba applications
    """

    _styles_manager = appstyles.AppStyles()
    _scripts_manager = scripts.AppScripts()

    def __init__(self):
        TwistedResource.__init__(self)

        config = Application()

        # headers and render keys for root_page and index templates
        header = headers.Headers()
        self.render_keys = {
            'doctype': header.get_doctype(),
            'header': {
                'title': config.name,
                'content_type': header.content_type,
                'generator_content': header.get_generator_content(),
                'description_content': header.get_description_content(),
                'language_content': header.get_language_content(),
                'mamba_content': header.get_mamba_content(),
                'media': header.get_favicon_content('assets'),
                'styles': self._styles_manager.get_styles().values(),
                'scripts': self._scripts_manager.get_scripts().values(),
                'lessjs': Application().lessjs
            }
        }
Beispiel #2
0
    def test_shared_packages_styles(self):

        chdir(self.currdir)
        sys.path.append('../mamba/test/dummy_app')
        config_file = tempfile.NamedTemporaryFile(delete=False)
        config_file.write(
            '{'
            '   "packages": {'
            '       "fakeshared": {"autoimport": true, "use_scripts": true}'
            '   }'
            '}')
        config_file.close()
        mgr = appstyles.AppStyles(config_file_name=config_file.name)
        mgr.setup()
        self.assertEqual(len(mgr.managers), 2)
        self.assertEqual(
            mgr.managers[0]._styles_store,
            '../mamba/test/dummy_app/fakeshared/view/stylesheets')
        self.assertTrue('dummyshared.css' in mgr.managers[0]._stylesheets)
        filepath.FilePath(config_file.name).remove()
Beispiel #3
0
 def setUp(self):
     self.currdir = getcwd()
     chdir('../mamba/test/dummy_app/')
     self.mgr = appstyles.AppStyles()
Beispiel #4
0
    def __init__(self, template_paths=None, cache_size=50):
        TwistedResource.__init__(self)

        sep = filepath.os.sep
        self._templates = {}
        self.cache_size = cache_size
        self.template_paths = [
            'application/view/templates', '{}/templates/jinja'.format(
                filepath.os.path.dirname(__file__).rsplit(sep, 1)[0])
        ]
        if template_paths is not None:
            if type(template_paths) is str:
                self.template_paths.append(template_paths)
            elif type(template_paths) is list:
                self.template_paths + template_paths
            elif type(template_paths) is tuple:
                self.template_paths + list(template_paths)

        self.config = Application()

        # set resources managers
        self._styles_manager = appstyles.AppStyles()
        self._scripts_manager = scripts.Scripts()

        # headers and render keys for root_page and index templates
        header = headers.Headers()
        self.render_keys = {
            'doctype': header.get_doctype(),
            'header': {
                'title': self.config.name,
                'content_type': header.content_type,
                'generator_content': header.get_generator_content(),
                'description_content': header.get_description_content(),
                'language_content': header.get_language_content(),
                'mamba_content': header.get_mamba_content(),
                'media': header.get_favicon_content('assets'),
                'styles': self._styles_manager.get_styles().values(),
                'scripts': self._scripts_manager.get_scripts().values()
            }
        }

        # containers
        self.containers = {
            'styles': static.Data('', 'text/css'),
            'scripts': static.Data('', 'text/javascript')
        }

        # register containers
        self.putChild('styles', self.containers['styles'])
        self.putChild('scripts', self.containers['scripts'])

        # insert stylesheets
        self.insert_stylesheets()

        # insert scripts
        self.insert_scripts()

        # static accessible data (scripts, css, images, and others)
        self.putChild('assets', static.File(filepath.os.getcwd() + '/static'))

        # template environment
        self.environment = templating.Environment(
            autoescape=lambda name: (name.rsplit('.', 1)[1] == 'html'
                                     if name is not None else False),
            cache_size=self.cache_size,
            loader=templating.FileSystemLoader(self.template_paths))
Beispiel #5
0
 def setUp(self):
     self.mgr = appstyles.AppStyles()