Skip to content

Commit

Permalink
Generate example HTML. Somewhat of a hack, but there may be an easier…
Browse files Browse the repository at this point in the history
… way to render a template outside of Rails.
  • Loading branch information
topfunky committed Dec 27, 2008
1 parent e1b15e3 commit e89e71a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 9 deletions.
53 changes: 44 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -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>
32 changes: 32 additions & 0 deletions examples/index.html.haml
Original file line number Diff line number Diff line change
@@ -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.