Difference between revisions of "Mediawiki RawFile"

From YobiWiki
Jump to navigation Jump to search
Line 16: Line 16:
 
<br>Do we need a MIME type?
 
<br>Do we need a MIME type?
 
<br>Transformation:
 
<br>Transformation:
<br><code><nowiki>[{{fullurl:{{PAGENAME}}|action=raw&rawsnippet=myscript.sh}} myscript.sh]</nowiki></code>
+
<br><code><nowiki>{{fullurl:{{PAGENAME}}|action=raw&rawsnippet=myscript.sh}}</nowiki></code>
<br> Test: save the following code as {{#rawsnippet: myscript.sh}}
+
<br> Test: save the following code [{{#rawsnippet: myscript.sh}}|as myscript.sh]
 
<source lang=bash>
 
<source lang=bash>
 
#!/bin/bash
 
#!/bin/bash
Line 24: Line 24:
 
exit 0
 
exit 0
 
</source>
 
</source>
  +
<code><nowiki>{{#rawsnippet: myscript.sh}}</nowiki></code> combines in fact 2 elements: the text that will be replaced by the link and the anchor just before the code section.
  +
<br>We can separate both functionalities with:
  +
  +
One such declaration, just before the code section:
  +
<code><nowiki>{{#rawsnippetAnchor: myscript.sh}}</nowiki></code>
  +
  +
One or many such declarations to create the download links:
  +
<code><nowiki>{{#rawsnippetLink: myscript.sh}}</nowiki></code>
   
 
==Hook on Raw==
 
==Hook on Raw==

Revision as of 22:10, 2 April 2008

Introduction

The idea is to be able to download directly a portion of code as a file.
I've numerous code examples in my wiki and I wast an easy way to download them, easier than a copy/paste!

  • It must work with pre, nowiki, js, css, code, source, so let's make it general: take the tag that comes after the parser function we'll create and select data up to the closing tag.

2 parts:

  • the parser magic word that will be converted into a "Save it as <filename>"
  • an extended action=raw that will strip the raw output to keep the desired code

Documentation

Syntax

{{#rawsnippet: myscript.sh}}
Do we need a MIME type?
Transformation:
{{fullurl:{{PAGENAME}}|action=raw&rawsnippet=myscript.sh}}
Test: save the following code [{{#rawsnippet: myscript.sh}}|as myscript.sh]

#!/bin/bash

echo 'Hello world!'
exit 0

{{#rawsnippet: myscript.sh}} combines in fact 2 elements: the text that will be replaced by the link and the anchor just before the code section.
We can separate both functionalities with:

One such declaration, just before the code section: {{#rawsnippetAnchor: myscript.sh}}

One or many such declarations to create the download links: {{#rawsnippetLink: myscript.sh}}

Hook on Raw

  • Must extract the right paragraph
    • Strip all up to the right rawsnippet: filename tag
    • Find the next tag
    • Select up to the closure tag
  • Must provide the filename to the browser
  • Tells the browser NOT to cache the raw?