Class: Clot::LiquidFormFor

Inherits:
LiquidForm
  • Object
show all
Defined in:
lib/clot/form_for.rb

Overview

{% form_for post as:post url_helper:post_path method:put html:{ :class => “edit_post”, :id => “edit_post_45” } %}

Constant Summary

Constants inherited from LiquidForm

Clot::LiquidForm::Syntax

Instance Method Summary collapse

Methods inherited from LiquidForm

#get_form_footer, #render_form, #set_upload, #syntax_error

Methods included from TagHelper

#resolve_value, #split_params

Methods included from FormFilters

#concat, #drop_class_to_table_item, #form_file_item, #form_input_item, #form_item, #form_select_item, #form_text_item, #get_attribute_value, #get_error_class, #get_id_from_name, #get_selection_value, #input_to_text, #set_param, #submit_button

Methods included from LinkFilters

#delete_link, #edit_link, #gen_delete_link, #gen_delete_onclick, #index_link, #new_link, #stylesheet_link, #view_link

Methods included from UrlFilters

#delete_link, #edit_link, #get_nested_edit_url, #get_nested_url, #index_link, #object_url, #stylesheet_url, #view_link

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ LiquidFormFor

Returns a new instance of LiquidFormFor.



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/clot/form_for.rb', line 76

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @form_object = $1
    @attributes = {}
    markup.scan(Liquid::TagAttributes) do |key, value|
      @attributes[key] = value
    end
  else
    syntax_error tag_name, markup, tokens
  end
  super
end

Instance Method Details

#get_form_body(context) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/clot/form_for.rb', line 117

def get_form_body(context)
  context.stack do
    context['form_model'] = @model
    context['form_class_name'] = @class_name
    context['form_errors'] = []
    @model.errors.each do |attr, msg|
      context['form_errors'] << attr
    end if @model.respond_to? :errors
    return render_all(@nodelist, context)
  end
end

#render(context) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/clot/form_for.rb', line 90

def render(context)
  if @attributes.has_key?('url_helper')
    Protected.config = context.registers[:controller]
    @attributes['url'] = Protected.send(@attributes['url_helper'].to_sym) unless @attributes.has_key?('url_helper_params')
    @attributes['url'] = Protected.send(@attributes['url_helper'].to_sym, context[@attributes['url_helper_params']].source) if @attributes.has_key?('url_helper_params')
  end

  if @attributes.has_key?('html')
    @attributes['html'] = eval(@attributes['html'].chomp('"').reverse.chomp('"').reverse)
  end

  @attributes.except!('url_helper').except!('url_helper_params')

  item = context[@form_object].to_sym if context[@form_object].is_a?(String)
  item = context[@form_object].source if context[@form_object].is_a?(Liquid::Drop)

  context.registers[:action_view].form_for(item, @attributes.symbolize_keys) do |form|
    set_model(context)
    set_upload
    context.stack do
      context['form'] = form
      get_form_body(context).html_safe
    end

  end
end