From 2a12a2dd5177f030f510147c98705bd71306f5ed Mon Sep 17 00:00:00 2001 From: Jonathan Linowes Date: Wed, 17 Mar 2010 00:56:50 -0400 Subject: [PATCH] added :render options to form.input and .inputs for ErbRenderer --- RENDERER.textile | 24 +++++++++++++++++++----- app/views/formtastic/_chronos.html.erb | 2 +- app/views/formtastic/_fieldset.html.erb | 2 +- app/views/formtastic/_items.html.erb | 2 +- lib/formtastic.rb | 7 ++++--- lib/formtastic/renderers/erb_renderer.rb | 14 +++++++++----- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/RENDERER.textile b/RENDERER.textile index c424a7b02..18a3b7b04 100644 --- a/RENDERER.textile +++ b/RENDERER.textile @@ -12,8 +12,8 @@ h2. Renderer API input hash may include keys :method => symbol - :as => the input type (eg :string, :textarea, etc) - :options => original set of options + :as => the input type (eg :string, :text, etc) + :options => original options :label => string with html label tag :hint => hints string (pre-rendered) :errors => actual errors on the method @@ -47,6 +47,7 @@ I am also leaving how Formtastic renders _required_ labels (with attr tag). If y
     render_field_set( fieldset )
     
+      :options        => original options
       :legend         => string that should go into the legend
       :contents       => string or array of html tag strings that make the content of the field set
       :wrapper        => hash of html attributes for the fieldset 
@@ -77,19 +78,32 @@ The ERB renderer renders an ERB partial for each input. There are 4 built-in par
   _fieldset.html.erb          field set wrapper
 
-You can create a partial for each and any specific input (the :as value), such as "_textarea.html.erb". If not found, it then looks for a partial for the input category ("chronos" for date and time selects; "items" for radio and check boxes' and "input" for all others). +You can create a partial for each and any specific input (the :as value), such as "_text.html.erb" for a text area. If not found, it then looks for a partial for the input category ("chronos" for date and time selects; "items" for radio and check boxes' and "input" for all others). + +The renderer looks for partials in the current controller's view directory (eg app/views/foos/_text.html.erb), then in a Formatastic view directory (app/views/formtastic/_text.html.erb), and then in the plug-in's directory. + +Using the ERB renderer, form.input takes the following new options: + +
+  :partial     => "partial"    name of partial to use (overrides the defaults)
+
+ +Similarly, , form.inputs take the following new options: + +
+  :partial     => "partial"    name of partial to use (overrides the default "fieldset")
+
-The renderer looks for partials in the current controller's view directory (eg app/views/foos/_textarea.html.erb), then in a Formatastic view directory (app/views/formtastic/_textarea.html.erb), and then in the plug-in's directory. h3. InspectorRenderer Dumps the arguments to the renderer api (in yaml format). Useful for debugging. + h2. To Do * write rspecs for renderers * add partial layouts -* option to specify partial name in the DSL * option to specify inline template string in the DSL * option to pass through arbitrary options to the renderer * add mustache renderer diff --git a/app/views/formtastic/_chronos.html.erb b/app/views/formtastic/_chronos.html.erb index 3a2bd339d..52b943c5e 100644 --- a/app/views/formtastic/_chronos.html.erb +++ b/app/views/formtastic/_chronos.html.erb @@ -5,7 +5,7 @@
    <% chronos.each do |item| %> -
  1. > +
  2. > <%= item[:label] -%> <%= item[:input] -%>
  3. diff --git a/app/views/formtastic/_fieldset.html.erb b/app/views/formtastic/_fieldset.html.erb index c66d389ec..706d71e31 100644 --- a/app/views/formtastic/_fieldset.html.erb +++ b/app/views/formtastic/_fieldset.html.erb @@ -1,4 +1,4 @@ -
    > +
    > <% unless legend.blank? -%> <%= legend %> diff --git a/app/views/formtastic/_items.html.erb b/app/views/formtastic/_items.html.erb index 20f3cf6bb..da765e31b 100644 --- a/app/views/formtastic/_items.html.erb +++ b/app/views/formtastic/_items.html.erb @@ -5,7 +5,7 @@
      <% items.each do |item| -%> -
    1. > +
    2. >