示例#1
0
    def test_library_simple_js(self):
        ptah.library('test-lib', path='http://ptah.org/test.js', type='js')
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(lib.render(self.request),
                         '<script src="http://ptah.org/test.js"> </script>')
示例#2
0
    def test_library_include(self):
        ptah.library(
            'test-lib2', path='http://ptah.org/style.css', type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib2')
        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />')
示例#3
0
    def test_library_include(self):
        ptah.library('test-lib2', path='http://ptah.org/style.css', type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib2')
        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />'
        )
示例#4
0
    def test_library_View_include(self):
        ptah.library('test-lib', path='http://ptah.org/test.js', type='js')
        self.init_ptah()

        base = ptah.View(None, self.request)
        base.include('test-lib')

        self.assertEqual(base.render_includes(),
                         '<script src="http://ptah.org/test.js"> </script>')
示例#5
0
    def test_library_render_absurls(self):
        ptah.library('test-lib', path='http://ptah.org/style.css', type='css')
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />')
示例#6
0
    def test_library_render_absurls(self):
        ptah.library('test-lib', path='http://ptah.org/style.css', type='css')
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />'
        )
示例#7
0
    def test_library_View_include(self):
        ptah.library('test-lib', path='http://ptah.org/test.js', type='js')
        self.init_ptah()

        base = ptah.View(None, self.request)
        base.include('test-lib')

        self.assertEqual(
            base.render_includes(),
            '<script src="http://ptah.org/test.js"> </script>')
