Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | # 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 Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 17 | from __future__ import unicode_literals |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 18 | import webnotes |
| 19 | from webnotes.model.doc import Document |
| 20 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 21 | def scrub_page_name(page_name): |
| 22 | if page_name.endswith('.html'): |
| 23 | page_name = page_name[:-5] |
| 24 | |
| 25 | return page_name |
| 26 | |
Rushabh Mehta | 949496c | 2012-01-25 18:48:46 +0530 | [diff] [blame] | 27 | def make_template(doc, path, convert_fields = ['main_section', 'side_section']): |
| 28 | """make template""" |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 29 | import os, jinja2 |
Rushabh Mehta | 949496c | 2012-01-25 18:48:46 +0530 | [diff] [blame] | 30 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 31 | markdown(doc, convert_fields) |
Rushabh Mehta | 949496c | 2012-01-25 18:48:46 +0530 | [diff] [blame] | 32 | |
| 33 | # write template |
| 34 | with open(path, 'r') as f: |
| 35 | temp = jinja2.Template(f.read()) |
| 36 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 37 | return temp.render(doc = doc.fields) |
| 38 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 39 | def page_name(title): |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 40 | """make page name from title""" |
| 41 | import re |
| 42 | name = title.lower() |
| 43 | name = re.sub('[~!@#$%^&*()<>,."\']', '', name) |
| 44 | return '-'.join(name.split()[:4]) |