Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit dcf8bebb449d871eab8d8eba38dbec5e85bf7173 Justin French committed Apr 7, 2008
Showing with 712 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +144 −0 README
  3. +22 −0 Rakefile
  4. +37 −0 docs/dsl.html
  5. +98 −0 docs/output.html
  6. +2 −0 init.rb
  7. +1 −0 install.rb
  8. +381 −0 lib/justin_french/formtastic.rb
  9. +6 −0 tasks/formtastic_tasks.rake
  10. 0 test/formtastic_test.rb
  11. +1 −0 uninstall.rb
@@ -0,0 +1,20 @@
+Copyright (c) 2007 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
144 README
@@ -0,0 +1,144 @@
+=Formtastic Sneaky Preview
+
+Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.
+
+One day, I finally had enough. Hacked together forms were easy, but awesome forms with decent semantics, rich mark-up and plenty of CSS hooks were incredibly painful. I was discouraged from doing things properly because it was do much mark-up and code to write.
+
+So I opened up a text file, and wrote a DSL for how I'd like to author forms:
+
+ <% semantic_form_for @article do |form| %>
+
+ <%= form.error_messages %>
+
+ <% form.input_field_set "Basic" do %>
+ <%= form.input :title %>
+ <%= form.input :body, :rows => 20 %>
+ <%= form.input :section_id, :include_blank => true %>
+ <%= form.input :publication_state_id, :as => :radio %>
+ <%= form.input :author_id, :as => :select %>
+ <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
+ <% end %>
+
+ <% form.input_field_set "Extra" do %>
+ <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
+ <%= form.input :extract, :required => false, :rows => 5 %>
+ <%= form.input :description, :required => false, :rows => 5 %>
+ <%= form.input :url_title, :required => false %>
+ <% end %>
+
+ <% form.button_field_set do %>
+ <%= form.cancel_button -%>
+ <%= form.commit_button -%>
+ <% end %>
+
+ <% end %>
+
+I also wrote the accompanying HTML output I expected, favoring something very similar to the fieldsets, lists and other semantic elements Aaron Gustafson presented in <i>Learning to Love Forms</i> <http://www.slideshare.net/AaronGustafson/learning-to-love-forms-web-directions-south-07>, and then hacked together enough Ruby to prove it could be done.
+
+
+==Configuration
+
+If you wish, put something like this in config/initializers/formtastic_config.rb:
+
+ JustinFrench::Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
+ JustinFrench::Formtastic::SemanticFormBuilder.required_string = "(required)"
+ JustinFrench::Formtastic::SemanticFormBuilder.optional_string = "(optional)"
+
+
+==Guiding Principals
+
+* great forms are at the heart of most web applications
+* semantically rich (and far more accessible) HTML forms really are possible with the use of appropriate elements like fieldsets & lists
+* sometimes more mark-up is better
+* stylesheet authors have more options and more control if plenty of structural mark-up, class names and element ids are provided
+* it should be easy to write a great form rather than a crappy form
+* I'm sick of re-inventing the wheel every time I need a form
+* applications with great data modelling and a RESTful architecture are my main consideration
+* there's no such thing as a silver bullet and I'll still have to hard-code some things I do
+* best practices and common patterns have to start somewhere
+
+
+
+==Status
+
+THIS IS DEFINITELY NOT PRODUCTION-READY. THINGS ARE GOING TO CHANGE A LOT.
+
+It's incredibly opinionated, incomplete, a work in progress, messy around the edges, messy in the middle too, tightly coupled to the database, tightly coupled to "my way" of doing things and also incredibly lacking in unit tests so far, but I hope you try it and offer some suggestions and improvements any way.
+
+* Justin's Weblog: http://justinfrench.com
+* Justin's email: justin at indent dot com dot au
+* Documentation: http://formtastic.justinfrench.com
+* SVN repository: http://indent.svnrepository.com/svn/plugins/formtastic/trunk
+
+
+==Roadmap
+
+* There's plenty of TODOs in the code
+* get the basic form_for implementation complete, proven and *well tested* (did I mention how laborious testing form builders is?)
+* provide generic, reusable, stylesheets that prove this stuff works
+* go back and ensure it works for remote_form_for, etc
+* probably do a shortcut like <%= form.inputs :name, :login, :email, :bio %> for those that want the form with zero configuration
+
+
+==Installation
+
+You know the drill:
+
+ cd path/to/your/app
+ ./script/plugin install http://indent.svnrepository.com/svn/plugins/formtastic/trunk
+
+
+==Usage
+
+The smallest example:
+
+ <% semantic_form_for @user do |form| %>
+ <% form.input_field_set do %>
+ <%= form.input :name %>
+ <%= form.input :email %>
+ <% end %>
+ <% end %>
+
+With an output something like:
+
+ <form id="new-article-form" action="#" method="post">
+ <fieldset>
+ <legend><span>Create a new User</span></legend>
+ <fieldset class="inputs">
+ <ol>
+ <li id="user_name_input" class="required string">
+ <label for="user_name">Name <abbr title="required">*</abbr></label>
+ <input type="text" id="user_name" name="user[name]" size="50" />
+ </li>
+ <li id="user_email_input" class="required string">
+ <label for="user_email">Email <abbr title="required">*</abbr></label>
+ <input type="text" id="user_email" name="user[email]" size="50" />
+ </li>
+ </ol>
+ </fieldset>
+ </fieldset>
+ </form>
+
+
+==What about Stylesheets?
+
+It's no where near complete, but there is a sample CSS file here:
+http://indent.svnrepository.com/svn/plugins/formtastic/sample/public/stylesheets/formtastic.css
+
+The plan is that a CSS file similar to this will be generated or otherwise made available to your app to give you basic vertical (labels above inputs) and horizontal (labels to the left of inputs), and then if needed, you would write new styles on top to customise the presentation to suit you.
+
+
+==Compatibility
+
+I'm only testing Formtastic with the latest Rails stable release (2.0.2 at this time).
+
+
+==But it doesn't do that thing I really need!
+
+Oh noes! It might not ever do it either. We'll see. This is not a silver bullet. I want to make the usual stuff easy, and the unusual stuff possible. That might mean that some of the inputs on your form still have to be hard-coded, but some is better than all, right?
+
+I really hope the plugin will soon be clean and extensible enough to invite others to contribute more complex input types (calendars, etc) to the core.
+
+
+
+Copyright (c) 2007 Justin French, released under the MIT license.
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the formtastic plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the formtastic plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Formtastic'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="Content-Language" content="en-us" />
+ <title>untitled</title>
+ <meta name="Copyright" content="(c) 2008 Copyright Justin French" />
+</head>
+
+<body>
+
+ <% semantic_form_for @article do |form| %>
+
+ <%= form.error_messages -%>
+
+ <% form.input_field_set do %>
+ <%= form.input :title %>
+ <%= form.input :body, :rows => 20 %>
+ <%= form.input :extract, :required => false, :rows => 5 %>
+ <%= form.input :description, :required => false, :rows => 5 %>
+ <%= form.input :keywords, :required => false, :hint => "Example: ruby, rails, forms" %>
+ <%= form.input :section_id, :include_blank => true %>
+ <%= form.input :publication_state_id, :as => :radio %>
+ <%= form.input :url_title, :required => false %>
+ <%= form.input :author_id %>
+ <%= form.input :allow_comments, :label => "Allow commenting on this article" %>
+ <% end %>
+
+ <% form.button_field_set do %>
+ <%= form.commit_button -%>
+ <% end %>
+
+ <% end %>
+
+</body>
+</html>
+
@@ -0,0 +1,98 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <meta http-equiv="Content-Language" content="en-us" />
+ <title>untitled</title>
+ <meta name="Copyright" content="(c) 2008 Copyright Justin French" />
+</head>
+
+<body>
+
+
+ <form id="new-article-form" action="#" method="post">
+ <fieldset>
+
+ <legend><span>Create a new Article</span></legend>
+
+ <div id="errors">
+ <p>We encountered <strong>2 errors</strong> while trying to process this form:</p>
+ <ol>
+ <li><a href="#article_title_input">title</a> must be provided</li>
+ <li><a href="#article_section_id_input">section</a> must be provided</li>
+ </ol>
+ </div>
+
+ <fieldset class="inputs">
+ <ol>
+ <li id="article_title_input" class="required string error">
+ <label for="article_title">Title</label>
+ <input type="text" id="article_title" name="article[title]" size="50" />
+ <p class="error"><strong>title must be provided</strong></p>
+ </li>
+
+ <li id="article_body_input" class="required text">
+ <label for="article_body">Body</label>
+ <textarea id="article_body" name="article[body]" rows="20" cols="50"></textarea>
+ </li>
+
+ <li id="article_extract_input" class="optional text">
+ <label for="article_extract">Extract</label>
+ <textarea id="article_extract" name="article[extract]" rows="5" cols="50"></textarea>
+ <p class="hint">An interesting passage or quote extracted from the article.</p>
+ </li>
+
+ <li id="article_keywords_input" class="optional string">
+ <label for="article_keywords">Keywords</label>
+ <input type="text" id="article_keywords" name="article[keywords]" size="50" />
+ <p class="hint">ruby, rails, forms, internets, remarkability</p>
+ </li>
+
+ <li id="article_section_id_input" class="required select error">
+ <label for="article_section_id">Section</lable>
+ <select id="article_section_id" name="article[section_id]">
+ <option value=""></option>
+ <option value="1">Blog</option>
+ <option value="2">Projects</option>
+ </select>
+ <p class="error"><strong>section must be provided</strong></p>
+ </li>
+
+ <li id="article_publication_state_id_input" class="required radio">
+ <fieldset>
+ <legend><span>Publication State</span></legend>
+ <ol>
+ <li>
+ <label><input type="radio" id="article_publication_state_id_1" name="article[publication_state_id]" value="1" /> draft (hidden)</label>
+ </li>
+ <li>
+ <label><input type="radio" id="article_publication_state_id_2" name="article[publication_state_id]" value="2" checked="checked" /> ready for publication (hidden)</label>
+ </li>
+ <li>
+ <label><input type="radio" id="article_publication_state_id_3" name="article[publication_state_id]" value="3" checked="checked" /> published (visible)</label>
+ </li>
+ </ol>
+ </fieldset>
+ </li>
+
+ <li id="article_allow_comments_input" class="required checkbox">
+ <input type="hidden" id="article_allow_comments_0" name="article[allow_comments]" value="0" />
+ <label><input type="checkbox" id="article_allow_comments_1" name="article[allow_comments]" value="1" /> Allow commenting on this article</label>
+ </li>
+ </ol>
+ </fieldset>
+
+ <fieldset class="buttons">
+ <ol>
+ <li class="primary">
+ <input type="submit" name="commit" value="Create new Article" />
+ </li>
+ </ol>
+ </fieldset>
+
+ </fieldset>
+ </form>
+
+</body>
+</html>
+
@@ -0,0 +1,2 @@
+require File.join(File.dirname(__FILE__), 'lib', 'justin_french', 'formtastic')
+ActionView::Base.send :include, JustinFrench::Formtastic::SemanticFormHelper
@@ -0,0 +1 @@
+puts IO.read(File.join(File.dirname(__FILE__), 'README'))
Oops, something went wrong.

0 comments on commit dcf8beb

Please sign in to comment.