Class: Sinicum::Jcr::TypeTranslators::ComponentTranslator

Inherits:
Object
  • Object
show all
Includes:
TranslatorBase
Defined in:
lib/sinicum/jcr/type_translators/component_translator.rb

Overview

Public: Identifies a node as a mgnl:page or mgnl:component and finds the class based on the node’s template information.

Constant Summary collapse

PAGE_TYPE =
"mgnl:page"
COMPONENT_TYPE =
"mgnl:component"

Constants included from TranslatorBase

TranslatorBase::META_NODE, TranslatorBase::MGNL_TEMPLATE, TranslatorBase::NODES, TranslatorBase::PRIMARY_TYPE, TranslatorBase::PROPERTIES, TranslatorBase::WORKSPACE

Class Method Summary collapse

Class Method Details

.initialize_node(json) ⇒ Object



12
13
14
15
16
17
# File 'lib/sinicum/jcr/type_translators/component_translator.rb', line 12

def self.initialize_node(json)
  if valid_json?(json) &&
      (jcr_primary_type(json) == PAGE_TYPE || jcr_primary_type(json) == COMPONENT_TYPE)
    instance_from_template_name(json)
  end
end

.instance_from_template_name(json) ⇒ Object



19
20
21
22
23
24
# File 'lib/sinicum/jcr/type_translators/component_translator.rb', line 19

def self.instance_from_template_name(json)
  class_name = split_template_parts(json).join("/").classify
  class_name.constantize.new(json_response: json)
rescue NameError
  nil
end