Class: Cms::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Cms::FormBuilder
- Defined in:
- app/helpers/cms/form_builder.rb
Overview
Adds additional form fields to the Rails FormBuilder which can be used to create CMS forms.
Instance Method Summary collapse
-
#cms_check_box(method, options = {}) ⇒ Object
Renders a label and checkbox suitable for allow editors to update a boolean field.
- #cms_drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
-
#cms_instructions(instructions) ⇒ Object
Renders instructions for a given field below the field itself.
- #cms_tag_list(options = {}) ⇒ Object
-
#cms_template_editor(method, options = {}) ⇒ Object
Renders a template editor that allows developers to edit the view used to render a specific block.
-
#cms_text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor with the ‘type’ selector.
- #date_picker(method, options = {}) ⇒ Object
-
#drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
Renders a CMS styled JavaScript/CSS styled select box, by itself with no label or other markup besides the js.
- #tag_list(options = {}) ⇒ Object
-
#text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor without the ‘type’ selector.
Instance Method Details
#cms_check_box(method, options = {}) ⇒ Object
Renders a label and checkbox suitable for allow editors to update a boolean field.
Params:
* method - The name of the field this check_box will update.
* - Hash of values including:
- :label
- :instructions
- :default_value
- Any other standard FormBuilder.check_box that will be passed directly to the check_box method.
114 115 116 117 118 119 |
# File 'app/helpers/cms/form_builder.rb', line 114 def cms_check_box(method, ={}) add_tabindex!() set_default_value!(method, ) = .extract!(:label, :instructions, :default_value) render_cms_form_partial "check_box", :method=>method, :options => , :cms_options => end |
#cms_drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/cms/form_builder.rb', line 54 def cms_drop_down(method, choices, ={}, ={}) add_tabindex!() set_default_value!(method, ) = .extract!(:label, :instructions, :default_value) render_cms_form_partial :drop_down, :object_name => @object_name, :method => method, :choices => choices, :options => , :cms_options => , :html_options => end |
#cms_instructions(instructions) ⇒ Object
Renders instructions for a given field below the field itself. Instructions can be used to provide helpful guidance to content editors including formatting help or just explaining what a field is for.
Will not render if instructions are blank/nil.
-
instructions - The text of the instructions to show (Defaults to blank)
101 102 103 |
# File 'app/helpers/cms/form_builder.rb', line 101 def cms_instructions(instructions) render_cms_form_partial :instructions, :instructions=>instructions end |
#cms_tag_list(options = {}) ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/helpers/cms/form_builder.rb', line 64 def cms_tag_list(={}) add_tabindex!() set_default_value!(:tag_list, ) = .extract!(:label, :instructions, :default_value) render_cms_form_partial :tag_list, :options => , :cms_options => end |
#cms_template_editor(method, options = {}) ⇒ Object
Renders a template editor that allows developers to edit the view used to render a specific block. Render both a ‘Handler’ select box (erb, builder, etc) and a text_area for editing. Will not display the editor if the underlying object is marked as ‘render_inline(false)’. This allows developers to edit the render.html.erb directly to update how the model displays.
For example, Portlets will often specify a :template to allow runtime update of their view.
Options:
:default_handler - Which handler will be the default when creating new instances. (Defaults to erb)
:instructions - Instructions that will be displayed below the text area. (Blank by default)
:label - The name for the label (Defaults to humanized version of field name)
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/helpers/cms/form_builder.rb', line 134 def cms_template_editor(method, ={}) if object.class.render_inline # Set some defaults [:default_value] = @object.class.default_template set_default_value!(method, ) [:default_handler] = "erb" unless [:default_handler] = .extract!(:label, :instructions) = .extract!(:default_handler) add_tabindex!() render_cms_form_partial :template_editor, :method=>method, :dropdown_options=>, :options => , :cms_options=> end end |
#cms_text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor with the ‘type’ selector.
84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/cms/form_builder.rb', line 84 def cms_text_editor(method, = {}) add_tabindex!() set_default_value!(method, ) = .extract!(:label, :instructions, :default_value) render_cms_form_partial :text_editor, :id => ([:id] || "#{@object_name}_#{method}"), :editor_enabled => (["editorEnabled"].blank? ? true : (["editorEnabled"] == 'true' || ["editorEnabled"] == ['true'])), :object_name => @object_name, :method => method, :options => , :cms_options => end |
#date_picker(method, options = {}) ⇒ Object
28 29 30 |
# File 'app/helpers/cms/form_builder.rb', line 28 def date_picker(method, ={}) text_field(method, {:size => 10, :class => "date_picker"}.merge()) end |
#drop_down(method, choices, options = {}, html_options = {}) ⇒ Object
Renders a CMS styled JavaScript/CSS styled select box, by itself with no label or other markup besides the js.
Options:
* All standard select tag plus:
* :default_value - The default item to have selected (defaults to the value of the model)
* :width - The width for the select (defaults to 455px).
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/cms/form_builder.rb', line 14 def drop_down(method, choices, = {}, = {}) select_class = "#{@object_name}_#{method}" h_opts = add_tabindex!(.merge()) h_opts[:class] = select_class opts = () set_default_value!(method, ) = .extract!(:default_value, :width) render_cms_form_partial :fancy_drop_down, :object_name => @object_name, :method => method, :choices => choices, :options => opts, :cms_options => , :html_options => h_opts end |
#tag_list(options = {}) ⇒ Object
32 33 34 35 |
# File 'app/helpers/cms/form_builder.rb', line 32 def tag_list(={}) field_name = .delete(:name) || :tag_list text_field(field_name, {:size => 50, :class => "tag-list"}.merge()) end |
#text_editor(method, options = {}) ⇒ Object
Renders a WYWIWYG editor without the ‘type’ selector.
75 76 77 78 79 80 81 |
# File 'app/helpers/cms/form_builder.rb', line 75 def text_editor(method, = {}) @template.send( "text_editor", @object_name, method, ()) end |