示例#1
0
def render_blocks(context):
	"""returns a dict of block name and its rendered content"""

	out = {}

	env = frappe.get_jenv()

	def _render_blocks(template_path):
		source = frappe.local.jloader.get_source(frappe.local.jenv, template_path)[0]
		for referenced_template_path in meta.find_referenced_templates(env.parse(source)):
			if referenced_template_path:
				_render_blocks(referenced_template_path)

		template = frappe.get_template(template_path)
		for block, render in template.blocks.items():
			out[block] = scrub_relative_urls(concat(render(template.new_context(context))))

	_render_blocks(context["template_path"])

	# default blocks if not found
	if "title" not in out and out.get("header"):
		out["title"] = out["header"]

	if "title" not in out:
		out["title"] = context.get("title")

	if "header" not in out and out.get("title"):
		out["header"] = out["title"]

	if not out["header"].startswith("<h"):
		out["header"] = "<h2>" + out["header"] + "</h2>"

	if "breadcrumbs" not in out:
		out["breadcrumbs"] = scrub_relative_urls(
			frappe.get_template("templates/includes/breadcrumbs.html").render(context))

	if "<!-- no-sidebar -->" in out.get("content", ""):
		out["no_sidebar"] = 1

	if "sidebar" not in out and not out.get("no_sidebar"):
		out["sidebar"] = scrub_relative_urls(
			frappe.get_template("templates/includes/sidebar.html").render(context))

	out["title"] = strip_html(out.get("title") or "")

	# remove style and script tags from blocks
	out["style"] = re.sub("</?style[^<>]*>", "", out.get("style") or "")
	out["script"] = re.sub("</?script[^<>]*>", "", out.get("script") or "")

	return out
示例#2
0
def set_breadcrumbs(out, context):
	"""Build breadcrumbs template (deprecated)"""
	out["no_breadcrumbs"] = context.get("no_breadcrumbs", 0) or ("<!-- no-breadcrumbs -->" in out.get("content", ""))

	# breadcrumbs
	if not out["no_breadcrumbs"] and "breadcrumbs" not in out:
		out["breadcrumbs"] = scrub_relative_urls(
			frappe.get_template("templates/includes/breadcrumbs.html").render(context))
示例#3
0
文件: template.py 项目: BIANBS/frappe
	def _render_blocks(template_path):
		source = frappe.local.jloader.get_source(frappe.local.jenv, template_path)[0]
		for referenced_template_path in meta.find_referenced_templates(env.parse(source)):
			if referenced_template_path:
				_render_blocks(referenced_template_path)

		template = frappe.get_template(template_path)
		for block, render in template.blocks.items():
			out[block] = scrub_relative_urls(concat(render(template.new_context(context))))
示例#4
0
	def _render_blocks(template_path):
		source = frappe.local.jloader.get_source(frappe.local.jenv, template_path)[0]
		for referenced_template_path in meta.find_referenced_templates(env.parse(source)):
			if referenced_template_path:
				_render_blocks(referenced_template_path)

		template = frappe.get_template(template_path)
		for block, render in template.blocks.items():
			out[block] = scrub_relative_urls(concat(render(template.new_context(context))))
示例#5
0
def build_page(path):
    context = get_context(path)

    html = frappe.get_template(context.base_template_path).render(context)
    html = scrub_relative_urls(html)

    if can_cache(context.no_cache):
        frappe.cache().set_value("page:" + path, html)

    return html
示例#6
0
def build_page(path):
	context = get_context(path)

	html = frappe.get_template(context.base_template_path).render(context)
	html = scrub_relative_urls(html)

	if can_cache(context.no_cache):
		frappe.cache().set_value("page:" + path, html)

	return html
