Example #1
0
def save(output_file=None, format=None):
    """
        Function to render the document to html

    """

    texp = time.time()
    bname = os.path.basename(output_file)
    bdir = output_file.replace(bname,'')


    if 'html' in output_file:
        document._output_format = 'html5'

        #check if we use cache
        if document._cache == True:
            cache_file = bdir+'.cache_'+bname.split('.')[0]+'_html5.pklz'
            print("[Beampy] Chache file to %s"%cache_file)
            document._cache = cache_slides(cache_file)

        output = html5_export()

    elif output_file != None and format == "svg":
        document._output_format = 'svg'

        #check if we use cache
        if document._cache == True:
            cache_file = bdir+'.cache_'+bname.split('.')[0]+'_svg.pklz'
            print("[Beampy] Chache file to %s"%cache_file)
            document._cache = cache_slides(cache_file)

        output = svg_export(output_file)
        output_file = None

    elif 'pdf' in output_file:
        document._output_format = 'pdf'

        #check if we use cache
        if document._cache == True:
            cache_file = bdir+'.cache_'+bname.split('.')[0]+'_pdf.pklz'
            print("[Beampy] Chache file to %s"%cache_file)
            document._cache = cache_slides(cache_file)

        output = pdf_export(output_file)
        output_file = None

    if output_file != None:
        with open(output_file,'w') as f:
            f.write( output.encode('utf8') )

    else:
        print(output)

    #write cache file
    if document._cache != None:
        document._cache.write_cache()

    print("[Beampy] Done in %0.1f seconds"%(time.time()-texp))
Example #2
0
    def set_options(self, input_dict):
        #Get document option from THEME
        default_options = self._theme['document']
        if 'theme' in input_dict:
            default_options['theme'] = input_dict['theme']

        good_values = {}
        for key, value in input_dict.items():
            if key in default_options:
                good_values[key] = value
            else:
                print('%s is not a valid argument for document'%key)
                print('valid arguments')
                print(default_options)
                sys.exit(1)

        #Update default if not in input
        for key, value in default_options.items():
            if key not in good_values:
                good_values[key] = value

        #Set size etc...
        document._width = good_values['width']
        document._height = good_values['height']
        document._guide = good_values['guide']
        document._text_box = good_values['text_box']
        document._cache = good_values['cache']
        document._optimize_svg = good_values['optimize']
        document._resize_raster = good_values['resize_raster']
        document._output_format = good_values['format']
        if document._cache == False:
            document._cache = None
        else:
            #cache_file = './.beampy_cache_%s_%s.pklz'%(script_file_name, document._output_format)
            cache_file = './.beampy_cache_%s.pklz'%(script_file_name)
            print("\nChache file to %s"%(cache_file))
            document._cache = cache_slides(cache_file, self)

        self.options = good_values