PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Tag.io

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