Apr 252013
 

OpenText Content Server Builder is the IDE for OpenText Content Server. It’s an advanced IDE given its age, but a missing feature of the IDE is a code formatter. For example, consider the following OScript and imagine how difficult it would be to read if it were 500 lines long (yes, some people write scripts this long, but that’s another topic):

/**
* Dump a module to the file system.
*/
function dump(String moduleName, \
String subdirectory="dmp")

Object module = $Kernel.ModuleSubsystem.GetItem(moduleName)

if IsDefined( module )

String ospace

 for ospace in module.fOSpaces
String path = module.PathPrefix() + subdirectory + File.Separator()
File.Create(path)
String filename = Str.Format('%1%2.dmp', path, ospace)
$Builder.Utilities.ExportOSpace( filename, OS.Root(ospace) )
end

    else
echo("Module not found: %1", moduleName)
end
  end

To fix this problem I created an OScript Beautifier, which formats OScript into something more readable:

/**
 * Dump a module to the file system.
 */
function dump(String moduleName, \
        String subdirectory="dmp")

    Object module = $Kernel.ModuleSubsystem.GetItem(moduleName)

    if IsDefined( module )

        String ospace

        for ospace in module.fOSpaces
            String path = module.PathPrefix() + subdirectory + File.Separator()
            File.Create(path)
            String filename = Str.Format('%1%2.dmp', path, ospace)
            $Builder.Utilities.ExportOSpace( filename, OS.Root(ospace) )
        end

    else
        echo("Module not found: %1", moduleName)
    end
end

The beautifier integrates into Builder and can be run against a script by executing a function from the Tools menu. It has saved me countless hours of formatting.

You can download beautify_oscript.lxe from GitHub as a Gist. Feel free to clone the gist and improve it.

  4 Responses to “OScript Beautifier”

  1. I liked this and I am repurposing it

  2. Very cool Chris!

  3. This is really nice..Will definitely save time!!!

  4. Great article. Thanks for posting it!

 Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)