/lib/Tag.io
Unknown | 60 lines | 54 code | 6 blank | 0 comment | 0 complexity | d4d335955f11aeeb7634034f83541e53 MD5 | raw file
1Tag := Object clone do( 2 init := method( 3 tag ::= Sequence clone 4 attributes ::= List clone 5 canvas ::= call sender 6 ) 7 8 addAttribute := method(name, value, 9 attributes append(list(name, value)) 10 self 11 ) 12 13 with := method( 14 canvas result appendSeq("<", tag) 15 attributes foreach(attr, 16 canvas result appendSeq(" ", attr at(0), "='", attr at(1), "'") 17 ) 18 canvas result appendSeq(">") 19 call message arguments foreach(arg, 20 arg doInContext(call sender) 21 ) 22 canvas result appendSeq("</", tag, ">") 23 // Return nil, so that it's not possible to chain after the 'with' call 24 // as with is the completion of the tag. 25 nil 26 ) 27) 28 29InputTag := Tag clone do( 30 callback := method(code, 31 id := canvas callbacks register(list(call sender, code)) 32 addAttribute("name", id) 33 ) 34) 35 36InputTextTag := InputTag clone do( 37 init := method( 38 super(init) 39 canvas = call sender 40 attributes append(list("type", "text")) 41 tag = "input" 42 ) 43) 44 45InputTextAreaTag := InputTag clone do( 46 init := method( 47 super(init) 48 canvas = call sender 49 tag = "textarea" 50 ) 51) 52 53InputDateTag := InputTag clone do( 54 init := method( 55 super(init) 56 canvas = call sender 57 attributes append(list("type", "date")) 58 tag = "input" 59 ) 60)