Module: Instructions::Tag
- Includes:
- Abstract
- Included in:
- ErrorMessageTag, InstructionsTag
- Defined in:
- lib/instructions/tag.rb
Instance Attribute Summary collapse
-
#formatters ⇒ Object
readonly
Returns the value of attribute formatters.
Instance Method Summary collapse
- #attribute_name ⇒ Object
- #attribute_name_formatter ⇒ Object
- #close_tag ⇒ Object
- #field_identifier ⇒ Object
- #formatted_attribute_name ⇒ Object
- #formatted_css_class ⇒ Object
- #formatted_instructions ⇒ Object
- #identifier ⇒ Object
- #initialize(method, model, model_name, instructions, formatters = {}) ⇒ Object
- #instructions ⇒ Object
- #instructions_formatter ⇒ Object
- #open_tag ⇒ Object
- #render ⇒ Object
Methods included from Abstract
Instance Attribute Details
#formatters ⇒ Object (readonly)
Returns the value of attribute formatters.
9 10 11 |
# File 'lib/instructions/tag.rb', line 9 def formatters @formatters end |
Instance Method Details
#attribute_name ⇒ Object
33 34 35 |
# File 'lib/instructions/tag.rb', line 33 def attribute_name @model.class.human_attribute_name(@method) end |
#attribute_name_formatter ⇒ Object
37 38 39 |
# File 'lib/instructions/tag.rb', line 37 def attribute_name_formatter @formatters[:attribute_name] end |
#close_tag ⇒ Object
67 68 69 |
# File 'lib/instructions/tag.rb', line 67 def close_tag "</div>" end |
#field_identifier ⇒ Object
54 55 56 |
# File 'lib/instructions/tag.rb', line 54 def field_identifier "#{@model_name}_#{@method}" end |
#formatted_attribute_name ⇒ Object
28 29 30 31 |
# File 'lib/instructions/tag.rb', line 28 def formatted_attribute_name return attribute_name_formatter.call(attribute_name) if attribute_name_formatter attribute_name end |
#formatted_css_class ⇒ Object
58 59 60 61 |
# File 'lib/instructions/tag.rb', line 58 def formatted_css_class return "#{css_class} empty" if instructions.empty? "#{css_class}" end |
#formatted_instructions ⇒ Object
41 42 43 44 |
# File 'lib/instructions/tag.rb', line 41 def formatted_instructions return instructions_formatter.call(@instructions) if instructions_formatter @instructions end |
#identifier ⇒ Object
50 51 52 |
# File 'lib/instructions/tag.rb', line 50 def identifier "#{field_identifier}_#{descriptor}" end |
#initialize(method, model, model_name, instructions, formatters = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/instructions/tag.rb', line 11 def initialize(method, model, model_name, instructions, formatters={}) @method = method @model = model @instructions = instructions @model_name = model_name @formatters = formatters end |
#instructions ⇒ Object
23 24 25 26 |
# File 'lib/instructions/tag.rb', line 23 def instructions return "#{formatted_attribute_name}" if @instructions.nil? or @instructions.empty? "#{formatted_attribute_name} #{formatted_instructions}".strip end |
#instructions_formatter ⇒ Object
46 47 48 |
# File 'lib/instructions/tag.rb', line 46 def instructions_formatter @formatters[:instructions] end |
#open_tag ⇒ Object
63 64 65 |
# File 'lib/instructions/tag.rb', line 63 def open_tag "<div id=\"#{identifier}\" data-for=\"#{field_identifier}\" class=\"#{formatted_css_class}\">" end |
#render ⇒ Object
19 20 21 |
# File 'lib/instructions/tag.rb', line 19 def render "#{open_tag}#{instructions}#{close_tag}".html_safe end |