Created
August 31, 2016 14:19
-
-
Save IvanShamatov/53ff6b371575cd67c4a5e93eee5f958a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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