Skip to content
Browse files

Generate example HTML. Somewhat of a hack, but there may be an easier…

… way to render a template outside of Rails.
  • Loading branch information...
1 parent e1b15e3 commit e89e71ac68c44a34a7bfeabbfcf9823ef10f24e9 @topfunky committed Dec 26, 2008
Showing with 107 additions and 9 deletions.
  1. +44 −9 Rakefile
  2. +31 −0 examples/index.html
  3. +32 −0 examples/index.html.haml
View
53 Rakefile
@@ -8,16 +8,51 @@ Hoe.new('good_form_builder', "0.0.1") do |p|
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
+namespace :build do
+
+ desc "Generate static CSS from Sass template"
+ task :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
-end
+ desc "Generate HTML example"
+ task :html do
+ require 'active_support'
+ require 'action_view'
+ require 'action_controller'
+ require './lib/good_form_builder'
+
+ include ActionView::Helpers
+ include ActionController::PolymorphicRoutes
+
+ ###
+ # HACK Stub methods for rendering
+ class ModelStub
+ def title; ""; end
+ def author; ""; end
+ def department; ""; end
+ end
+ def polymorphic_path(options); '/'; end
+ def protect_against_forgery?; false; end
+ $buffer_string = ''
+ def output_buffer; $buffer_string; end
+ def output_buffer=(buf); $buffer_string = buf; end
+ ###
+
+ require 'haml'
+ File.open("examples/index.html.haml", 'r') do |inf|
+ File.open("examples/index.html", 'w') do |outf|
+ outf.write Haml::Engine.new(inf.read).to_html
+ end
+ end
+ end
+
+end
View
31 examples/index.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title>
+ Good Form Example
+ </title>
+ <link href='../generators/good_form_builder/templates/good_form.css' media='screen' rel='stylesheet' type='text/css' />
+ <style>
+ body { font-family: sans-serif; margin: 2em; }
+ h1 { margin-bottom: 0.5em; }
+ </style>
+ </head>
+ <body>
+ <h1>
+ Good Form Example
+ </h1>
+ <form>
+ <fieldset>
+ <legend>
+ Your Info, Please
+ </legend>
+ <label class="field" for="model_stub_title">Title<input id="model_stub_title" name="model_stub[title]" size="30" type="text" value="" /></label>
+ <label class="field-first" for="model_stub_author">Author<input id="model_stub_author" name="model_stub[author]" size="30" type="text" value="" /></label>
+ <label class="field-last" for="model_stub_department">Department<input id="model_stub_department" name="model_stub[department]" size="30" type="text" value="" /></label>
+ </fieldset>
+ <fieldset>
+ <input id="model_stub_submit" name="commit" type="submit" value="Save" />
+ </fieldset>
+ </form>
+ </body>
+</html>
View
32 examples/index.html.haml
@@ -0,0 +1,32 @@
+!!! Strict
+%html
+ %head
+ %title
+ Good Form Example
+
+ %link{:href => "../generators/good_form_builder/templates/good_form.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/
+
+ %style
+ body { font-family: sans-serif; margin: 2em; }
+ h1 { margin-bottom: 0.5em; }
+
+ %body
+
+ %h1
+ Good Form Example
+
+ -# HACK Use Haml form since output_buffer isn't working
+ %form
+ -form_for(ModelStub.new, :builder => GoodFormBuilder) do |f|
+ %fieldset
+ -# TODO Get output_buffer and concat working so fieldset helper can be used.
+ %legend
+ Your Info, Please
+
+ =f.text_field 'title'
+
+ =f.text_field 'author', :label => "Author", :class => "field-first"
+ =f.text_field 'department', :class => "field-last"
+
+ %fieldset
+ =f.submit "Save"

0 comments on commit e89e71a

Please sign in to comment.
Something went wrong with that request. Please try again.