Class: Mullet::HTML::IfElementRenderer

Inherits:
CommandElementRenderer show all
Defined in:
lib/mullet/html/if_element_renderer.rb

Overview

Renders an element if variable is true.

Direct Known Subclasses

UnlessElementRenderer

Constant Summary

Constants inherited from ElementRenderer

ElementRenderer::ATTRIBUTE_NAME_MISSING_ERROR, ElementRenderer::ATTRIBUTE_NAME_SEPARATOR, ElementRenderer::ATTRIBUTE_SEPARATOR, ElementRenderer::ATTRIBUTE_SYNTAX_ERROR, ElementRenderer::CONVENIENT_ATTRIBUTE_COMMANDS

Instance Attribute Summary

Attributes inherited from ElementRenderer

#remove_mode

Instance Method Summary collapse

Methods inherited from CommandElementRenderer

#has_command

Methods inherited from ElementRenderer

#add_attribute_command, #add_attribute_commands, #add_attribute_message_command, #add_attribute_message_commands, #configure_attribute_commands, #configure_attribute_message_commands, #configure_commands, #configure_content, #execute_attribute_commands, #has_command, #has_dynamic_content, #render_content, #render_end_tag, #render_start_tag, #should_render_content, #should_render_tag

Methods included from Container

#add_child, #children, #clear_children, #delete_child, #render_children

Constructor Details

#initialize(element, variable_name) ⇒ IfElementRenderer

Constructor



15
16
17
18
# File 'lib/mullet/html/if_element_renderer.rb', line 15

def initialize(element, variable_name)
  super(element)
  @variable_name = variable_name.to_sym()
end

Instance Method Details

#render(render_context) ⇒ Object



39
40
41
42
43
# File 'lib/mullet/html/if_element_renderer.rb', line 39

def render(render_context)
  if should_render_element(render_context)
    super_render(render_context)
  end
end

#should_render_element(render_context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mullet/html/if_element_renderer.rb', line 20

def should_render_element(render_context)
  value = render_context.get_variable_value(@variable_name)
  if value == Scope::NOT_FOUND || value == nil
    return false
  end

  if value.is_a?(FalseClass) || value.is_a?(TrueClass)
    return value
  end

  if value.respond_to?(:empty?)
    return !value.empty?()
  end

  return true
end

#super_renderObject



37
# File 'lib/mullet/html/if_element_renderer.rb', line 37

alias :super_render :render