示例#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")

        with codecs.open(print_css, encoding=self.encoding) as css_file:
            css['print'] = {
                'path_url': utils.get_path_url(print_css, self.relative),
                'contents': css_file.read(),
            }

        screen_css = os.path.join(self.theme_dir, 'css', 'screen.css')

        if (os.path.exists(screen_css)):
            with codecs.open(screen_css, encoding=self.encoding) as css_file:
                css['screen'] = {
                    'path_url': utils.get_path_url(screen_css, self.relative),
                    'contents': css_file.read(),
                }
        else:
            self.log(u"No screen stylesheet provided in current theme",
                     'warning')

        return css
示例#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")

        with codecs.open(print_css, encoding=self.encoding) as css_file:
            css['print'] = {
                'path_url': utils.get_path_url(print_css, self.relative),
                'contents': css_file.read(),
            }

        screen_css = os.path.join(self.theme_dir, 'css', 'screen.css')

        if (os.path.exists(screen_css)):
            with codecs.open(screen_css, encoding=self.encoding) as css_file:
                css['screen'] = {
                    'path_url': utils.get_path_url(screen_css, self.relative),
                    'contents': css_file.read(),
                }
        else:
            self.log(u"No screen stylesheet provided in current theme",
                      'warning')

        return css
示例#3
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")
        with codecs.open(js_file, encoding=self.encoding) as js_file_obj:
            return {
                'path_url': utils.get_path_url(js_file, self.relative),
                'contents': js_file_obj.read(),
            }
示例#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")
        with codecs.open(js_file, encoding=self.encoding) as js_file_obj:
            return {
                'path_url': utils.get_path_url(js_file, self.relative),
                'contents': js_file_obj.read(),
            }
示例#5
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 string.
        """
        if isinstance(css_list, string_types):
            css_list = [css_list]

        for css_path in css_list:
            if css_path and css_path not in self.user_css:
                if not os.path.exists(css_path):
                    raise IOError('%s user css file not found' % (css_path,))
                with codecs.open(css_path, encoding=self.encoding) as css_file:
                    self.user_css.append({
                        'path_url': utils.get_path_url(css_path,
                                                       self.relative),
                        'contents': css_file.read(),
                    })
示例#6
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 string.
        """
        if isinstance(css_list, string_types):
            css_list = [css_list]

        for css_path in css_list:
            if css_path and css_path not in self.user_css:
                if not os.path.exists(css_path):
                    raise IOError('%s user css file not found' % (css_path,))
                with codecs.open(css_path, encoding=self.encoding) as css_file:
                    self.user_css.append({
                        'path_url': utils.get_path_url(css_path,
                                                       self.relative),
                        'contents': css_file.read(),
                    })
示例#7
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]

        regex = r'<img.*?src="(?!http://)(.*?)".*/?>'

        images = re.findall(regex, 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
示例#8
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 string.
     """
     if isinstance(js_list, string_types):
         js_list = [js_list]
     for js_path in js_list:
         if js_path and js_path not 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:
                 with codecs.open(js_path,
                                  encoding=self.encoding) as js_file:
                     self.user_js.append({
                         'path_url': utils.get_path_url(js_path,
                                                        self.relative),
                         'contents': js_file.read(),
                     })
示例#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 string.
     """
     if isinstance(js_list, string_types):
         js_list = [js_list]
     for js_path in js_list:
         if js_path and js_path not 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:
                 with codecs.open(js_path,
                                  encoding=self.encoding) as js_file:
                     self.user_js.append({
                         'path_url': utils.get_path_url(js_path,
                                                        self.relative),
                         'contents': js_file.read(),
                     })