def _render_resource(self, resource): """ Render a single resource. :param resource: The resource. :type resource: str|InlineMarkupResource|InlineScriptResource :return: String of HTML """ if not resource: # pragma: no cover return "" if isinstance(resource, InlineMarkupResource): return force_text(resource) if isinstance(resource, InlineScriptResource): return "<script>%s</script>" % resource resource = force_text(resource) # TODO: should this be extensible? if resource.endswith(".js"): return "<script%s></script>" % get_html_attrs({"src": resource}) if resource.endswith(".css"): return "<link%s>" % get_html_attrs({ "href": resource, "rel": "stylesheet" }) return "<!-- (unknown resource type: %s) -->" % escape(resource)
def _render_resource(self, resource): """ Render a single resource. :param resource: The resource. :type resource: str|InlineMarkupResource|InlineScriptResource :return: String of HTML """ if not resource: # pragma: no cover return "" if isinstance(resource, InlineMarkupResource): return force_text(resource) if isinstance(resource, InlineScriptResource): return "<script>%s</script>" % resource resource = force_text(resource) # TODO: should this be extensible? if resource.endswith(".js"): return "<script%s></script>" % get_html_attrs({"src": resource}) if resource.endswith(".css"): return "<link%s>" % get_html_attrs({"href": resource, "rel": "stylesheet"}) return "<!-- (unknown resource type: %s) -->" % escape(resource)
def _render_cell(self, write, x, cell): """ Render a layout cell into HTML. :param write: Writer function :type write: callable :param x: Cell X coordinate :type x: int :param cell: Cell :type cell: shoop.xtheme.view_config.LayoutCell """ classes = ["xt-ph-cell"] for breakpoint, width in cell.sizes.items(): if width is None: continue if width <= 0: classes.append(self.layout.hide_cell_class_template % { "breakpoint": breakpoint, "width": width }) else: classes.append(self.layout.cell_class_template % { "breakpoint": breakpoint, "width": width }) cell_attrs = {"class": classes} if self.edit: cell_attrs.update({"data-xt-cell": str(x)}) write("<div%s>" % get_html_attrs(cell_attrs)) content = cell.render(self.context) if content is not None: # pragma: no branch write(force_text(content)) write("</div>")
def _render_cell(self, write, x, cell): """ Render a layout cell into HTML. :param write: Writer function :type write: callable :param x: Cell X coordinate :type x: int :param cell: Cell :type cell: shoop.xtheme.view_config.LayoutCell """ classes = ["xt-ph-cell"] for breakpoint, width in cell.sizes.items(): if width is None: continue if width <= 0: classes.append(self.layout.hide_cell_class_template % {"breakpoint": breakpoint, "width": width}) else: classes.append(self.layout.cell_class_template % {"breakpoint": breakpoint, "width": width}) cell_attrs = { "class": classes } if self.edit: cell_attrs.update({"data-xt-cell": str(x)}) write("<div%s>" % get_html_attrs(cell_attrs)) content = cell.render(self.context) if content is not None: # pragma: no branch write(force_text(content)) write("</div>")
def _render_default_layout_script_tag(self, write): # This script tag is read by editor.js write("<script%s>" % get_html_attrs({"class": "xt-ph-default-layout", "type": "text/plain"})) layout = self.default_layout if hasattr(layout, "serialize"): layout = layout.serialize() # TODO: Might have to do something about .. # TODO: .. http://www.w3.org/TR/html5/scripting-1.html#restrictions-for-contents-of-script-elements write(TaggedJSONEncoder(separators=",:").encode(layout)) write("</script>")
def _render_default_layout_script_tag(self, write): # This script tag is read by editor.js write("<script%s>" % get_html_attrs({ "class": "xt-ph-default-layout", "type": "text/plain" })) layout = self.default_layout if hasattr(layout, "serialize"): layout = layout.serialize() # TODO: Might have to do something about .. # TODO: .. http://www.w3.org/TR/html5/scripting-1.html#restrictions-for-contents-of-script-elements write(TaggedJSONEncoder(separators=",:").encode(layout)) write("</script>")
def render(self): """ Get this placeholder's rendered contents. :return: Rendered markup. :rtype: markupsafe.Markup """ wrapper_start = "<div%s>" % get_html_attrs(self._get_wrapper_attrs()) buffer = [] write = buffer.append self._render_layout(write) content = "".join(buffer) return Markup( "%(wrapper_start)s%(content)s%(wrapper_end)s" % {"wrapper_start": wrapper_start, "content": content, "wrapper_end": "</div>"} )
def render(self): """ Get this placeholder's rendered contents. :return: Rendered markup. :rtype: markupsafe.Markup """ wrapper_start = "<div%s>" % get_html_attrs(self._get_wrapper_attrs()) buffer = [] write = buffer.append self._render_layout(write) content = "".join(buffer) return Markup("%(wrapper_start)s%(content)s%(wrapper_end)s" % { "wrapper_start": wrapper_start, "content": content, "wrapper_end": "</div>", })
def _render_row(self, write, y, row): """ Render a layout row into HTML. :param write: Writer function :type write: callable :param y: Row Y coordinate :type y: int :param row: Row object :type row: shoop.xtheme.view_config.LayoutRow """ row_attrs = {"class": [self.layout.row_class, "xt-ph-row"]} if self.edit: row_attrs["data-xt-row"] = str(y) write("<div%s>" % get_html_attrs(row_attrs)) for x, cell in enumerate(row): self._render_cell(write, x, cell) write("</div>\n")