示例#7
0
def render_blocks(context):
    """returns a dict of block name and its rendered content"""

    out = {}

    env = frappe.get_jenv()

    def _render_blocks(template_path):
        source = frappe.local.jloader.get_source(frappe.local.jenv,
                                                 template_path)[0]
        for referenced_template_path in meta.find_referenced_templates(
                env.parse(source)):
            if referenced_template_path:
                _render_blocks(referenced_template_path)

        template = frappe.get_template(template_path)
        for block, render in template.blocks.items():
            out[block] = scrub_relative_urls(
                concat(render(template.new_context(context))))

    _render_blocks(context["template_path"])

    # default blocks if not found
    if "title" not in out:
        out["title"] = context.get("title")

    if "header" not in out:
        out["header"] = out["title"]

    if not out["header"].startswith("<h"):
        out["header"] = "<h2>" + out["header"] + "</h2>"

    if "breadcrumbs" not in out:
        out["breadcrumbs"] = scrub_relative_urls(
            frappe.get_template("templates/includes/breadcrumbs.html").render(
                context))

    if "sidebar" not in out:
        out["sidebar"] = scrub_relative_urls(
            frappe.get_template("templates/includes/sidebar.html").render(
                context))

    return out
示例#8
0
def render_blocks(template_path, out, context):
	"""Build the template block by block from the main template."""
	env = frappe.get_jenv()
	source = frappe.local.jloader.get_source(frappe.local.jenv, template_path)[0]
	for referenced_template_path in meta.find_referenced_templates(env.parse(source)):
		if referenced_template_path:
			render_blocks(referenced_template_path, out, context)

	template = frappe.get_template(template_path)
	for block, render in template.blocks.items():
		new_context = template.new_context(context)
		out[block] = scrub_relative_urls(concat(render(new_context)))
def build_page(path):
	if not getattr(frappe.local, "path", None):
		frappe.local.path = path

	context = get_context(path)

	html = frappe.get_template(context.base_template_path).render(context)
	html = scrub_relative_urls(html)

	if can_cache(context.no_cache):
		frappe.cache().set_value("page:{0}:{1}".format(path, frappe.local.lang), html)

	return html
示例#10
0
    def _render_blocks(template_path):
        #print "template_paths {}".format(template_path)
        source = frappe.local.floader.get_source(frappe.local.fenv,
                                                 template_path)[0]
        for referenced_template_path in meta.find_referenced_templates(
                env.parse(source)):
            if referenced_template_path:
                _render_blocks(referenced_template_path)

        template = fluorine_get_template(template_path)
        for block, render in template.blocks.items():
            make_heritage(block, context)
            out[block] = scrub_relative_urls(
                concat(render(template.new_context(context))))
示例#11
0
文件: template.py 项目: BIANBS/frappe
def render_blocks(context):
	"""returns a dict of block name and its rendered content"""

	out = {}

	env = frappe.get_jenv()

	def _render_blocks(template_path):
		source = frappe.local.jloader.get_source(frappe.local.jenv, template_path)[0]
		for referenced_template_path in meta.find_referenced_templates(env.parse(source)):
			if referenced_template_path:
				_render_blocks(referenced_template_path)

		template = frappe.get_template(template_path)
		for block, render in template.blocks.items():
			out[block] = scrub_relative_urls(concat(render(template.new_context(context))))

	_render_blocks(context["template"])

	# default blocks if not found
	if "title" not in out and out.get("header"):
		out["title"] = out["header"]

	if "title" not in out:
		out["title"] = context.get("title")

	if "header" not in out and out.get("title"):
		out["header"] = out["title"]

	if out.get("header") and not out["header"].startswith("<h"):
		out["header"] = "<h2>" + out["header"] + "</h2>"

	if "breadcrumbs" not in out:
		out["breadcrumbs"] = scrub_relative_urls(
			frappe.get_template("templates/includes/breadcrumbs.html").render(context))

	if "meta_block" not in out:
		out["meta_block"] = frappe.get_template("templates/includes/meta_block.html").render(context)


	out["no_sidebar"] = context.get("no_sidebar", 0)

	if "<!-- no-sidebar -->" in out.get("content", ""):
		out["no_sidebar"] = 1

	if "<!-- title:" in out.get("content", ""):
		out["title"] = re.findall('<!-- title:([^>]*) -->', out.get("content"))[0].strip()

	if "{index}" in out.get("content", "") and context.get("children"):
		html = frappe.get_template("templates/includes/static_index.html").render({
				"items": context["children"]})
		out["content"] = out["content"].replace("{index}", html)

	if "{next}" in out.get("content", ""):
		next_item = context.doc.get_next()
		if next_item:
			if next_item.name[0]!="/": next_item.name = "/" + next_item.name
			html = '''<p><br><a href="{name}" class="btn btn-primary">
				{title} <i class="icon-chevron-right"></i></a>
			</p>'''.format(**next_item)
			out["content"] = out["content"].replace("{next}", html)

	if "sidebar" not in out and not out.get("no_sidebar"):
		out["sidebar"] = scrub_relative_urls(
			frappe.get_template("templates/includes/sidebar.html").render(context))

	out["title"] = strip_html(out.get("title") or "")

	# remove style and script tags from blocks
	out["style"] = re.sub("</?style[^<>]*>", "", out.get("style") or "")
	out["script"] = re.sub("</?script[^<>]*>", "", out.get("script") or "")

	return out
