Skip to content

Instantly share code, notes, and snippets.

@IvanShamatov
Created August 31, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanShamatov/53ff6b371575cd67c4a5e93eee5f958a to your computer and use it in GitHub Desktop.
Save IvanShamatov/53ff6b371575cd67c4a5e93eee5f958a to your computer and use it in GitHub Desktop.
Comment = Struct.new(:title, :body, :author)
class Comment::Item
include Componenta
render :html do
h1 object.title
div object.body
span object.author
end
render :json do
title object.title
body object.body
author object.author
end
end
comment = Comment.new("Test", "This is first comment", "Ivan")
Comment::Item.new(comment).render # => "<h1>Test</h1><div>This is first comment</div><span>Ivan</span>"
Comment::Item.new(comment).render(:json) # => '{"title":"Test","body":"This is first comment","author":"Ivan"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment