Difference between revisions of "Template:Collapsible script"

From relax wiki
Jump to navigation Jump to search
(Created the {{collapsible script}} template based on my content at [http://wiki.flightgear.org/Template:Collapsible_script].)
(No difference)

Revision as of 09:49, 17 October 2015

Template documentation

Goal

This template allow for large scripts or code segments to be embedded into relax 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=}}
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.

Examples

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
}}

The result is: