Using the TYPE header

This is something I've had churning in my mind since I first saw Type: 'index on a RebSite index: if a Rebol header has a TYPE value, it generally doesn't contain your regular DO code (some do—modules, for instance).

What if when you DO a script that has a TYPE value, it passes it on to a handler for that type? Presumably in the above example, you'd open a Rebsite viewer, or return a block of items in the index.

That's great if your TYPE is already registered, but if you call a script from SHELL:

ren-c script-in-my-own-dialect.reb

Then you'd have no way to register a handler. Unless even custom scripts could use a NEEDS header:

Rebol [
    Title: "A Book"
    Type: 'epub
    Needs: [%epub-dialect-handler.reb]
]

some dialect stuff

manifest [
     * %some.html
     * %content.html
     %files.html
]

Shell -> HTML, could be CGI too:

#!/usr/local/bin/ren-c

Rebol [
    Title: "My Web Page"
    Type: 'lest
    Needs: [%lest.reb]
]

head
title "Hello World!"

body
h1
    either (now/time < 12:00) "Good morning" "Good afternoon" 
    " 🌎🌍🌏."
2 Likes

In addition, if you had e.g. a %python.reb that registered a codec linked to %.py files importing a Python script as a Rebol dialect and simulated a header with a Type: 'python Needs: %python.reb, then you could theoretically emulate Python by just saying: ren-c script.py (presuming your Python dialect was up to snuff).

Edit: this bears further thought as you'd need the codec already in place, but an interesting avenue all the same.

2 Likes

I'd like something this as well, even with different file extensions. But maybe the different file extensions would be done with another level of dot, e.g. .epub.reb.

2 Likes

I'm all for this and is something I've wanted (and even briefly played about with) in the past.

When I envisaged this before this is how I saw it...

Rebol [
    title: "My web page"
    dialect: html-dialect
]

;; dialect code goes here

This looks for module html-dialect.reb (same way needs: works).

But you could also be explicit...

Rebol [
    title: "My web page"
    dialect: %html-dialect.reb
]

;; dialect code goes here
2 Likes