-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenumaker.py
96 lines (77 loc) · 3.05 KB
/
menumaker.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
96
# -*- coding: utf-8 -*-
bootstrap = """
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 101 Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
</head>
<body>
<h1>Hello, world!</h1>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Be sure to leave the brand out there if you want it shown -->
<a class="brand" href="#">Project name</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse collapse">
<!-- .nav, .navbar-search, .navbar-form, etc -->
{}
</div>
</div>
</div>
</div>
</body>
</html>
"""
class MenuItem(object):
"""docstring for MenuItem"""
def __init__(self, href, texto, active=False):
super(MenuItem, self).__init__()
self.href = href
self.texto = texto
self.active = ' class="active"' if active else ''
def __str__(self):
return u'<li{0.active}><a href="{0.href}">{0.texto}</a></li>'.format(self)
class MenuSearch(object):
"""docstring for MenuItem"""
def __init__(self, action="", klass="pull-left", placeholder="Search"):
super(MenuSearch, self).__init__()
self.placeholder = placeholder
self.klass = klass
self.action = action
def __str__(self):
return u'<form class="navbar-search {0.klass}" action="{0.action}"><input type="text" class="search-query" placeholder="{0.placeholder}"></form>'.format(self)
items = [
MenuItem('/bunda','Primeiro'), MenuItem('/bunda','Segundo Ativo', active=True),
('Dropdown', [MenuItem('/bunda','Drop 01'), MenuItem('/bunda','Drop 02')]),
MenuSearch(),
]
html = ""
def explode(node, klass="nav"):
html = ""
if type(node) == list:
for i in node:
html += explode(i)
return '<ul class="{}">{}</ul>'.format(klass,html)
if type(node) == tuple:
drop_name, items = node
html += explode(items,'dropdown-menu')
return '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">{} <b class="caret"></b></a>{}</li>'.format(drop_name,html)
elif isinstance(node, MenuItem) or isinstance(node, MenuSearch):
return str(node)
output = bootstrap.format(explode(items))
print output
with file('menumaker.html','w') as arq:
arq.write(output)
arq.close()