Skip to content

Instantly share code, notes, and snippets.

@adamrabung
Created September 29, 2011 13:43
Show Gist options
  • Save adamrabung/1250746 to your computer and use it in GitHub Desktop.
Save adamrabung/1250746 to your computer and use it in GitHub Desktop.
trait Publishable[T] {
def asWebMarkup(p: T): String
}
case class BlogPost(title: String, text: String)
implicit object BlogPostPublisher extends Publishable[BlogPost] {
def asWebMarkup(p: BlogPost) =
"""|<h2>%s</h2>
|<div>%s</div>""".stripMargin format(p title, p text)
}
object WebPublisher {
def publish[T](p: T)(implicit publisher:Publishable[T]) = println(publisher.asWebMarkup(p))
}
val post = new BlogPost("Test", "This is a test post")
val web = WebPublisher.publish(post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment