Esempio n. 1
0
def make_toc(context, out):
	'''Insert full index (table of contents) for {index} tag'''
	from frappe.website.utils import get_full_index
	if '{index}' in out:
		html = frappe.get_template("templates/includes/full_index.html").render({
			"full_index": get_full_index(),
			"url_prefix": context.url_prefix or "/",
			"route": context.route
		})

		out = out.replace('{index}', html)

	if '{next}' in out:
		# insert next link
		next_item = None
		children_map = get_full_index()
		parent_route = os.path.dirname(context.route)
		children = children_map[parent_route]

		if parent_route and children:
			for i, c in enumerate(children):
				if c.route == context.route and i < (len(children) - 1):
					next_item = children[i+1]
					next_item.url_prefix = context.url_prefix or "/"

		if next_item:
			if next_item.route and next_item.title:
				html = ('<p class="btn-next-wrapper">'+_("Next")\
					+': <a class="btn-next" href="{url_prefix}{route}">{title}</a></p>').format(**next_item)

				out = out.replace('{next}', html)

	return out
Esempio n. 2
0
def add_index(out, context):
	"""Add index, next button if `{index}`, `{next}` is present."""
	# table of contents

	extn = ""
	if context.page_links_with_extn:
		extn = ".html"

	if "{index}" in out.get("content", "") and context.get("children"):
		html = frappe.get_template("templates/includes/full_index.html").render({
				"full_index": get_full_index(context.pathname, extn = extn),
				"url_prefix": context.url_prefix
			})

		out["content"] = out["content"].replace("{index}", html)

	# next and previous
	if "{next}" in out.get("content", ""):
		next_item = context.doc.get_next()
		next_item.extn = "" if context.doc.has_children(next_item.name) else extn
		if context.relative_links:
			next_item.name = next_item.page_name or ""
		else:
			if next_item and next_item.name and next_item.name[0]!="/":
				next_item.name = "/" + next_item.name

		if next_item and next_item.name:
			if not next_item.title:
				next_item.title = ""
			html = ('<p class="btn-next-wrapper"><a class="btn-next" href="{name}{extn}">'\
				+_("Next")+': {title}</a></p>').format(**next_item)
		else:
			html = ""

		out["content"] = out["content"].replace("{next}", html)
Esempio n. 3
0
def get_toc(route, url_prefix=None, app=None):
	'''Insert full index (table of contents) for {index} tag'''
	from frappe.website.utils import get_full_index

	full_index = get_full_index(app=app)

	return frappe.get_template("templates/includes/full_index.html").render({
			"full_index": full_index,
			"url_prefix": url_prefix or "/",
			"route": route.rstrip('/')
		})
Esempio n. 4
0
	def add_index(self, context):
		"""Add index, next button if `{index}`, `{next}` is present."""
		# table of contents

		extn = ""
		if context.page_links_with_extn:
			extn = ".html"

		if "{index}" in context.main_section and context.get("children") and len(context.children):
			full_index = get_full_index(context.pathname, extn = extn)

			if full_index:
				html = frappe.get_template("templates/includes/full_index.html").render({
					"full_index": full_index,
					"url_prefix": context.url_prefix
				})

				context.main_section = context.main_section.replace("{index}", html)

		# next and previous
		if "{next}" in context.main_section:
			next_item = self.get_next()
			next_item.extn = "" if self.has_children(next_item.name) else extn
			if next_item and next_item.page_name:
				if context.relative_links:
					if next_item.next_parent:
						next_item.name = "../" + next_item.page_name or ""
					else:
						next_item.name = next_item.page_name or ""
				else:
					if next_item and next_item.name and next_item.name[0]!="/":
						next_item.name = "/" + next_item.name

				if not next_item.title:
					next_item.title = ""
				html = ('<p class="btn-next-wrapper">'+_("Next")\
					+': <a class="btn-next" href="{name}{extn}">{title}</a></p>').format(**next_item)
			else:
				html = ""

			context.main_section = context.main_section.replace("{next}", html)
Esempio n. 5
0
def get_next_link(route, url_prefix=None, app=None):
	# insert next link
	next_item = None
	route = route.rstrip('/')
	children_map = get_full_index(app=app)
	parent_route = os.path.dirname(route)
	children = children_map[parent_route]

	if parent_route and children:
		for i, c in enumerate(children):
			if c.route == route and i < (len(children) - 1):
				next_item = children[i+1]
				next_item.url_prefix = url_prefix or "/"

	if next_item:
		if next_item.route and next_item.title:
			html = ('<p class="btn-next-wrapper">' + frappe._("Next")\
				+': <a class="btn-next" href="{url_prefix}{route}">{title}</a></p>').format(**next_item)

			return html

	return ''
Esempio n. 6
0
def get_context(context):
	context.full_index = get_full_index()
Esempio n. 7
0
def get_context(context):
	for item in get_full_index():
		if item.page_name=="contents":
			context.full_index = item.children
			break
Esempio n. 8
0
def get_context(context):
    context.full_index = get_full_index(extn=True)