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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
import os
import openobject
from _base import Widget
from _utils import Enum
from openobject import tools
locations = Enum(["head", "bodytop", "bodybottom"])
class Resource(Widget):
location = locations.head
@property
def name(self):
return None
class Link(Resource):
params = {
'link': None,
}
_filename = None
modname = None
def __init__(self, modname, filename, location=locations.head, **kw):
super(Link, self).__init__(modname=modname, location=location, **kw)
self._filename = filename
def get_link(self):
return tools.url('/%s/static/%s' % (self.modname, self.filename))
def get_file(self):
return self._filename
link = property(lambda self: self.get_link())
filename = property(lambda self: self.get_file())
def __eq__(self, other):
return getattr(other, 'link', None) == self.link
def __hash__(self):
return hash(self.link)
class JSLink(Link):
template = "/openobject/widgets/templates/jslink.mako"
params = {
'charset': 'The character encoding of the linked script',
'defer': 'If true, browser may defer execution of the script'
}
charset = None
defer = None
class CSSLink(Link):
params = {
'media': 'Specify the media attribute for the css link tag'
}
template = "/openobject/widgets/templates/csslink.mako"
class Source(Resource):
params = {
'src': 'The source text',
}
def __init__(self, src, location=locations.head, **kw):
super(Source, self).__init__(src=src, location=location, **kw)
def __hash__(self):
return hash(self.src)
def __eq__(self, other):
return self.src == getattr(other, 'src', None)
class JSSource(Source):
"""A JavaScript source snippet."""
template = "/openobject/widgets/templates/jssource.mako"
params = {
'defer': 'If true, browser may defer execution of the script'
}
class CSSSource(Source):
"""A CSS source snippet."""
template = "/openobject/widgets/templates/csssource.mako"
params = {
'src': 'The CSS source for the link',
'media' : 'Specify the media the css source link is for'
}
media = "all"
def register_resource_directory(config, modulename, directory):
"""Set up an application wide static resource directory...
"""
if not openobject.WSGI_STATIC_PATHS:
return False
directory = os.path.abspath(directory)
config.update({'/%s/static' % modulename: {
'tools.staticdir.on': True,
'tools.staticdir.dir': directory
}})
return True
|