Created
December 14, 2014 19:04
-
-
Save thecatwasnot/c58da1c58bd83f08dc81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<h1>New Post</h1> | |
<% form('/posts') do |f| %> | |
<%= f.text_field :title %> | |
<%= f.text_area :body %> | |
<%= f.submit 'Create' %> | |
<% end %> |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="description" content="An object oriented blog on lotus"> | |
<title>Bloog</title> | |
</head> | |
<body> | |
<div> | |
<div class="sidebar two columns"> | |
<nav> | |
<ul> | |
<li><a href="/posts/new">New post...</a></li> | |
</ul> | |
</nav> | |
</div> | |
<h1>New Post</h1> | |
<input type="text" value=""><br /> | |
<textarea rows="20" cols="80"></textarea><br /> | |
<input type="submit" value="Create"> | |
</div> | |
</body> | |
</html> |
This file contains hidden or 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
module Bloog::Views::Posts | |
class New | |
include Bloog::View | |
def form path, &blk | |
Form.new(post, path).build(&blk) | |
end | |
end | |
end | |
class Form | |
def initialize object, path | |
@object = object | |
@action_path = path | |
end | |
def build | |
%Q{<form action="#{@action_path}" method="post">} | |
yield(self) | |
%Q{</form>} | |
end | |
def text_field attribute | |
%Q{<input type="text" value="#{@object.send(attribute)}"><br />} | |
end | |
def text_area attribute | |
%Q{<textarea rows="20" cols="80">#{@object.send(attribute)}</textarea><br />} | |
end | |
def submit text | |
%Q{<input type="submit" value="#{text}">} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment