Class: TextFieldTag

Inherits:
LiquidumTag
  • Object
show all
Defined in:
lib/scribo/liquid/tags/text_field_tag.rb

Overview

Add a text-field, either specifying everything manually or using a model object on the form

Basic usage:

{%text_field name:"name" value:"Pencil"%}

Advanced usage:

{%text_field name%}

This last usage requires a model on the form

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, args, tokens) ⇒ TextFieldTag

Returns a new instance of TextFieldTag.



16
17
18
19
# File 'lib/scribo/liquid/tags/text_field_tag.rb', line 16

def initialize(tag, args, tokens)
  super
  @field_type = 'text'
end

Instance Attribute Details

#field_typeObject

Returns the value of attribute field_type.



14
15
16
# File 'lib/scribo/liquid/tags/text_field_tag.rb', line 14

def field_type
  @field_type
end

Instance Method Details

#render(context) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/scribo/liquid/tags/text_field_tag.rb', line 21

def render(context)
  super

  result = %[<input] +
           attr_str(:name, arg(:name), input(:name, argv1)) +
           attr_str(:id, arg(:id), input(:id, argv1)) +
           attr_str(:value, arg(:value), input(:value, argv1))

  result += attrs_str(reject: %[name value id])
  result += %[ type="#{field_type}"/>]
  result
end