Class: Hanami::Helpers::FormHelper::HtmlNode Private

Inherits:
HtmlHelper::HtmlNode show all
Defined in:
lib/hanami/helpers/form_helper/html_node.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

HTML form node

See Also:

Since:

  • 0.2.0

Constant Summary

Constants inherited from HtmlHelper::EmptyHtmlNode

HtmlHelper::EmptyHtmlNode::ATTRIBUTES_SEPARATOR, HtmlHelper::EmptyHtmlNode::BOOLEAN_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from HtmlHelper::HtmlNode

#to_s

Methods inherited from HtmlHelper::EmptyHtmlNode

#attribute, #attributes, #boolean_attribute, #boolean_attribute?, #to_s

Constructor Details

#initialize(name, content, attributes, options) ⇒ Hanami::Helpers::FormHelper::HtmlNode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new HTML form node

Parameters:

  • name (Symbol, String)

    the name of the tag

  • content (String, Proc, Hanami::Helpers::HtmlHelper::FormBuilder, NilClass)

    the optional content

  • attributes (Hash, NilClass)

    the optional tag attributes

  • options (Hash)

    a set of data

Since:

  • 0.2.0


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hanami/helpers/form_helper/html_node.rb', line 24

def initialize(name, content, attributes, options)
  super

  @verb       = options.fetch(:verb,       nil)
  @csrf_token = options.fetch(:csrf_token, nil)

  @builder = FormBuilder.new(
    options.fetch(:name),
    options.fetch(:values)
  )
end

Instance Method Details

#_csrf_protection!Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Inject a hidden field for CSRF Protection token

Since:

  • 0.2.0


69
70
71
72
73
74
75
76
# File 'lib/hanami/helpers/form_helper/html_node.rb', line 69

def _csrf_protection!
  return if @csrf_token.nil?

  csrf_token = @csrf_token
  @builder.resolve do
    input(type: :hidden, name: FormHelper::CSRF_TOKEN, value: csrf_token)
  end
end

#_method_override!Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Inject a hidden field to make Method Override possible

Since:

  • 0.2.0


56
57
58
59
60
61
62
63
# File 'lib/hanami/helpers/form_helper/html_node.rb', line 56

def _method_override!
  return if @verb.nil?

  verb = @verb
  @builder.resolve do
    input(type: :hidden, name: :_method, value: verb)
  end
end

#contentString (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Resolve the (nested) content

Returns:

  • (String)

    the content

See Also:

Since:

  • 0.2.0


46
47
48
49
50
# File 'lib/hanami/helpers/form_helper/html_node.rb', line 46

def content
  _method_override!
  _csrf_protection!
  super
end