示例#8
0
    def test_library_simple_js(self):
        ptah.library(
            'test-lib', path='http://ptah.org/test.js', type='js')
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<script src="http://ptah.org/test.js"> </script>')
示例#9
0
    def test_library_render_with_extra(self):
        ptah.library(
            'test-lib', path='http://ptah.org/test.js', type='js',
            extra={'test': "extra"})
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<script test="extra" src="http://ptah.org/test.js"> </script>')
示例#10
0
    def test_library_render_with_prefix_postfix(self):
        ptah.library(
            'test-lib', path='http://ptah.org/style.css', type='css',
            prefix='<!--[if lt IE 7 ]>', postfix='<![endif]-->')
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<!--[if lt IE 7 ]><link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" /><![endif]-->')
示例#11
0
    def test_library_render_with_extra(self):
        ptah.library('test-lib',
                     path='http://ptah.org/test.js',
                     type='js',
                     extra={'test': "extra"})
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<script test="extra" src="http://ptah.org/test.js"> </script>')
示例#12
0
    def test_library_include_resource(self):
        self.config.add_static_view('tests30', 'ptah.tests:static/dir1')
        ptah.library(
            'test-lib-30',
            path='ptah.tests:static/dir1/style.css',
            type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib-30')

        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://example.com/tests30/style.css" />')
示例#13
0
    def test_library_include_resource(self):
        self.config.add_static_view('tests30', 'ptah.tests:static/dir1')
        ptah.library('test-lib-30',
                     path='ptah.tests:static/dir1/style.css',
                     type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib-30')

        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://example.com/tests30/style.css" />'
        )
示例#14
0
    def test_library_simple_css(self):
        self.config.add_static_view('tests30', 'ptah.tests:static/dir1')
        ptah.library('test-lib30', path='style.css', type='css')
        self.init_ptah()

        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib30']

        self.assertEqual(lib.name, 'test-lib30')
        self.assertEqual(len(lib.entries), 1)
        self.assertEqual(len(lib.entries), 1)
        self.assertTrue('style.css' in lib.entries[0].paths)

        self.assertEqual(repr(lib), '<ptah.Library "test-lib30">')
示例#15
0
    def test_library_include_recursive(self):
        ptah.library(
            'test-lib1-r', path='http://ptah.org/style1.css', type='css')

        ptah.library(
            'test-lib2-r', path='http://ptah.org/style2.css', type='css',
            require='test-lib1-r')

        ptah.library(
            'test-lib3-r', path='http://ptah.org/style3.css', type='css',
            require=('test-lib1-r', 'test-lib2-r'))

        ptah.library(
            'test-lib4-r', path='http://ptah.org/style4.css', type='css',
            require=('test-lib1-r', 'test-lib2-r'))
        self.init_ptah()

        ptah.include(self.request, 'test-lib3-r')
        ptah.include(self.request, 'test-lib4-r')

        self.assertEqual(
            ptah.render_includes(self.request),
"""<link type="text/css" rel="stylesheet" href="http://ptah.org/style1.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style2.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style3.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style4.css" />""")
示例#16
0
    def test_library_include_recursive(self):
        ptah.library('test-lib1-r',
                     path='http://ptah.org/style1.css',
                     type='css')

        ptah.library('test-lib2-r',
                     path='http://ptah.org/style2.css',
                     type='css',
                     require='test-lib1-r')

        ptah.library('test-lib3-r',
                     path='http://ptah.org/style3.css',
                     type='css',
                     require=('test-lib1-r', 'test-lib2-r'))

        ptah.library('test-lib4-r',
                     path='http://ptah.org/style4.css',
                     type='css',
                     require=('test-lib1-r', 'test-lib2-r'))
        self.init_ptah()

        ptah.include(self.request, 'test-lib3-r')
        ptah.include(self.request, 'test-lib4-r')

        self.assertEqual(
            ptah.render_includes(self.request),
            """<link type="text/css" rel="stylesheet" href="http://ptah.org/style1.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style2.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style3.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style4.css" />""")
示例#17
0
    def test_library_render_with_prefix_postfix(self):
        ptah.library('test-lib',
                     path='http://ptah.org/style.css',
                     type='css',
                     prefix='<!--[if lt IE 7 ]>',
                     postfix='<![endif]-->')
        self.init_ptah()
        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib']

        self.assertEqual(
            lib.render(self.request),
            '<!--[if lt IE 7 ]><link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" /><![endif]-->'
        )
示例#18
0
    def test_library_simple_css(self):
        self.config.add_static_view('tests30', 'ptah.tests:static/dir1')
        ptah.library('test-lib30',path='style.css',type='css')
        self.init_ptah()

        from ptah.library import LIBRARY_ID
        lib = ptah.get_cfg_storage(LIBRARY_ID)['test-lib30']

        self.assertEqual(lib.name, 'test-lib30')
        self.assertEqual(len(lib.entries), 1)
        self.assertEqual(len(lib.entries), 1)
        self.assertTrue('style.css' in lib.entries[0].paths)

        self.assertEqual(
            repr(lib), '<ptah.Library "test-lib30">')
示例#19
0
    def test_library_request(self):
        ptah.library('test-lib2', path='http://ptah.org/style.css', type='css')
        self.init_ptah()

        from pyramid.request import Request
        from pyramid.events import NewRequest
        from pyramid.config.factories import _set_request_properties

        req = Request(environ=self._environ)
        req.registry = self.registry
        _set_request_properties(NewRequest(req))

        req.include_library('test-lib2')
        self.assertEqual(
            req.render_includes(),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />')
示例#20
0
    # populate database
    config.ptah_populate()

    # Refer: Pyramid's _URL Dispatch_
    config.add_route('home', '/')
    config.add_route('home2', '/home2')

    # static assets
    config.add_static_view('_herokuapp', 'herokuapp:static')

    # js protocols
    config.include('herokuapp.protocols')

    # add role
    Admin = ptah.Role('admin', 'Admin')
    Manager = ptah.Role('manager', 'Manager')

    # Refer: Pyramid's _Configuration Decorations and Code Scanning_
    config.scan()

    return config.make_wsgi_app()


import ptah
ptah.library(
    'herokuapp-styles',
    path='herokuapp:static/styles.css',
    type="css",
    require=('bootstrap',))
 
示例#21
0
import ptah

# register colorpicker assets as library
ptah.library('colorpicker',
             path=('ptah_models:static/colorpicker/js/colorpicker.js',
                   'ptah_models:static/colorpicker/js/eye.js',
                   'ptah_models:static/colorpicker/js/utils.js'),
             type="js",
             require="jquery")

ptah.library('colorpicker',
             path=('ptah_models:static/colorpicker/css/colorpicker.css',
                   'ptah_models:static/colorpicker/css/layout.css'),
             type='css')


@ptah.form.field('colorpicker')
class ColorPickerField(ptah.form.InputField):
    __doc__ = u'Colorpicker input widget'

    klass = u'colorpicker-widget'
    value = u''

    tmpl_input = "ptah_models:templates/colorpicker-input.pt"
    tmpl_display = "ptah_models:templates/colorpicker-display.pt"


@ptah.form.fieldpreview(ColorPickerField)
def colorpickerPreview(request):
    field = ColorPickerField(
        'ColorPickerField',
示例#22
0
文件: __init__.py 项目: runyaga/ptah
""" assets libraries """
import ptah

# jQuery library
ptah.library(
    'jquery',
    path='ptah:static/jquery/jquery-1.7.min.js',
    type="js")

ptah.library(
    'jquery-ui',
    path='ptah:static/jquery/jquery-ui-1.8.16.min.js',
    type="js",
    require="jquery")

ptah.library(
    'jquery-ui',
    'ptah:static/jquery/jquery-ui.css',
    type='css')

# Bootstrap css
ptah.library(
    'bootstrap',
    path='ptah:static/bootstrap/bootstrap-1.4.0.min.css',
    type="css")

ptah.library(
    'bootstrap-js',
    path=('ptah:static/bootstrap/js/bootstrap-alerts.js',
          'ptah:static/bootstrap/js/bootstrap-buttons.js',
          'ptah:static/bootstrap/js/bootstrap-dropdown.js',
示例#23
0
    config.add_static_view('_gallery', 'gallery:static')

    # amd
    config.register_amd_module('gallery', 'gallery:static/app.js')

    # mustache
    config.register_mustache_bundle('gallery-tmpls', 'gallery:templates')

    # facebook
    config.add_route("facebook_process",
                     "/_facebook_auth",
                     use_global_views=True)
    config.add_view(route_name='facebook_process', view=facebook_process)

    # view photo
    config.add_route('view_photo', pattern='/_photos/{id}')

    # app route
    config.add_route('root', '/')
    config.add_view(route_name='root', renderer='gallery:app.pt')

    config.scan()
    return config.make_wsgi_app()


import ptah
ptah.library('gallery',
             path='gallery:static/styles.css',
             type="css",
             require=('bootstrap', ))
示例#24
0
import ptah


# register colorpicker assets as library
ptah.library(
    "colorpicker",
    path=(
        "ptah_models:static/colorpicker/js/colorpicker.js",
        "ptah_models:static/colorpicker/js/eye.js",
        "ptah_models:static/colorpicker/js/utils.js",
    ),
    type="js",
    require="jquery",
)

ptah.library(
    "colorpicker",
    path=("ptah_models:static/colorpicker/css/colorpicker.css", "ptah_models:static/colorpicker/css/layout.css"),
    type="css",
)


@ptah.form.field("colorpicker")
class ColorPickerField(ptah.form.InputField):
    __doc__ = u"Colorpicker input widget"

    klass = u"colorpicker-widget"
    value = u""

    tmpl_input = "ptah_models:templates/colorpicker-input.pt"
    tmpl_display = "ptah_models:templates/colorpicker-display.pt"
示例#25
0
文件: __init__.py 项目: webmaven/ptah
    # ptah ui classes
    config.register_amd_module(
        'ptah-form', 'ptah:static/form.js')
    config.register_amd_module(
        'ptah-form2', 'ptah:static/form.js')
    config.register_amd_module(
        'ptah-pager', 'ptah:static/pager.js')

    # templates
    config.register_mustache_bundle(
        'ptah-templates', 'ptah:templates/mustache/')


# jQuery library
ptah.library(
    'jquery-ui',
    'ptah:static/jquery/jquery-ui-1.8.20.css',
    type='css')

# Bootstrap css
ptah.library(
    'bootstrap',
    path='ptah:static/bootstrap/bootstrap.min.css',
    type="css")


# curl
ptah.library(
    'curl',
    path='ptah:static/lib/curl-0.6.2.js',
    type="js")