Example #1
0
 def test_builder_registration(self):
     def func(): 
         pass
     builder = Builder()
     function = func
     builder.register(function)
     self.assert_equal(builder.get_callbacks(), [function])
Example #2
0
 def test_run_builder(self):
     def ret(content):
         return "return"
     builder = Builder()
     function = ret
     builder.register(function)
     self.assert_equal(builder.content, "")
     builder.run()
     self.assert_equal(builder.content, "return")
Example #3
0
 def test_duplicate_registration_with_builder(self):
     def ret(content):
         return "return"
     builder = Builder()
     function = ret
     builder.register(function)
     self.assert_equal(builder.get_callbacks(), [function])
     builder.register(function)
     self.assert_equal(builder.get_callbacks(), [function])
     self.assert_equal(builder.content, "")
     builder.run()
     self.assert_equal(builder.content, "return")
Example #4
0
def main(argv):
    "Build routine for compiling multiple text files into a pdf or html file"

    try:
        opts, args = getopt.getopt(argv, "ho:p:cu", 
            ["help", "output=", "processor=", "clean"]) 
    except getopt.GetoptError:           
        usage()                          
        sys.exit(2)

    # set default output to html
    output = "html"   
    # set the default processor to textile
    processor = "textile"
         
    for opt, arg in opts:
        if opt in ("-h", "--help"):      
            usage()
            sys.exit()
        elif opt in ("-c", "--clean"):      
            clean()
            sys.exit()
        elif opt in ("-o", "--output"): 
            if arg in ["html", "pdf", "txt"]:
                output = arg
            else:
                usage()
                sys.exit()
        
        # we only get here if we have a valid output
        if opt in ("-p", "--processor"): 
            if arg in ["textile", "markdown", "none"]:
                processor = arg
            else:
                usage()
                sys.exit()

    # instantiate the builder
    builder = Builder()
    
    # check we have a build directory
    # and create one if not
    if not os.path.isdir("build"):
        os.makedirs("build")
    
    builder.register(content_buffer)
    
    if processor == "markdown":
        builder.register(from_markdown)
    elif processor == "none":
        pass
    else:
        builder.register(from_textile)
        
    builder.register(load_code)
    
    builder.register(highlight_code)
    
    # check if we need to generate a pdf
    if output == "pdf":
        builder.register(generate_pdf)
    elif output == "txt":
        builder.register(generate_txt)
    # alternatively generate html
    else:
        builder.register(generate_html)

    # run any registered callbacks
    builder.run()