blob: 22fcce741f2442b9e86f0d1c99bde721ed8bb7cd [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
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053017import webnotes
18from webnotes.model.doc import Document
19
Anand Doshi51146c02012-07-12 18:41:12 +053020def scrub_page_name(page_name):
21 if page_name.endswith('.html'):
22 page_name = page_name[:-5]
23
24 return page_name
25
Rushabh Mehta949496c2012-01-25 18:48:46 +053026def make_template(doc, path, convert_fields = ['main_section', 'side_section']):
27 """make template"""
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053028 import os, jinja2
Rushabh Mehta949496c2012-01-25 18:48:46 +053029
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053030 markdown(doc, convert_fields)
Rushabh Mehta949496c2012-01-25 18:48:46 +053031
32 # write template
33 with open(path, 'r') as f:
34 temp = jinja2.Template(f.read())
35
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053036 return temp.render(doc = doc.fields)
37
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053038def page_name(title):
Anand Doshi72c945b2012-06-22 20:01:07 +053039 """make page name from title"""
40 import re
41 name = title.lower()
42 name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
43 return '-'.join(name.split()[:4])