Permalink
Browse files

Added generator for CSS. Not yet fully functional.

  • Loading branch information...
1 parent a6b66e7 commit daa4dd6613927c83b7150c4de152628dab4b8490 @topfunky committed Dec 22, 2008
View
@@ -2,11 +2,23 @@
require 'rubygems'
require 'hoe'
-require './lib/good_form.rb'
+# require './lib/good_form_builder.rb'
-Hoe.new('GoodForm', GoodForm::VERSION) do |p|
+Hoe.new('good_form_builder', "0.0.1") do |p|
# p.rubyforge_name = 'GoodFormx' # if different than lowercase project name
- # p.developer('FIX', 'FIX@example.com')
+ p.developer('Geoffrey Grosenbach', 'boss@topfunky.com')
+end
+
+desc "Generate static CSS from Sass template"
+task :build_css do
+ require 'sass'
+
+ good_form_generator_template_dir = "./generators/good_form_builder/templates/"
+ File.open("#{good_form_generator_template_dir}/good_form.sass", 'r') do |inf|
+ File.open("#{good_form_generator_template_dir}/good_form.css", 'w') do |outf|
+ outf.write Sass::Engine.new(inf.read).to_css
+ end
+ end
+
end
-# vim: syntax=Ruby
@@ -0,0 +1,15 @@
+class GoodFormBuilderGenerator < Rails::Generator::Base
+
+ def manifest
+ record do |m|
+ stylesheets_dir = File.join("public", "stylesheets")
+ sass_dir = File.join(stylesheets_dir, "sass")
+
+ m.directory stylesheets_dir
+ m.directory sass_dir
+
+ m.file "good_form.sass", File.join(sass_dir, "good_form.sass")
+ m.file "good_form.css", File.join(stylesheets_dir, "good_form.css")
+ end
+ end
+end
@@ -0,0 +1,151 @@
+* {
+ margin: 0;
+ padding: 0; }
+
+form {
+ width: 280px;
+ text-align: left; }
+ form h3 {
+ clear: both;
+ padding: 5px 0px 10px 0px;
+ font-size: 14px; }
+ form label {
+ display: block;
+ width: 270px;
+ font-size: 12px;
+ line-height: 14px;
+ padding: 0px 0px 12px 0px; }
+ form label.field {
+ clear: left;
+ float: left;
+ width: 270px;
+ margin: 0px 0px 0px 0px; }
+ form label.field input {
+ float: left;
+ width: 270px;
+ padding: 0px; }
+ form label.field-first {
+ float: left;
+ margin: 0px 10px 0px 0px;
+ width: 130px; }
+ form label.field-first input {
+ float: left;
+ width: 130px;
+ padding: 0px; }
+ form label.field-first select {
+ width: 130px;
+ float: left;
+ margin-top: 3px; }
+ form label.field-state {
+ float: left;
+ margin-right: 10px;
+ width: 50px; }
+ form label.field-state select {
+ width: 50px;
+ float: left;
+ margin-top: 3px; }
+ form label.field-zip {
+ float: left;
+ width: 70px; }
+ form label.field-zip input {
+ float: left;
+ width: 70px; }
+ form label.radiobutton {
+ clear: none;
+ margin: 0px 0px 0px 25px;
+ padding: 0px 0px 15px 0px; }
+ form label.checkbox {
+ clear: none;
+ margin: 0px 0px 0px 25px;
+ padding: 0px 0px 15px 0px; }
+ form input {
+ display: block;
+ margin-top: 3px; }
+ form input.radiobutton {
+ clear: left;
+ float: left;
+ padding: 0px;
+ margin: 0px 0px 0px 0px; }
+ form input.checkbox {
+ clear: both;
+ float: left;
+ padding: 0px;
+ margin: 0px; }
+ form select {
+ float: left;
+ display: block; }
+ form textarea {
+ margin-top: 3px; }
+
+fieldset {
+ margin: 0;
+ border: 0;
+ padding: 0;
+ text-indent: 0;
+ clear: left;
+ border: 0 solid;
+ position: relative; }
+
+legend {
+ padding: 5px 0px 10px 0px;
+ margin: 0 0 0 0;
+ font-size: 14px;
+ font-weight: bold;
+ position: relative;
+ left: -7px; }
+
+fieldset>legend {
+ left: 0; }
+
+form label.field-first {
+ clear: left; }
+form label.field-address {
+ clear: left;
+ float: left;
+ width: 270px;
+ margin: 0px 0px 0px 0px; }
+ form label.field-address input {
+ float: left;
+ width: 270px;
+ padding: 0px; }
+form label.field-city {
+ clear: left;
+ float: left;
+ margin: 0px 10px 0px 0px;
+ width: 130px; }
+ form label.field-city input {
+ float: left;
+ width: 130px;
+ padding: 0px; }
+form label.field-email {
+ clear: left;
+ float: left;
+ margin: 0px 10px 0px 0px;
+ width: 130px; }
+ form label.field-email input {
+ float: left;
+ width: 130px;
+ padding: 0px; }
+form label.field-last {
+ float: left;
+ margin: 0px 10px 0px 0px;
+ width: 130px; }
+ form label.field-last input {
+ float: left;
+ width: 130px;
+ padding: 0px; }
+ form label.field-last select {
+ width: 130px;
+ float: left;
+ margin-top: 3px; }
+form label.field-phone {
+ float: left;
+ margin: 0px 10px 0px 0px;
+ width: 130px; }
+ form label.field-phone input {
+ float: left;
+ width: 130px;
+ padding: 0px; }
+
+textarea {
+ display: block; }
File renamed without changes.
View
No changes.
View
@@ -1,3 +0,0 @@
-class GoodForm
- VERSION = '1.0.0'
-end
@@ -1,13 +1,19 @@
+require File.dirname(__FILE__) + "/form_helper_fieldset"
+
##
-# Custom form builder.
+# Good Form builder for Ruby on Rails. Implements a form as shown
+# originally by Khoi Vinh at http://www.subtraction.com/pics/0508/050822/.
+#
+# This uses the variant at http://examples.webtypes.com/goodform/.
+# CSS can be copied by using the generator that ships with this plugin.
#
-# For use with CSS from http://examples.webtypes.com/goodform/
+# All fields take a :label argument in options (or html_options
+# for collection_select). The value will be used as the label
+# content. The field name is used otherwise.
+#
+# TODO Display errors with CSS.
-class TopfunkyFormBuilder < ActionView::Helpers::FormBuilder
- # helpers = field_helpers +
- # %w{date_select datetime_select time_select} +
- # %w{collection_select select country_select time_zone_select} -
- # %w{hidden_field label fields_for} # Don't decorate these
+class GoodFormBuilder < ActionView::Helpers::FormBuilder
def text_field(field, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
@@ -32,7 +38,11 @@ def check_box(field, options={}, checked_value='1', unchecked_value='0')
super(field, options, checked_value, unchecked_value) +
label(field, label_title, :class => options[:class])
end
-
+
+ ##
+ # Unlike the other elements, the :label option should be passed in
+ # the html_options Hash.
+
def collection_select(field, collection, value_method, text_method, options={}, html_options={})
label_class = (html_options.delete(:class) || 'field')
@template.content_tag("label",

0 comments on commit daa4dd6

Please sign in to comment.