Difference between revisions of "Template:CodeSample"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
m (Protected "Template:CodeSample": High traffic page ([edit=sysop] (indefinite) [move=sysop] (indefinite)))
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<includeonly>{{#if: {{{title|}}}|<h2>{{{title}}}</h2>}}{{#if: {{{description|}}}|<p>{{{description}}}</p>}}<div style="margin-bottom: 1em; border: dashed 1px green; padding: 1em;" title="Note: All functions (shown in blue) have their own page on the wiki you can look up for more information.">{{{code}}}</div>{{#if: {{{moreinfo|}}}|{{{moreinfo}}}}}</includeonly>
+
<includeonly>{{#if: {{{title|}}}|<h2>{{{title}}}</h2>}}{{#if: {{{description|}}}|<p>{{{description}}}</p>}}
 +
{{{code}}}{{#if: {{{moreinfo|}}}|{{{moreinfo}}}}}</includeonly>
 
<noinclude>
 
<noinclude>
 
<p>Uses the named parameters ''title'', ''description'' and ''code'' to display a code block & its information.</p>
 
<p>Uses the named parameters ''title'', ''description'' and ''code'' to display a code block & its information.</p>
 
<p>Note that only ''code'' is required; the ''title'' and ''description'' are optional.</p>
 
<p>Note that only ''code'' is required; the ''title'' and ''description'' are optional.</p>
<p>A sample call to this template:</p>
+
 
<pre>
+
==Example==
 +
{| class="wikitable"
 +
! Wiki markup
 +
! Result
 +
|-
 +
| <pre>
 
{{CodeSample|
 
{{CodeSample|
 
title=Sample Code|
 
title=Sample Code|
 
description=Some basic sample code.|
 
description=Some basic sample code.|
 
code=
 
code=
<syntaxhighlight>
+
<syntaxhighlight lang="d" line>
 
int i = 1; //this line is useless!
 
int i = 1; //this line is useless!
 
if (to_int(my_id()) > 1) {
 
if (to_int(my_id()) > 1) {
 
   print("Aw, I guess you aren't Jick.");
 
   print("Aw, I guess you aren't Jick.");
 
}
 
}
</syntaxhighlight>
+
</syntaxhighlight>|
 +
moreinfo=
 +
Here is how you show a return value:
 +
&lt;pre&gt;
 +
"Aw, I guess you aren't Jick.");
 +
&lt;/pre&gt;
 
}}
 
}}
 
</pre>
 
</pre>
<p>Which produces the following:</p>
+
|
 
{{CodeSample|
 
{{CodeSample|
 
title=Sample Code|
 
title=Sample Code|
 
description=Some basic sample code.|
 
description=Some basic sample code.|
 
code=
 
code=
<syntaxhighlight>
+
<syntaxhighlight lang="d" line>
 
int i = 1; //this line is useless!
 
int i = 1; //this line is useless!
 
if (to_int(my_id()) > 1) {
 
if (to_int(my_id()) > 1) {
 
   print("Aw, I guess you aren't Jick.");
 
   print("Aw, I guess you aren't Jick.");
 
}
 
}
</syntaxhighlight>
+
</syntaxhighlight>|
 +
moreinfo=
 +
Here is how you show a return value:
 +
<pre>
 +
Aw, I guess you aren't Jick.
 +
</pre>
 
}}
 
}}
 +
|}
 +
 +
==Read Me==
 +
Please keep the following in mind when adding a code sample:
 +
* Tabs display poorly in the <nowiki><syntaxhighlight></nowiki> tag. Please use 3 spaces for ASH, 2 spaces for JS.
 +
** Yes, some people have other preferences; I'm not going to tell you how to write your own scripts
 +
** In order to make the wiki as easy-to-use as possible, it's important to keep to ONE standard, please
 +
* Please make sure there is one code sample (the 1st) that is as short & to-the-point as is possible.
 +
* Please make sure that testing the code sample won't be significantly negative to the user; these are designed as hands-on examples
 +
** For instance, if you must autosell items in the sample, choose something cheap
 +
** Do NOT include anything that could cause "permanent" damage!
 +
* Please follow other conventions used on other code samples as much as possible
 +
* Please avoid using cli_execute() if there is a built-in ash function
 +
* Please note that incredibly long lines will break formatting on smaller screens; break things up if needed
 +
* Do not modify a code sample purely to "add your own mark" to a page; if it illustrates the function, leave it be
 +
 
[[Category:Basic Templates]]</noinclude>
 
[[Category:Basic Templates]]</noinclude>

Latest revision as of 14:33, 31 December 2020


Uses the named parameters title, description and code to display a code block & its information.

Note that only code is required; the title and description are optional.

Example

Wiki markup Result
{{CodeSample|
title=Sample Code|
description=Some basic sample code.|
code=
<syntaxhighlight lang="d" line>
int i = 1; //this line is useless!
if (to_int(my_id()) > 1) {
   print("Aw, I guess you aren't Jick.");
}
</syntaxhighlight>|
moreinfo=
Here is how you show a return value:
<pre>
"Aw, I guess you aren't Jick.");
</pre>
}}

Sample Code

Some basic sample code.

1 int i = 1; //this line is useless!
2 if (to_int(my_id()) > 1) {
3    print("Aw, I guess you aren't Jick.");
4 }
Here is how you show a return value:
Aw, I guess you aren't Jick.

Read Me

Please keep the following in mind when adding a code sample:

  • Tabs display poorly in the <syntaxhighlight> tag. Please use 3 spaces for ASH, 2 spaces for JS.
    • Yes, some people have other preferences; I'm not going to tell you how to write your own scripts
    • In order to make the wiki as easy-to-use as possible, it's important to keep to ONE standard, please
  • Please make sure there is one code sample (the 1st) that is as short & to-the-point as is possible.
  • Please make sure that testing the code sample won't be significantly negative to the user; these are designed as hands-on examples
    • For instance, if you must autosell items in the sample, choose something cheap
    • Do NOT include anything that could cause "permanent" damage!
  • Please follow other conventions used on other code samples as much as possible
  • Please avoid using cli_execute() if there is a built-in ash function
  • Please note that incredibly long lines will break formatting on smaller screens; break things up if needed
  • Do not modify a code sample purely to "add your own mark" to a page; if it illustrates the function, leave it be