def test_interpolate_cache_slug(self): with self.swap(feconf, 'DEV_MODE', True): utils.ASSET_DIR_PREFIX = None cache_slug = utils.get_asset_dir_prefix() parsed_str = jinja_utils.interpolate_cache_slug('{{cache_slug}}') self.assertEqual(parsed_str, '%s' % cache_slug) with self.swap(feconf, 'DEV_MODE', False): utils.ASSET_DIR_PREFIX = None cache_slug = utils.get_asset_dir_prefix() parsed_str = jinja_utils.interpolate_cache_slug('{{cache_slug}}') self.assertEqual(parsed_str, '%s' % cache_slug) with self.swap(feconf, 'IS_MINIFIED', True): utils.ASSET_DIR_PREFIX = None cache_slug = utils.get_asset_dir_prefix() parsed_str = jinja_utils.interpolate_cache_slug('{{cache_slug}}') self.assertEqual(parsed_str, '%s' % cache_slug) cache_slug = utils.get_asset_dir_prefix() parsed_str = jinja_utils.interpolate_cache_slug( '{{cache_slug}}/test/test.css') self.assertEqual(parsed_str, '%s/test/test.css' % cache_slug) # cache slug parameter is missing. parsed_str = jinja_utils.interpolate_cache_slug( '{{invalid_test}}/test/test.css') self.assertEqual(parsed_str, '/test/test.css')
def get_deps_html_and_angular_modules(cls, dependency_ids): """Returns data needed to load the given dependencies. The return value is a 2-tuple. The first element of the tuple is the additional HTML to insert on the page. The second element of the tuple is a de-duplicated list of strings, each representing an additional angular module that should be loaded. """ html = '\n'.join( [cls.get_dependency_html(dep) for dep in set(dependency_ids)]) # Html content for interactions is loaded using get_dependency_html # method. This content is then interpolated using Jinja. Interactions # such as logicproof contain jinja like variables that need to be # interpolated. LogicProof contains a cache slug variable that is # interpolated using interpolate_cache_slug method. html = jinja_utils.interpolate_cache_slug(html) angular_modules_for_each_dep = [ cls.get_angular_modules(dep) for dep in set(dependency_ids) ] deduplicated_angular_modules = list( set( list( itertools.chain.from_iterable( angular_modules_for_each_dep)))) return html, deduplicated_angular_modules
def html_body(self): """The HTML code containing directives and templates for the gadget. This contains everything needed to display the gadget once the necessary attributes are supplied. """ html_templates = utils.get_file_contents(os.path.join( feconf.GADGETS_DIR, self.type, '%s.html' % self.type)) return jinja_utils.interpolate_cache_slug('%s' % html_templates)
def get_editor_html_template(cls): if cls.edit_html_filename is None: raise Exception( 'There is no editor template defined for objects of type %s' % cls.__name__) html_templates = utils.get_file_contents( os.path.join(os.getcwd(), feconf.OBJECT_TEMPLATES_DIR, '%s.html' % cls.edit_html_filename)) return jinja_utils.interpolate_cache_slug('%s' % html_templates)
def get_editor_html_template(cls): if cls.edit_html_filename is None: raise Exception( 'There is no editor template defined for objects of type %s' % cls.__name__) html_templates = utils.get_file_contents(os.path.join( os.getcwd(), feconf.OBJECT_TEMPLATES_DIR, '%s.html' % cls.edit_html_filename)) return jinja_utils.interpolate_cache_slug('%s' % html_templates)
def html_body(self): """The HTML code containing directives and templates for the component. This contains everything needed to display the component once the necessary attributes are supplied. For rich-text components, this consists of a single directive/template pair. """ html_templates = utils.get_file_contents(os.path.join( feconf.RTE_EXTENSIONS_DIR, self.id, '%s.html' % self.id)) return jinja_utils.interpolate_cache_slug('%s' % html_templates)
def html_body(self): """The HTML code containing directives and templates for the component. This contains everything needed to display the component once the necessary attributes are supplied. For rich-text components, this consists of a single directive/template pair. """ html_templates = utils.get_file_contents( os.path.join(feconf.RTE_EXTENSIONS_DIR, self.id, '%s.html' % self.id)) return jinja_utils.interpolate_cache_slug('%s' % html_templates)
def html_body(self): """The HTML code containing directives and templates for the interaction. This contains everything needed to display the interaction once the necessary attributes are supplied. Each interaction has two directive/template pairs, one for the interaction itself and the other for displaying the learner's response in a read-only view after it has been submitted. """ html_templates = utils.get_file_contents(os.path.join( feconf.INTERACTIONS_DIR, self.id, '%s.html' % self.id)) return jinja_utils.interpolate_cache_slug('%s' % html_templates)
def get_deps_html_and_angular_modules(cls, dependency_ids): """Returns data needed to load the given dependencies. The return value is a 2-tuple. The first element of the tuple is the additional HTML to insert on the page. The second element of the tuple is a de-duplicated list of strings, each representing an additional angular module that should be loaded. """ html = '\n'.join([ cls.get_dependency_html(dep) for dep in set(dependency_ids)]) # Html content for interactions is loaded using get_dependency_html # method. This content is then interpolated using Jinja. Interactions # such as logicproof contain jinja like variables that need to be # interpolated. LogicProof contains a cache slug variable that is # interpolated using interpolate_cache_slug method. html = jinja_utils.interpolate_cache_slug(html) angular_modules_for_each_dep = [ cls.get_angular_modules(dep) for dep in set(dependency_ids)] deduplicated_angular_modules = list(set(list( itertools.chain.from_iterable(angular_modules_for_each_dep)))) return html, deduplicated_angular_modules