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 __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) )
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__`. """ registry = request.environ['paste.registry'] setup_global_translator(registry=registry) response.scripts = Scripts() response.stylesheets = StyleSheets() response.feed_links = [] response.facebook = None response.warnings = [] request.perm = request.environ['mediadrop.perm'] 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)
class Facebook(object): 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) ) def init_code(self): return u'<div id="fb-root"></div>' + self.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)
def test_can_add_a_script(self): scripts = Scripts() scripts.add(Script('/foo.js')) assert_length(1, scripts)
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_scripts_during_instantiation(self): scripts = Scripts(Script('/foo.js'), Script('/bar.js')) assert_length(2, scripts)
def test_can_multiple_scripts(self): scripts = Scripts() scripts.add_all(Script('/foo.js'), Script('/bar.js')) assert_length(2, scripts)