示例#12
0
文件: template.py 项目: saguas/frappe
def render_blocks(context):
    """returns a dict of block name and its rendered content"""

    out = {}

    env = frappe.get_jenv()

    def _render_blocks(template_path):
        source = frappe.local.jloader.get_source(frappe.local.jenv,
                                                 template_path)[0]
        for referenced_template_path in meta.find_referenced_templates(
                env.parse(source)):
            if referenced_template_path:
                _render_blocks(referenced_template_path)

        template = frappe.get_template(template_path)
        for block, render in template.blocks.items():
            out[block] = scrub_relative_urls(
                concat(render(template.new_context(context))))

    _render_blocks(context["template"])

    # default blocks if not found
    if "title" not in out and out.get("header"):
        out["title"] = out["header"]

    if "title" not in out:
        out["title"] = context.get("title")

    if "header" not in out and out.get("title"):
        out["header"] = out["title"]

    if out.get("header") and not out["header"].startswith("<h"):
        out["header"] = "<h2>" + out["header"] + "</h2>"

    if "breadcrumbs" not in out:
        out["breadcrumbs"] = scrub_relative_urls(
            frappe.get_template("templates/includes/breadcrumbs.html").render(
                context))

    if "meta_block" not in out:
        out["meta_block"] = frappe.get_template(
            "templates/includes/meta_block.html").render(context)

    out["no_sidebar"] = context.get("no_sidebar", 0)

    if "<!-- no-sidebar -->" in out.get("content", ""):
        out["no_sidebar"] = 1

    if "<!-- title:" in out.get("content", ""):
        out["title"] = re.findall('<!-- title:([^>]*) -->',
                                  out.get("content"))[0].strip()

    if "{index}" in out.get("content", "") and context.get("children"):
        html = frappe.get_template(
            "templates/includes/static_index.html").render(
                {"items": context["children"]})
        out["content"] = out["content"].replace("{index}", html)

    if "{next}" in out.get("content", ""):
        next_item = context.doc.get_next()
        if next_item:
            if next_item.name[0] != "/": next_item.name = "/" + next_item.name
            html = '''<p><br><a href="{name}" class="btn btn-primary">
				{title} <i class="icon-chevron-right"></i></a>
			</p>'''.format(**next_item)
            out["content"] = out["content"].replace("{next}", html)

    if "sidebar" not in out and not out.get("no_sidebar"):
        out["sidebar"] = scrub_relative_urls(
            frappe.get_template("templates/includes/sidebar.html").render(
                context))

    out["title"] = strip_html(out.get("title") or "")

    # remove style and script tags from blocks
    out["style"] = re.sub("</?style[^<>]*>", "", out.get("style") or "")
    out["script"] = re.sub("</?script[^<>]*>", "", out.get("script") or "")

    return out