本文整理汇总了Python中utils.get_path_url函数的典型用法代码示例。如果您正苦于以下问题:Python get_path_url函数的具体用法?Python get_path_url怎么用?Python get_path_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_path_url函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_css
def get_css(self):
""" Fetches and returns stylesheet file path or contents, for both
print and screen contexts, depending if we want a standalone
presentation or not.
"""
css = {}
print_css = os.path.join(self.theme_dir, 'css', 'print.css')
if not os.path.exists(print_css):
# Fall back to default theme
print_css = os.path.join(THEMES_DIR, 'default', 'css', 'print.css')
if not os.path.exists(print_css):
raise IOError(u"Cannot find css/print.css in default theme")
css['print'] = {
'path_url': utils.get_path_url(print_css, self.relative),
'contents': self.css_contents(print_css),
}
screen_css = os.path.join(self.theme_dir, 'css', 'screen.css')
if (os.path.exists(screen_css)):
css['screen'] = {
'path_url': utils.get_path_url(screen_css, self.relative),
'contents': self.css_contents(screen_css),
}
else:
self.log(u"No screen stylesheet provided in current theme",
'warning')
return css
示例2: get_css
def get_css(self):
""" Fetches and returns stylesheet file path or contents, for both
print and screen contexts, depending if we want a standalone
presentation or not.
"""
css = {}
print_css = os.path.join(self.theme_dir, "css", "print.css")
if not os.path.exists(print_css):
# Fall back to default theme
print_css = os.path.join(THEMES_DIR, "default", "css", "print.css")
if not os.path.exists(print_css):
raise IOError(u"Cannot find css/print.css in default theme")
css["print"] = {"path_url": utils.get_path_url(print_css, self.relative), "contents": open(print_css).read()}
screen_css = os.path.join(self.theme_dir, "css", "screen.css")
if os.path.exists(screen_css):
css["screen"] = {
"path_url": utils.get_path_url(screen_css, self.relative),
"contents": open(screen_css).read(),
}
else:
self.log(u"No screen stylesheet provided in current theme", "warning")
return css
示例3: get_js
def get_js(self):
""" Fetches and returns javascript file path or contents, depending if
we want a standalone presentation or not.
"""
js_file = os.path.join(self.theme_dir, "js", "slides.js")
if not os.path.exists(js_file):
js_file = os.path.join(THEMES_DIR, "default", "js", "slides.js")
if not os.path.exists(js_file):
raise IOError(u"Cannot find slides.js in default theme")
return {"path_url": utils.get_path_url(js_file, self.relative), "contents": open(js_file).read()}
示例4: get_css
def get_css(self):
""" Fetches and returns stylesheet file path or contents, for both
print and screen contexts, depending if we want a standalone
presentation or not.
"""
css = {}
print_css = os.path.join(self.theme_dir, 'css', 'print.css')
if not os.path.exists(print_css):
# Fall back to default theme
print_css = os.path.join(THEMES_DIR, 'default', 'css', 'print.css')
if not os.path.exists(print_css):
raise IOError(u"Cannot find css/print.css in default theme")
css['print'] = {
'path_url': utils.get_path_url(print_css, self.relative),
'contents': open(print_css).read(),
}
screen_css = os.path.join(self.theme_dir, 'css', 'screen.css')
if (os.path.exists(screen_css)):
css['screen'] = {
'path_url': utils.get_path_url(screen_css, self.relative),
'contents': open(screen_css).read(),
}
else:
self.log(u"No screen stylesheet provided in current theme",
'warning')
if self.notes and self.file_type == 'pdf':
css['print']['contents'] += ".presenter_notes { display: block; }"
if self.embed:
contents = css['screen']['contents']
css['screen']['contents'] = self.embed_imported_files(contents)
return css
示例5: process
def process(self, content, source=None):
classes = []
if self.embed:
return content, classes
base_path = utils.get_path_url(source, self.options.get('relative'))
base_url = os.path.split(base_path)[0]
fn = lambda p: r'<img src="%s" />' % os.path.join(base_url, p.group(1))
sub_regex = r'<img.*?src="(?!http://)(.*?)".*/?>'
content = re.sub(sub_regex, fn, content, re.UNICODE)
return content, classes
示例6: add_user_js
def add_user_js(self, js_list):
""" Adds supplementary user javascript files to the presentation. The
``js_list`` arg can be either a ``list`` or a ``basestring``
instance.
"""
if isinstance(js_list, basestring):
js_list = [js_list]
for js_path in js_list:
if js_path and not js_path in self.user_js:
if not os.path.exists(js_path):
raise IOError("%s user js file not found" % (js_path,))
self.user_js.append(
{"path_url": utils.get_path_url(js_path, self.relative), "contents": open(js_path).read()}
)
示例7: add_user_css
def add_user_css(self, css_list):
""" Adds supplementary user css files to the presentation. The
``css_list`` arg can be either a ``list`` or a ``basestring``
instance.
"""
if isinstance(css_list, basestring):
css_list = [css_list]
for css_path in css_list:
if css_path and not css_path in self.user_css:
if not os.path.exists(css_path):
raise IOError("%s user css file not found" % (css_path,))
self.user_css.append(
{"path_url": utils.get_path_url(css_path, self.relative), "contents": open(css_path).read()}
)
示例8: get_js
def get_js(self):
""" Fetches and returns javascript file path or contents, depending if
we want a standalone presentation or not.
"""
js_file = os.path.join(self.theme_dir, 'js', 'slides.js')
if not os.path.exists(js_file):
js_file = os.path.join(THEMES_DIR, 'default', 'js', 'slides.js')
if not os.path.exists(js_file):
raise IOError(u"Cannot find slides.js in default theme")
return {
'path_url': utils.get_path_url(js_file, self.relative),
'contents': codecs.open(js_file, encoding=self.encoding).read(),
}
示例9: process
def process(self, content, source=None):
classes = []
if self.embed:
return content, classes
base_path = utils.get_path_url(source, self.options.get('relative'))
base_url = os.path.split(base_path)[0]
images = re.findall(r'<img.*?src="(?!http://)(.*?)".*/?>', content,
re.DOTALL | re.UNICODE)
for image in images:
full_path = os.path.join(base_url, image)
content = content.replace(image, full_path)
return content, classes
示例10: add_user_js
def add_user_js(self, js_list):
""" Adds supplementary user javascript files to the presentation. The
``js_list`` arg can be either a ``list`` or a ``basestring``
instance.
"""
if isinstance(js_list, basestring):
js_list = [js_list]
for js_path in js_list:
if js_path and not js_path in self.user_js:
if js_path.startswith("http:"):
self.user_js.append({
'path_url': js_path,
'contents': '',
})
elif not os.path.exists(js_path):
raise IOError('%s user js file not found' % (js_path,))
else:
self.user_js.append({
'path_url': utils.get_path_url(js_path, self.relative),
'contents': open(js_path).read(),
})
示例11: get_js
def get_js(self):
""" Fetches and returns javascript file path or contents, depending if
we want a standalone presentation or not.
"""
js_dir = os.path.join(self.theme_dir, 'js')
if not os.path.exists(js_dir):
js_dir = os.path.join(THEMES_DIR, 'default', 'js')
if not os.path.exists(js_dir):
raise IOError(u"Cannot find js folder in default theme")
js_files = []
for path in os.listdir(js_dir):
filename, ext = os.path.splitext(path)
if ext == ".js":
js_file = os.path.join(js_dir, path)
js_files.append({
'path_url': utils.get_path_url(js_file, self.relative),
'contents': open(js_file).read(),
})
return js_files