Example #1
0
    def set_title_and_header(self, context):
        """Extract and set title and header from content or context."""
        if not "no_header" in context:
            if "<!-- no-header -->" in context.main_section:
                context.no_header = 1

        if not context.title:
            context.title = extract_title(context.main_section,
                                          context.path_name)

        # header
        if context.no_header and "header" in context:
            context.header = ""

        if not context.no_header:
            # if header not set and no h1 tag in the body, set header as title
            if not context.header and "<h1" not in context.main_section:
                context.header = context.title

            # add h1 tag to header
            if context.get("header") and not re.findall(
                    "<h.>", context.header):
                context.header = "<h1>" + context.header + "</h1>"

        # if title not set, set title from header
        if not context.title and context.header:
            context.title = strip_html(context.header)
Example #2
0
	def set_title_and_header(self, context):
		"""Extract and set title and header from content or context."""
		if not "no_header" in context:
			if "<!-- no-header -->" in context.main_section:
				context.no_header = 1

		if not context.title:
			context.title = extract_title(context.main_section, context.path_name)

		# header
		if context.no_header and "header" in context:
			context.header = ""

		if not context.no_header:
			# if header not set and no h1 tag in the body, set header as title
			if not context.header and "<h1" not in context.main_section:
				context.header = context.title

			# add h1 tag to header
			if context.get("header") and not re.findall("<h.>", context.header):
				context.header = "<h1>" + context.header + "</h1>"

		# if title not set, set title from header
		if not context.title and context.header:
			context.title = strip_html(context.header)
Example #3
0
def load_properties(page_info):
    '''Load properties like no_cache, title from raw'''
    if not page_info.title:
        page_info.title = extract_title(page_info.source, page_info.route)

    # if page_info.title and not '{% block title %}' in page_info.source:
    # 	if not page_info.only_content:
    # 		page_info.source += '\n{% block title %}{{ title }}{% endblock %}'

    if "<!-- no-breadcrumbs -->" in page_info.source:
        page_info.no_breadcrumbs = 1

    if "<!-- show-sidebar -->" in page_info.source:
        page_info.show_sidebar = 1

    if "<!-- add-breadcrumbs -->" in page_info.source:
        page_info.add_breadcrumbs = 1

    if "<!-- no-header -->" in page_info.source:
        page_info.no_header = 1
    # else:
    # 	# every page needs a header
    # 	# add missing header if there is no <h1> tag
    # 	if (not '{% block header %}' in page_info.source) and (not '<h1' in page_info.source):
    # 		if page_info.only_content:
    # 			page_info.source = '<h1>{{ title }}</h1>\n' + page_info.source
    # 		else:
    # 			page_info.source += '\n{% block header %}<h1>{{ title }}</h1>{% endblock %}'

    if "<!-- no-cache -->" in page_info.source:
        page_info.no_cache = 1

    if "<!-- no-sitemap -->" in page_info.source:
        page_info.no_cache = 1
Example #4
0
def load_properties(page_info):
    '''Load properties like no_cache, title from raw'''
    if not page_info.title:
        page_info.title = extract_title(page_info.source, page_info.route)

    if "<!-- no-breadcrumbs -->" in page_info.source:
        page_info.no_breadcrumbs = 1

    if "<!-- show-sidebar -->" in page_info.source:
        page_info.show_sidebar = 1

    if "<!-- add-breadcrumbs -->" in page_info.source:
        page_info.add_breadcrumbs = 1

    if "<!-- no-header -->" in page_info.source:
        page_info.no_header = 1

    if "<!-- add-next-prev-links -->" in page_info.source:
        page_info.add_next_prev_links = 1

    if "<!-- no-cache -->" in page_info.source:
        page_info.no_cache = 1

    if "<!-- no-sitemap -->" in page_info.source:
        page_info.no_cache = 1
Example #5
0
def load_properties(page_info):
	'''Load properties like no_cache, title from raw'''
	if not page_info.title:
		page_info.title = extract_title(page_info.source, page_info.route)

	# if page_info.title and not '{% block title %}' in page_info.source:
	# 	if not page_info.only_content:
	# 		page_info.source += '\n{% block title %}{{ title }}{% endblock %}'

	if "<!-- no-breadcrumbs -->" in page_info.source:
		page_info.no_breadcrumbs = 1

	if "<!-- show-sidebar -->" in page_info.source:
		page_info.show_sidebar = 1

	if "<!-- add-breadcrumbs -->" in page_info.source:
		page_info.add_breadcrumbs = 1

	if "<!-- no-header -->" in page_info.source:
		page_info.no_header = 1
	# else:
	# 	# every page needs a header
	# 	# add missing header if there is no <h1> tag
	# 	if (not '{% block header %}' in page_info.source) and (not '<h1' in page_info.source):
	# 		if page_info.only_content:
	# 			page_info.source = '<h1>{{ title }}</h1>\n' + page_info.source
	# 		else:
	# 			page_info.source += '\n{% block header %}<h1>{{ title }}</h1>{% endblock %}'

	if "<!-- no-cache -->" in page_info.source:
		page_info.no_cache = 1

	if "<!-- no-sitemap -->" in page_info.source:
		page_info.no_cache = 1
Example #6
0
def load_properties(page_info):
	'''Load properties like no_cache, title from raw'''
	if not page_info.title:
		page_info.title = extract_title(page_info.source, page_info.route)

	if "<!-- no-breadcrumbs -->" in page_info.source:
		page_info.no_breadcrumbs = 1

	if "<!-- show-sidebar -->" in page_info.source:
		page_info.show_sidebar = 1

	if "<!-- add-breadcrumbs -->" in page_info.source:
		page_info.add_breadcrumbs = 1

	if "<!-- no-header -->" in page_info.source:
		page_info.no_header = 1

	if "<!-- add-next-prev-links -->" in page_info.source:
		page_info.add_next_prev_links = 1

	if "<!-- no-cache -->" in page_info.source:
		page_info.no_cache = 1

	if "<!-- no-sitemap -->" in page_info.source:
		page_info.no_cache = 1
