def test_can_render_markup_for_all_scripts(self):
     foo_script = Script('/foo.js')
     bar_script = Script('/bar.js')
     scripts = Scripts()
     scripts.add(foo_script)
     scripts.add(bar_script)
     assert_equals(foo_script.render()+bar_script.render(), scripts.render())
Пример #2
0
 def test_can_render_markup_for_all_scripts(self):
     foo_script = Script('/foo.js')
     bar_script = Script('/bar.js')
     scripts = Scripts()
     scripts.add(foo_script)
     scripts.add(bar_script)
     assert_equals(foo_script.render()+bar_script.render(), scripts.render())
 def test_can_replace_script_with_key(self):
     foo_script = Script('/foo.js', key='foo')
     bar_script = Script('/bar.js', key='foo')
     
     scripts = Scripts()
     scripts.add(foo_script)
     scripts.replace_script_with_key(bar_script)
     assert_length(1, scripts)
     assert_contains(bar_script, scripts.scripts)
Пример #4
0
 def __init__(self, app_id):
     self.app_id = app_id
     self.scripts = Scripts(
         FacebookSDKScript(self.app_id), 
         # '//' is a protocol-relative URL, uses HTTPS if the page uses HTTPS
         Script('//connect.facebook.net/en_US/all.js', async=True)
     )
class Facebook(object):
    def __init__(self, app_id):
        self.app_id = app_id
        self.scripts = Scripts(
            FacebookSDKScript(self.app_id), 
            Script('//connect.facebook.net/en_US/all.js', async=True)
        )
    
    def init_code(self):
        # '//' is a protocol-relative URL, uses HTTPS if the page uses HTTPS
        return u'<div id="fb-root"></div>' + self.scripts.render()
Пример #6
0
    def test_can_replace_script_with_key(self):
        foo_script = Script('/foo.js', key='foo')
        bar_script = Script('/bar.js', key='foo')

        scripts = Scripts()
        scripts.add(foo_script)
        scripts.replace_script_with_key(bar_script)
        assert_length(1, scripts)
        assert_contains(bar_script, scripts.scripts)
Пример #7
0
    def __before__(self, *args, **kwargs):
        """This method is called before your action is.

        It should be used for setting up variables/objects, restricting access
        to other actions, or other tasks which should be executed before the
        action is called.

        NOTE: If this method is wrapped in an ActionProtector, all methods of
              the class will be protected it. See :meth:`__init__`.
        """
        self.setup_translator()
        response.scripts = Scripts()
        response.stylesheets = StyleSheets()
        response.facebook = None

        action_method = getattr(self, kwargs['action'], None)
        # The expose decorator sets the exposed attribute on controller
        # actions. If the method does not exist or is not exposed, raise
        # an HTTPNotFound exception.
        if not getattr(action_method, 'exposed', False):
            abort(status_code=404)
 def test_uses_non_async_if_conflicting_variants_are_added(self):
     scripts = Scripts()
     scripts.add(Script('/foo.js', async=True))
     assert_length(1, scripts)
     assert_true(scripts.scripts[0].async)
 def test_does_not_add_duplicate_scripts(self):
     scripts = Scripts()
     scripts.add(Script('/foo.js'))
     scripts.add(Script('/foo.js'))
     assert_length(1, scripts)
 def test_can_add_a_script(self):
     scripts = Scripts()
     scripts.add(Script('/foo.js'))
     assert_length(1, scripts)
Пример #11
0
 def test_uses_non_async_if_conflicting_variants_are_added(self):
     scripts = Scripts()
     scripts.add(Script('/foo.js', async=True))
     assert_length(1, scripts)
     assert_true(scripts.scripts[0]. async)
Пример #12
0
 def test_does_not_add_duplicate_scripts(self):
     scripts = Scripts()
     scripts.add(Script('/foo.js'))
     scripts.add(Script('/foo.js'))
     assert_length(1, scripts)
Пример #13
0
 def test_can_add_scripts_during_instantiation(self):
     scripts = Scripts(Script('/foo.js'), Script('/bar.js'))
     assert_length(2, scripts)
Пример #14
0
 def test_can_add_a_script(self):
     scripts = Scripts()
     scripts.add(Script('/foo.js'))
     assert_length(1, scripts)
 def __init__(self, app_id):
     self.app_id = app_id
     self.scripts = Scripts(
         FacebookSDKScript(self.app_id), 
         Script('//connect.facebook.net/en_US/all.js', async=True)
     )
Пример #16
0
 def test_can_multiple_scripts(self):
     scripts = Scripts()
     scripts.add_all(Script('/foo.js'), Script('/bar.js'))
     assert_length(2, scripts)