Skip to content

Instantly share code, notes, and snippets.

@thecatwasnot
Created December 14, 2014 19:04
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 thecatwasnot/c58da1c58bd83f08dc81 to your computer and use it in GitHub Desktop.
Save thecatwasnot/c58da1c58bd83f08dc81 to your computer and use it in GitHub Desktop.
<h1>New Post</h1>
<% form('/posts') do |f| %>
<%= f.text_field :title %>
<%= f.text_area :body %>
<%= f.submit 'Create' %>
<% end %>
<!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>
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