blob: 58897a66b21e71e9ec2d8b0d221523ff27873ee6 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Anand Doshi486f9df2012-07-19 13:40:31 +053017from __future__ import unicode_literals
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053018import webnotes
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053019
Rushabh Mehta89c7b412012-12-06 14:58:44 +053020def render(page_name):
21 """render html page"""
22 import webnotes
23 try:
24 if page_name:
25 html = get_html(page_name)
26 else:
27 html = get_html('index')
28 except Exception, e:
29 html = get_html('404')
30
31 from webnotes.handler import eprint, print_zip
32 eprint("Content-Type: text/html")
33 print_zip(html)
34
35def get_html(page_name):
36 """get page html"""
37 page_name = scrub_page_name(page_name)
38 comments = get_comments(page_name)
39
40 import website.web_cache
41 html = website.web_cache.get_html(page_name, comments)
42 return html
43
44def get_comments(page_name):
45 import webnotes
46
47 if page_name == '404':
48 comments = """error: %s""" % webnotes.getTraceback()
49 else:
50 comments = """page: %s""" % page_name
51
52 return comments
53
Anand Doshi51146c02012-07-12 18:41:12 +053054def scrub_page_name(page_name):
55 if page_name.endswith('.html'):
56 page_name = page_name[:-5]
57
58 return page_name
59
Rushabh Mehta949496c2012-01-25 18:48:46 +053060def make_template(doc, path, convert_fields = ['main_section', 'side_section']):
61 """make template"""
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053062 import os, jinja2
Rushabh Mehta949496c2012-01-25 18:48:46 +053063
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053064 markdown(doc, convert_fields)
Rushabh Mehta949496c2012-01-25 18:48:46 +053065
66 # write template
67 with open(path, 'r') as f:
68 temp = jinja2.Template(f.read())
69
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053070 return temp.render(doc = doc.fields)
71
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053072def page_name(title):
Anand Doshi72c945b2012-06-22 20:01:07 +053073 """make page name from title"""
74 import re
75 name = title.lower()
76 name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
77 return '-'.join(name.split()[:4])