Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import with
- type
- Bob = object
- y: int
- Test = object
- x: Bob
- proc `$`(x: Bob): string =
- "Bob[" & $x.y & "]"
- # This could be defined by a user, or it could be absent
- #proc toHtml(x: Bob): string =
- # $x.y
- proc toCss(x: Bob): string =
- "(This is CSS: " & $x.y & ")"
- # This would be automatically generated by autotemplate
- proc toHtml(x: Test): string =
- proc tt(x: auto): string =
- when compiles(toHtml(x)):
- toHtml(x)
- else:
- $x
- proc `$`(x: auto): string =
- tt(x)
- with x:
- "Hello: " & $x & " world"
- proc toCss(x: Test): string =
- proc tt(x: auto): string =
- when compiles(toCss(x)):
- toCss(x)
- else:
- $x
- proc `$`(x: auto): string =
- tt(x)
- with x:
- "Hello: " & $x & " world"
- echo Test(x: Bob(y: 42)).toHtml # This should output: Hello: Bob[42] world
- echo Test(x: Bob(y: 42)).toCss # This should output: Hello: (This is CSS: 42) world
Advertisement
Add Comment
Please, Sign In to add comment