Template:Collapsible script

From FlightGear wiki
Jump to navigation Jump to search


The following template description is not displayed when the template is inserted in an article.

Goal

This template allow for large scripts or code segments to be embedded into FlightGear wiki articles without cluttering the article. Introduction text, the script, code, or commands, and conclusion text will be embedded within a MediaWiki NavFrame, which starts off in a collapsed state.

Usage

{{collapsible script|type=|title=|intro=|lang=|script=|conc=|bgcolor=|show=}}
type
The type of script, code, shell command, etc. This text, which defaults to Code, will be bold and form the start of the heading.
title
The optional title to show in the NavFrame header. This follows the type and is of normal font weight (not bold).
intro
Any optional introductory text.
lang
The optional language of the script or code for syntax highlighting. If not given, the language defaults to text to avoid syntax highlighting.
script
The script, code block, or set of commands. This will be placed within a set of <syntaxhighlight> tags.
conc
Any optional text to conclude with.
bgcolor
The optional background colour of the NavFrame header. This defaults to transparent.
show
If set, the NavFrame will start off in the opened state.

Examples

Nasal example

{{collapsible script
| type   = Nasal code
| title  = Closure demo
| script = var timers = [];
foreach(var delay; [2.0, 4.0, 8.0] ) {
#this declares an anonymous/unnamed function
(func(arg...) 
{
var interval=delay; 
var myTimer = maketimer(interval, func() {
print("Hello from the ", interval,"-second timer!");
}); # end of the embedded func
myTimer.start();
append(timers, myTimer);
})(); # this will directly invoke the unnamed function
} # end of the foreach loop

# kill all timers
maketimer(60, func() {
foreach(var t; timers)
 t.stop();
});
| lang = nasal
}}

Minimal example

When the following is used within an article:

{{collapsible script
| title  = The ''grep_python'' script.
| script = 
#! /usr/bin/env python

import os
import sys

# The args.
args = ''
for i in range(1, len(sys.argv)):
    args = "%s %s" % (args, sys.argv[i])

os.system("find -name '*.py' -exec grep --color=always -H %s '{}' \;" % args)
}}

The result is:

Using all options

When the following is used within an article:

{{collapsible script
| type    = Python script
| title   = The ''grep_python'' script.
| intro   = This is a script for grepping Python files.
| lang    = python
| script  = 
#! /usr/bin/env python

import os
import sys

# The args.
args = ''
for i in range(1, len(sys.argv)):
    args = "%s %s" % (args, sys.argv[i])

os.system("find -name '*.py' -exec grep --color=always -H %s '{}' \;" % args)
| conc    = Note that this script is not efficient.
| bgcolor = #e0f2ff
| show    = 1
}}

The result is: