Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Web Development

When a Language Becomes a Platform


===A sample REBOL application.

REBOL [
	Title: "A Sample Document"
	Author: "Kurt Cagle"
	Date: 12-Jan-2002
	Version: 1.1.2
]	

flash "Fetching image..."
read-thru/to http://www.rebol.com/view/demos/palms.jpg %palms.jpg
unview

content: {A Sample Document

===My Introduction

The ability to create rich wizards via easy to use text is perhaps one of the real advantages 
that REBOL offers. This, for instance, is a modified script from the initial documentation, 
where such elements as headers are indicated by elements such as the characters ===.
These are automatically parsed out by the REBOL engine into control headers.

---Inline Code

You can also introduce inline code into REBOL scripts. For instance, the following line will create a pop-up text message:

   view layout [
		text "This is a sample app!"
		button blue "With a Button"
		]

===A Second Section

Much more information can be contained within one of these documents.



}



code: text: layo: xview: none

sections: []

layouts: []

space: charset " ^-"
chars: complement charset " ^-^/"

rules: [title some parts]

title: [text-line (title-line: text)]

parts: [
	  newline
	| "===" section
	| "---" subsect
	| "!" note
	| example
	| paragraph
]

text-line: [copy text to newline newline]
indented:  [some space thru newline]
paragraph: [copy para some [chars thru newline] (emit txt para)]
note: [copy para some [chars thru newline] (emit-note para)]
example: [
	copy code some [indented | some newline indented]
	(emit-code code)
]
section: [
	text-line (
		append sections text
		append/only layouts layo: copy page-template
		emit h1 text
	) newline
]
subsect: [text-line (emit h2 text)]

emit: func ['style data] [repend layo [style data]]

emit-code: func [code] [
	remove back tail code
	repend layo ['code 460x-1 trim/auto code 'show-example]
]

emit-note: func [code] [
	remove back tail code
	repend layo ['tnt 460x-1 code]
]

show-example: [
	if xview [xy: xview/offset  unview/only xview]
	xcode: load/all face/text
	if not block? xcode [xcode: reduce [xcode]] ;!!! fix load/all
	if here: select xcode 'layout [xcode: here]
	xview: view/new/offset layout xcode xy
]

page-template: [
	size 500x480 origin 8x8
	backdrop white
	style code tt black silver bold as-is para [origin: margin: 12x8]
		font [colors: [0.0.0 0.80.0]]
	style tnt txt maroon bold
]

parse/all detab content rules

show-page: func [i /local blk][
	i: max 1 min length? sections i
	append clear tl/picked pick sections i show tl
	if blk: pick layouts this-page: i [f-box/pane: layout/offset blk 0x0 show f-box]
]

main: layout [
	across
	h2 title-line return
	space 0
	tl: text-list 160x480 bold black white data sections [
		show-page index? find sections value
	]
	h: at
	f-box: info 500x480
	at h + 456x-24
	across space 4
	arrow left  keycode [up left] [show-page this-page - 1]
	arrow right keycode [down right] [show-page this-page + 1]
	pad -120
	txt form system/script/header/date/date
]
show-page 1
xy: main/offset + 480x100
view main



Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.