Example #1
0
def build_page(path):
    if not getattr(frappe.local, "path", None):
        frappe.local.path = path

    context = get_context(path)

    if context.source:
        html = frappe.render_template(context.source, context)
    elif context.template:
        html = frappe.get_template(context.template).render(context)

    if '{index}' in html:
        html = html.replace('{index}', get_toc(context.route))

    if '{next}' in html:
        html = html.replace('{next}', get_next_link(context.route))

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

    if can_cache(context.no_cache):
        page_cache = frappe.cache().hget("website_page", path) or {}
        page_cache[frappe.local.lang] = html
        frappe.cache().hset("website_page", path, page_cache)

    return html
Example #2
0
def build_page(path):
	if not getattr(frappe.local, "path", None):
		frappe.local.path = path

	context = get_context(path)

	if context.source:
		html = frappe.render_template(context.source, context)
	elif context.template:
		html = frappe.get_template(context.template).render(context)

	if '{index}' in html:
		html = html.replace('{index}', get_toc(context.route))

	if '{next}' in html:
		html = html.replace('{next}', get_next_link(context.route))

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

	if can_cache(context.no_cache):
		page_cache = frappe.cache().hget("website_page", path) or {}
		page_cache[frappe.local.lang] = html
		frappe.cache().hset("website_page", path, page_cache)

	return html
Example #3
0
def build_page(path):
	if not getattr(frappe.local, "path", None):
		frappe.local.path = path

	context = get_context(path)

	if context.source:
		html = frappe.render_template(context.source, context)
	elif context.template:
		if path.endswith("min.js"):
			html = frappe.get_jloader().get_source(frappe.get_jenv(), context.template)[0]
		else:
			html = frappe.get_template(context.template).render(context)

	if "{index}" in html:
		html = html.replace("{index}", get_toc(context.route))

	if "{next}" in html:
		html = html.replace("{next}", get_next_link(context.route))

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

	if can_cache(context.no_cache):
		page_cache = frappe.cache().hget("website_page", path) or {}
		page_cache[frappe.local.lang] = html
		frappe.cache().hset("website_page", path, page_cache)

	return html
Example #4
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
Example #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
Example #6
0
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)

    if can_cache(context.no_cache):
        page_cache = frappe.cache().hget("website_page", path) or {}
        page_cache[frappe.local.lang] = html
        frappe.cache().hset("website_page", path, page_cache)

    return html
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
Example #8
0
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)

	if can_cache(context.no_cache):
		page_cache = frappe.cache().hget("website_page", path) or {}
		page_cache[frappe.local.lang] = html
		frappe.cache().hset("website_page", path, page_cache)

	return html
Example #9
0
    def write_files(self):
        """render templates and write files to target folder"""
        frappe.local.flags.home_page = "index"

        # clear the user, current folder in target
        shutil.rmtree(os.path.join(self.target, "user"), ignore_errors=True)
        shutil.rmtree(os.path.join(self.target, "current"), ignore_errors=True)

        cnt = 0
        for page in frappe.db.sql("""select parent_website_route,
			page_name from `tabWeb Page` where ifnull(template_path, '')!=''""",
                                  as_dict=True):

            if page.parent_website_route:
                path = page.parent_website_route + "/" + page.page_name
            else:
                path = page.page_name

            print "Writing {0}".format(path)

            # set this for get_context / website libs
            frappe.local.path = path

            context = {
                "page_links_with_extn": True,
                "relative_links": True,
                "docs_base_url": self.docs_base_url,
                "url_prefix": self.docs_base_url,
            }

            context.update(self.app_context)

            context = get_context(path, context)

            target_path_fragment = context.template_path.split('/docs/', 1)[1]
            target_filename = os.path.join(self.target, target_path_fragment)

            # rename .md files to .html
            if target_filename.rsplit(".", 1)[1] == "md":
                target_filename = target_filename[:-3] + ".html"

            context.brand_html = context.top_bar_items = context.favicon = None

            self.docs_config.get_context(context)

            if not context.brand_html:
                if context.docs_icon:
                    context.brand_html = '<i class="{0}"></i> {1}'.format(
                        context.docs_icon, context.app.title)
                else:
                    context.brand_html = context.app.title

            if not context.top_bar_items:
                context.top_bar_items = [
                    # {"label": "Contents", "url": self.docs_base_url + "/contents.html", "right": 1},
                    {
                        "label": "User Guide",
                        "url": self.docs_base_url + "/user",
                        "right": 1
                    },
                    {
                        "label": "Developer Docs",
                        "url": self.docs_base_url + "/current",
                        "right": 1
                    },
                ]

            context.top_bar_items = [{
                "label": '<i class="octicon octicon-search"></i>',
                "url": "#",
                "right": 1
            }] + context.top_bar_items

            if not context.favicon:
                context.favicon = "/assets/img/favicon.ico"

            context.only_static = True
            context.base_template_path = "templates/autodoc/base_template.html"

            html = frappe.get_template(
                "templates/generators/web_page.html").render(context)

            if not "<!-- autodoc -->" in html:
                html = html.replace('<!-- edit-link -->',
                 edit_link.format(\
                  source_link = self.docs_config.source_link,
                  app_name = self.app,
                  branch = context.app.branch,
                  target = target_path_fragment))

            if not os.path.exists(os.path.dirname(target_filename)):
                os.makedirs(os.path.dirname(target_filename))

            with open(target_filename, "w") as htmlfile:
                htmlfile.write(html.encode("utf-8"))

                cnt += 1

        print "Wrote {0} files".format(cnt)
