My favorites
|
Sign in
web2py
Enterprise Web Framework
Project Home
Downloads
Wiki
Issues
Source
Checkout
|
Browse
|
Changes
|
‹r1404
r1450
Source path:
svn
/
trunk
/
scripts
/
layout_make.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import glob
import os
import zipfile
import sys
import re
from BeautifulSoup import BeautifulSoup as BS
def head(styles):
title = '<title>{{=response.title or request.application}}</title>'
items = '\n'.join(["{{response.files.append(URL(request.application,'static','%s'))}}" % (style) for style in styles])
loc="""<style>
div.flash {
position: absolute;
float: right;
padding: 10px;
top: 0px;
right: 0px;
opacity: 0.75;
margin: 10px 10px 10px 10px;
text-align: center;
clear: both;
color: #fff;
font-size: 11pt;
text-align: center;
vertical-align: middle;
cursor: pointer;
background: black;
border: 2px solid #fff;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
z-index: 2;
}
div.error {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background-color: red;
color: white;
padding: 3px;
border: 1px solid #666;
}
</style>"""
return "\n%s\n%s\n{{include 'web2py_ajax.html'}}\n%s" % (title,items,loc)
def content():
return """<div class="flash">{{=response.flash or ''}}</div>{{include}}"""
def process(folder):
soup = BS(open(os.path.join(folder,'index.html'),'rb').read())
styles = [x['href'] for x in soup.findAll('link')]
soup.find('head').contents=BS(head(styles))
try:
soup.find('h1').contents=BS('{{=response.title or request.application}}')
soup.find('h2').contents=BS("{{=response.subtitle or '=response.subtitle'}}")
except:
pass
for match in (soup.find('div',id='menu'),
soup.find('div',{'class':'menu'}),
soup.find('div',id='nav'),
soup.find('div',{'class':'nav'})):
if match:
match.contents=BS('{{=MENU(response.menu)}}')
break
done=False
for match in (soup.find('div',id='content'),
soup.find('div',{'class':'content'}),
soup.find('div',id='main'),
soup.find('div',{'class':'main'})):
if match:
match.contents=BS(content())
done=True
break
if done:
page = soup.prettify()
page = re.compile("\s*\{\{=response\.flash or ''\}\}\s*",re.MULTILINE)\
.sub("{{=response.flash or ''}}",page)
print page
else:
raise Exception, "Unable to convert"
if __name__=='__main__':
if len(sys.argv)<2:
print """USAGE:
1) start a new web2py application
2) Download a sample free layout from the web into the static/ folder of
your web2py application (make sure a sample index.html is there)
3) run this script with
python layout_make.py /path/to/web2py/applications/app/static/
> /path/to/web2py/applications/app/views/layout.html
"""
elif not os.path.exists(sys.argv[1]):
print 'Folder %s does not exist' % sys.argv[1]
else:
process(sys.argv[1])
Show details
Hide details
Change log
r1405
by mdipie...@cs.depaul.edu on Nov 09, 2009
Diff
better layout_make
Go to:
/trunk/VERSION
/trunk/scripts/layout_make.py
/trunk/welcome.w2p
Project members,
sign in
to write a code review
Older revisions
r1404
by mdipie...@cs.depaul.edu on Nov 09, 2009
Diff
better layout_make
r1403
by mdipie...@cs.depaul.edu on Nov 09, 2009
Diff
added layout_make.py
All revisions of this file
File info
Size: 2920 bytes, 95 lines
View raw file
Hosted by