Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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()}
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 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()}
             )
Ejemplo n.º 8
0
 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()}
             )
Ejemplo n.º 9
0
 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(),
             })
Ejemplo n.º 10
0
 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(),
             })
Ejemplo n.º 11
0
    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(),
        }
Ejemplo n.º 12
0
    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(),
        }
Ejemplo n.º 13
0
    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
Ejemplo n.º 14
0
 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(),
                 })
Ejemplo n.º 15
0
    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