Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: New dialect for building HTML and XML tags [Announce] ML update

From: AJMartin::orcon::net::nz at: 24-Dec-2003 22:51

I've enhanced my ML dialect to eliminate the need for the 'check function:
>> French: true
== true
>> ML compose [input/type/checked checkbox (French)]
== {<input type="checkbox" checked="checked" />}
>> French: false
== false
>> ML compose [input/type/checked checkbox (French)]
== {<input type="checkbox" />}
>> French: none
== none
>> ML compose [input/type/checked checkbox (French)]
== {<input type="checkbox" />} Note that a logic! false or none! attribute causes the corresponding Name to vanish away, which makes it just right for optional attributes in HTML and XML tags. And I've enhanced my ML dialect to allow building complex tags, with out needing to use path! values (but it still allows path! values)! Just use a surrounding <" and ">" for the "expanded" tag:
>> ML [< a href http://www.rebol.com title "Rebol HQ" > [ "Rebol HQ Link"] ]
== {<a href="http://www.rebol.com" title="Rebol HQ">Rebol HQ Link</a>} I've also chopped out NameSpace, which was implemented wrongly (it doesn't do the right thing for XSL stylesheets that generate HTML). :( I've also chopped out some redundant words and values. :) Enjoy! Andrew J Martin Speaking in tongues and performing miracles. ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/ -><- ; From my %Patterns.r script: Fail^: [to end skip] ; A rule that always fails. Succeed^: [] ; A rule that always succeeds. LT^: compose [(to-lit-word "<")] GT^: compose [(to-lit-word ">")] Slash^: Compose [(to-lit-word "/")] [ Rebol [ Name: 'ML Title: "ML" File: %"ML.r" Author: "A J Martin" Owner: "Aztecnology" Rights: "Copyright © 2003 A J Martin, Aztecnology." eMail: [Rebol--orcon--net--nz] Web: http://www.rebol.it/Valley/ Tabs: 4 Purpose: {ML generates XML markup from Rebol words, paths, refinements, tags and blocks.} Requires: [Build-Tag Fail^ LT^ GT^ Slash^] Provides: [ML] Language: 'English Date: 11/December/2003 Version: 2.0.0 ] ML: function [ {ML generates XML markup from Rebol words, paths, tags, refinements and blocks.} Dialect [block!] "ML Dialect" ] [Gate String Values_Rule Value Tag Values Name Attribute] [ Gate: [] String: copy "" Values_Rule: [ ; Caution! The 'none word below is replaced in the 'parse rule below! none [ set Value any-type! ( Tag: next next Tag either Value [ if logic? Value [ Value: form first back Tag ] insert/only Tag :Value ] [ remove back Tag ] Value: none ) (Tag: head Tag) ] ; Caution! The 'opt word below is replaced in the 'parse rule below! opt [ set Value [ decimal! | file! | block! | string! | char! | money! | time! | issue! | tuple! | date! | email! | pair! | logic! | integer! | url! ] ] ] parse Dialect [ any [ [ set Tag tag! ( Values_Rule/1: 0 ; Replace 'none word in 'Values_Rule above. Values_Rule/3: either any [ ; Replace 'opt word... #"/" = last Tag ; empty tag. #"?" = first Tag ; XML tag. #"!" = first Tag ; DOCTYPE tag. ] [0] [1] ) | [ LT^ set Tag [word! | url!] ( Values: make block! 10 insert tail Values Tag ) any [ [opt Slash^ GT^ (insert Gate Fail^) Fail^] | Gate set Name [word! | url!] set Attribute [ decimal! | file! | string! | char! | none! | money! | time! | issue! | tuple! | date! | email! | logic! | integer! | url! | lit-word! ] ( if Attribute [ if logic? Attribute [ Attribute: form Name ] insert tail Values reduce [Name Attribute] ] ) ] ( clear Gate Tag: Values Values_Rule/1: 0 ; Replace 'none word in 'Values_Rule above. Values_Rule/3: 1 ; Replace 'opt word... ) opt [Slash^ (Values_Rule/3: 0)] GT^ ] | set Tag [path! | word!] ( Tag: to-block get 'Tag ; Replace 'none word in 'Values_Rule above. Values_Rule/1: -1 + length? Tag Values_Rule/3: 'opt ; Replace 'opt word... ) ] (Value: none) Values_Rule ( if not tag? Tag [ Tag: build-tag Tag ] insert tail String reduce either none? :Value [ if all [ #"/" <> last Tag #"?" <> first Tag #"!" <> first Tag ] [ insert tail Tag " /" ] Tag ] [ [ Tag either block? :Value [ML Value] [:Value] to-tag join #"/" first to-block Tag ] ] Values_Rule/1: none ) | set Tag refinement! ( ; Converts: /br to: <br /> for a saving of three characters! insert tail String head insert tail to-tag Tag " /" ) | none! | logic! ; Ignore 'none and logic! values. | unset! ; And ignore unset values (caused by 'print...) | set Value any-type! (insert/only tail String :Value) ] end ] String ] ]