Example #10
0
	def write_files(self):
		"""render templates and write files to target folder"""
		frappe.local.flags.home_page = "index"

		cnt = 0
		for page in frappe.db.sql("""select parent_website_route,
			page_name from `tabWeb Page` where ifnull(template_path, '')!=''""", as_dict=True):

			if page.parent_website_route:
				path = page.parent_website_route + "/" + page.page_name
			else:
				path = page.page_name

			print "Writing {0}".format(path)

			# set this for get_context / website libs
			frappe.local.path = path

			context = {
				"page_links_with_extn": True,
				"relative_links": True,
				"docs_base_url": self.docs_base_url,
				"url_prefix": self.docs_base_url,
			}

			context.update(self.app_context)

			context = get_context(path, context)

			target_path_fragment = context.template_path.split('/docs/', 1)[1]
			target_filename = os.path.join(self.target, target_path_fragment)

			# rename .md files to .html
			if target_filename.rsplit(".", 1)[1]=="md":
				target_filename = target_filename[:-3] + ".html"

			context.brand_html = context.top_bar_items = context.favicon = None

			self.docs_config.get_context(context)

			if not context.brand_html:
				if context.docs_icon:
					context.brand_html = '<i class="{0}"></i> {1}'.format(context.docs_icon, context.app.title)
				else:
					context.brand_html = context.app.title

			if not context.top_bar_items:
				context.top_bar_items = [
					# {"label": "Contents", "url": self.docs_base_url + "/contents.html", "right": 1},
					{"label": "User Guide", "url": self.docs_base_url + "/user", "right": 1},
					{"label": "Developer Docs", "url": self.docs_base_url + "/current", "right": 1},
				]

			context.top_bar_items = [{"label": '<i class="octicon octicon-search"></i>', "url": "#",
				"right": 1}] + context.top_bar_items

			if not context.favicon:
				context.favicon = "/assets/img/favicon.ico"

			context.only_static = True

			html = frappe.get_template("templates/autodoc/base_template.html").render(context)

			if not "<!-- autodoc -->" in html:
				html = html.replace('<!-- edit-link -->',
					edit_link.format(\
						source_link = self.docs_config.source_link,
						app_name = self.app,
						branch = context.app.branch,
						target = target_path_fragment))

			if not os.path.exists(os.path.dirname(target_filename)):
				os.makedirs(os.path.dirname(target_filename))

			with open(target_filename, "w") as htmlfile:
				htmlfile.write(html.encode("utf-8"))

				cnt += 1

		print "Wrote {0} files".format(cnt)
Example #11
0
def build_json(path):
    return get_context(path).data