Example #7
0
def get_page_info(path, app, start, basepath=None, app_path=None, fname=None):
    '''Load page info'''
    if fname is None:
        fname = os.path.basename(path)

    if app_path is None:
        app_path = frappe.get_app_path(app)

    if basepath is None:
        basepath = os.path.dirname(path)

    page_name, extn = os.path.splitext(fname)

    # add website route
    page_info = frappe._dict()

    page_info.basename = page_name if extn in ('html', 'md') else fname
    page_info.basepath = basepath
    page_info.page_or_generator = "Page"

    page_info.template = os.path.relpath(os.path.join(basepath, fname),
                                         app_path)

    if page_info.basename == 'index':
        page_info.basename = ""

    # get route from template name
    page_info.route = page_info.template.replace(start, '').strip('/')
    if os.path.basename(page_info.route) in ('index.html', 'index.md'):
        page_info.route = os.path.dirname(page_info.route)

    # remove the extension
    if page_info.route.endswith('.md') or page_info.route.endswith('.html'):
        page_info.route = page_info.route.rsplit('.', 1)[0]

    page_info.name = page_info.page_name = page_info.route
    # controller
    page_info.controller_path = os.path.join(
        basepath,
        page_name.replace("-", "_") + ".py")

    if os.path.exists(page_info.controller_path):
        controller = app + "." + os.path.relpath(
            page_info.controller_path, app_path).replace(os.path.sep, ".")[:-3]

        page_info.controller = controller

    # get the source
    setup_source(page_info)

    if not page_info.title:
        page_info.title = extract_title(page_info.source, page_info.route)

    # extract properties from controller attributes
    load_properties_from_controller(page_info)

    return page_info
Example #8
0
def load_properties_from_source(page_info):
    '''Load properties like no_cache, title from source html'''

    if not page_info.title:
        page_info.title = extract_title(page_info.source, page_info.route)

    custom_base_template = extract_comment_tag(page_info.source,
                                               'base_template')

    page_info.meta_tags = frappe._dict()

    page_info.meta_tags.name = extract_comment_tag(page_info.source,
                                                   'meta:name')
    page_info.meta_tags.description = extract_comment_tag(
        page_info.source, 'meta:description')

    if custom_base_template:
        page_info.source = '''{{% extends "{0}" %}}
			{{% block page_content %}}{1}{{% endblock %}}'''.format(
            custom_base_template, page_info.source)
        page_info.no_cache = 1

    if "<!-- no-breadcrumbs -->" in page_info.source:
        page_info.no_breadcrumbs = 1

    if "<!-- show-sidebar -->" in page_info.source:
        page_info.show_sidebar = 1

    if "<!-- add-breadcrumbs -->" in page_info.source:
        page_info.add_breadcrumbs = 1

    if "<!-- no-header -->" in page_info.source:
        page_info.no_header = 1

    if "<!-- add-next-prev-links -->" in page_info.source:
        page_info.add_next_prev_links = 1

    if "<!-- no-cache -->" in page_info.source:
        page_info.no_cache = 1

    if "<!-- no-sitemap -->" in page_info.source:
        page_info.sitemap = 0

    if "<!-- sitemap -->" in page_info.source:
        page_info.sitemap = 1
Example #9
0
    def set_properties_from_source(self):
        if not self.source:
            return
        context = self.context
        if not context.title:
            context.title = extract_title(self.source, self.path)

        base_template = extract_comment_tag(self.source, 'base_template')
        if base_template:
            context.base_template = base_template

        if (context.base_template and "{%- extends" not in self.source
                and "{% extends" not in self.source
                and "</body>" not in self.source):
            self.source = '''{{% extends "{0}" %}}
				{{% block page_content %}}{1}{{% endblock %}}'''.format(
                context.base_template, self.source)

        self.set_properties_via_comments()
Example #10
0
def load_properties_from_source(page_info):
    '''Load properties like no_cache, title from source html'''

    if not page_info.title:
        page_info.title = extract_title(page_info.source, page_info.route)

    base_template = extract_comment_tag(page_info.source, 'base_template')
    if base_template:
        page_info.base_template = base_template

    if (page_info.base_template and "{%- extends" not in page_info.source
            and "{% extends" not in page_info.source
            and "</body>" not in page_info.source):
        page_info.source = '''{{% extends "{0}" %}}
			{{% block page_content %}}{1}{{% endblock %}}'''.format(
            page_info.base_template, page_info.source)
        page_info.no_cache = 1

    if "<!-- no-breadcrumbs -->" in page_info.source:
        page_info.no_breadcrumbs = 1

    if "<!-- show-sidebar -->" in page_info.source:
        page_info.show_sidebar = 1

    if "<!-- add-breadcrumbs -->" in page_info.source:
        page_info.add_breadcrumbs = 1

    if "<!-- no-header -->" in page_info.source:
        page_info.no_header = 1

    if "<!-- add-next-prev-links -->" in page_info.source:
        page_info.add_next_prev_links = 1

    if "<!-- no-cache -->" in page_info.source:
        page_info.no_cache = 1

    if "<!-- no-sitemap -->" in page_info.source:
        page_info.sitemap = 0

    if "<!-- sitemap -->" in page_info.source:
        page_info.sitemap = 1