#include function for HTML block files

#include function for HTML block files

1
NewbieNewbie
1

    May 05, 2011#1

    I have HTML block files that I use to generate long letter.
    Currently, I cut and past them into a framework file manually.

    I wish to automate the process in a VERY specific way, to create a pre-processor like "#include" script, so that my new document will look like that


    <html>
    <header>whatever required here</header>
    <body>
    <global = a group of required global definitions, design parameters, tags and tables>

    <! here is the important part>

    #include "d:\users\username\project\data\zBlock-Hello.html"
    #include "d:\users\username\project\data\zBlock-UserDetails.html"
    #include "d:\users\username\project\data\zBlock-DocumentsLinks.html"
    #include "d:\users\username\project\data\zBlock-DownloadLinks.html"


    </global>
    </body>
    </html>


    The structure of the #include script I believe should be something like the following:
    UltraEdit.document[$FileName].open
    UltraEdit.document[$FileName].SelectAll
    UltraEdit.document[$FileName].copy
    UltraEdit.activeDocument.paste
    UltraEdit.document[$FileName].close


    Questions:
    (1) How to obtain the file name string ($FileName) required for the commands
    (2) How to implement the commands
    (3) How to get an output file, that is how to actually execute the script?

    I am TOTALLY new to Ultra Edit, I have to find my way around on how to do things here, I would DEEPLY appreciate a step by step guidance (or if anyone may just programme it and I use it as an excellent tutorial), if my modus operandi is erroneous, please enlighten me on how to do that correctly with UE. Please note the a simple "merge" is UNFAVOURABLE as I must have the work frame and I wish not to split the decelerations openings from their closing, leaving me with a serve maintenance problem.


    TYIA, J

    6,675585
    Grand MasterGrand Master
    6,675585

      May 07, 2011#2

      In former times this was done on webserver with SSI (server side includes), nowadays PHP is used usually. But if you want to do that offline, here is a script which should fulfill the task. I have included just one important comment and no more. If I should comment the code for you when the script is working, please feel free to ask for the comments.

      Code: Select all

      // Include here function GetFileIndex posted in UltraEdit script forum
      // http://forums.ultraedit.com/viewtopic.php?f=52&t=4596#p26710
      
      if (UltraEdit.document.length > 1) {
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
         var nCurLine = UltraEdit.activeDocument.currentLineNum;
         var nCurColumn = UltraEdit.activeDocument.currentColumnNum;
         if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nCurColumn++;
         UltraEdit.activeDocument.selectAll();
         if (UltraEdit.activeDocument.isSel()) {
            UltraEdit.selectClipboard(9);
            UltraEdit.activeDocument.copy();
            UltraEdit.activeDocument.endSelect();
            UltraEdit.activeDocument.gotoLine(nCurLine,nCurColumn);
            var nOutputIndex = UltraEdit.document.length;
            UltraEdit.newFile();
            UltraEdit.ueReOn();
            UltraEdit.document[nOutputIndex].paste();
            UltraEdit.document[nOutputIndex].top();
            UltraEdit.document[nOutputIndex].findReplace.mode=0;
            UltraEdit.document[nOutputIndex].findReplace.matchCase=true;
            UltraEdit.document[nOutputIndex].findReplace.matchWord=false;
            UltraEdit.document[nOutputIndex].findReplace.regExp=true;
            UltraEdit.document[nOutputIndex].findReplace.searchDown=true;
            UltraEdit.document[nOutputIndex].findReplace.searchInColumn=false;
            var sLineType = "\r";
            if (UltraEdit.document[nOutputIndex].findReplace.find("^p")) sLineType = "\r\n";
            else if (UltraEdit.document[nOutputIndex].findReplace.find("^n")) sLineType = "\n";
            UltraEdit.document[nOutputIndex].top();
            while (UltraEdit.document[nOutputIndex].findReplace.find("%[ ^t]++#include[ ^t]+\"*\"")) {
               var sFileName = UltraEdit.activeDocument.selection.replace(/.*"(.+)"/,"$1");
               var nIncludeIndex = GetFileIndex(sFileName);
               if (nIncludeIndex < 0) {
                  UltraEdit.open(sFileName);
                  UltraEdit.activeDocument.selectAll();
                  UltraEdit.activeDocument.copy();
                  UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
               } else {
                  UltraEdit.document[nIncludeIndex].selectAll();
                  UltraEdit.document[nIncludeIndex].copy();
               }
               UltraEdit.document[nOutputIndex].selectLine();
               UltraEdit.document[nOutputIndex].paste();
               if (UltraEdit.document[nOutputIndex].isColNumGt(1)) {
                  UltraEdit.document[nOutputIndex].write(sLineType);
               }
            }
            UltraEdit.document[nOutputIndex].top();
            UltraEdit.clearClipboard();
            UltraEdit.selectClipboard(0);
         }
      }