Example #12
0
	def write_files(self):
		"""render templates and write files to target folder"""
		frappe.flags.home_page = "index"

		from frappe.website.router import get_pages, make_toc
		pages = get_pages(self.app)

		# clear the user, current folder in target
		shutil.rmtree(os.path.join(self.target, "user"), ignore_errors=True)
		shutil.rmtree(os.path.join(self.target, "current"), ignore_errors=True)

		def raw_replacer(matchobj):
			if '{% raw %}' in matchobj.group(0):
				return matchobj.group(0)
			else:
				return '{% raw %}' + matchobj.group(0) + '{% endraw %}'

		cnt = 0
		for path, context in pages.iteritems():
			print "Writing {0}".format(path)

			# set this for get_context / website libs
			frappe.local.path = path

			context.update({
				"page_links_with_extn": True,
				"relative_links": True,
				"docs_base_url": self.docs_base_url,
				"url_prefix": self.docs_base_url,
			})

			context.update(self.app_context)

			context = get_context(path, context)

			if context.basename:
				target_path_fragment = context.route + '.html'
			else:
				# index.html
				target_path_fragment = context.route + '/index.html'

			target_filename = os.path.join(self.target, target_path_fragment.strip('/'))

			context.brand_html = context.app.brand_html
			context.top_bar_items = context.favicon = None

			self.docs_config.get_context(context)

			if not context.brand_html:
				if context.docs_icon:
					context.brand_html = '<i class="{0}"></i> {1}'.format(context.docs_icon, context.app.title)
				else:
					context.brand_html = context.app.title

			if not context.top_bar_items:
				context.top_bar_items = [
					# {"label": "Contents", "url": self.docs_base_url + "/contents.html", "right": 1},
					{"label": "User Guide", "url": self.docs_base_url + "/user", "right": 1},
					{"label": "Developer Docs", "url": self.docs_base_url + "/current", "right": 1},
				]

			context.top_bar_items = [{"label": '<i class="octicon octicon-search"></i>', "url": "#",
				"right": 1}] + context.top_bar_items

			context.parents = []
			parent_route = os.path.dirname(context.route)
			if pages[parent_route]:
				context.parents = [pages[parent_route]]

			context.only_static = True
			context.base_template_path = "templates/autodoc/base_template.html"

			if '<code>' in context.source:
				context.source = re.sub('\<code\>(.*)\</code\>', raw_replacer, context.source)

			html = frappe.render_template(context.source, context)

			html = make_toc(context, html, self.app)

			if not "<!-- autodoc -->" in html:
				html = html.replace('<!-- edit-link -->',
					edit_link.format(\
						source_link = self.docs_config.source_link,
						app_name = self.app,
						branch = context.app.branch,
						target = context.template))

			if not os.path.exists(os.path.dirname(target_filename)):
				os.makedirs(os.path.dirname(target_filename))

			with open(target_filename, "w") as htmlfile:
				htmlfile.write(html.encode("utf-8"))

				cnt += 1

		print "Wrote {0} files".format(cnt)
Example #13
0
def build_json(path):
	return get_context(path).data
Example #14
0
    def write_files(self):
        """render templates and write files to target folder"""
        frappe.local.flags.home_page = "index"

        for page in frappe.db.sql("""select parent_website_route,
			page_name from `tabWeb Page` where ifnull(template_path, '')!=''""",
                                  as_dict=True):

            if page.parent_website_route:
                path = page.parent_website_route + "/" + page.page_name
            else:
                path = page.page_name

            print "Writing {0}".format(path)

            # set this for get_context / website libs
            frappe.local.path = path

            context = {
                "page_links_with_extn": True,
                "relative_links": True,
                "docs_base_url": self.docs_base_url,
                "url_prefix": self.docs_base_url
            }

            context.update(self.app_context)

            context = get_context(path, context)

            target_path_fragment = context.template_path.split('/docs/', 1)[1]
            target_filename = os.path.join(self.target, target_path_fragment)

            # rename .md files to .html
            if target_filename.rsplit(".", 1)[1] == "md":
                target_filename = target_filename[:-3] + ".html"

            context.brand_html = context.top_bar_items = context.favicon = None

            self.docs_config.get_context(context)

            if not context.brand_html:
                if context.docs_icon:
                    context.brand_html = '<i class="{0}"></i> {1}'.format(
                        context.docs_icon, context.app.title)
                else:
                    context.brand_html = context.app.title

            if not context.top_bar_items:
                context.top_bar_items = [
                    # {"label": "Contents", "url": self.docs_base_url + "/contents.html", "right": 1},
                    {
                        "label": "User Guide",
                        "url": self.docs_base_url + "/user",
                        "right": 1
                    },
                    {
                        "label": "Developer Docs",
                        "url": self.docs_base_url + "/current",
                        "right": 1
                    },
                ]

            if not context.favicon:
                context.favicon = "/assets/img/favicon.ico"

            context.only_static = True

            html = frappe.get_template(
                "templates/autodoc/base_template.html").render(context)

            if not "<!-- autodoc -->" in html:
                html = html.replace('<!-- edit-link -->',
                 '<p><br><a class="text-muted" href="{source_link}/blob/{branch}/{app_name}/docs/{target}">Improve this page</a></p>'.format(\
                  source_link = self.docs_config.source_link,
                  app_name = self.app,
                  branch = context.app.branch,
                  target = target_path_fragment))

            if not os.path.exists(os.path.dirname(target_filename)):
                os.makedirs(os.path.dirname(target_filename))

            with open(target_filename, "w") as htmlfile:
                htmlfile.write(html.encode("utf-8"))