Class: Clot::LiquidForm

Inherits:
Liquid::Block
  • Object
show all
Includes:
FormFilters, LinkFilters, TagHelper, UrlFilters
Defined in:
lib/clot/form_for.rb

Direct Known Subclasses

FormTag, LiquidFormFor

Constant Summary collapse

Syntax =
/([^\s]+)\s+/

Instance Method Summary collapse

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) ⇒ LiquidForm

Returns a new instance of LiquidForm.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clot/form_for.rb', line 15

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



44
45
46
47
48
# File 'lib/clot/form_for.rb', line 44

def get_form_body(context)
  context.stack do
    render_all(@nodelist, context) * ""
  end
end


50
51
52
# File 'lib/clot/form_for.rb', line 50

def get_form_footer
  "</form>"
end

#render(context) ⇒ Object



28
29
30
31
# File 'lib/clot/form_for.rb', line 28

def render(context)
  set_variables context
  render_form context
end

#render_form(context) ⇒ Object



33
34
35
36
37
38
# File 'lib/clot/form_for.rb', line 33

def render_form(context)
  result = get_form_header(context)
  result += get_form_body(context)
  result += get_form_footer
  result
end

#set_uploadObject



54
55
56
57
58
59
60
# File 'lib/clot/form_for.rb', line 54

def set_upload
  if @attributes["uploading"] || @attributes["multipart"] == "true"
    @upload_info = ' enctype="multipart/form-data"'
  else
    @upload_info = ''
  end
end

#set_variables(context) ⇒ Object



62
63
64
65
66
67
# File 'lib/clot/form_for.rb', line 62

def set_variables(context)
  set_controller_action
  set_form_action(context)
  set_class
  set_upload
end

#syntax_errorObject

Raises:

  • (SyntaxError)


40
41
42
# File 'lib/clot/form_for.rb', line 40

def syntax_error
  raise SyntaxError.new("Syntax Error in form tag")
end