Sha256: cf2b8a50696dcd6965e5ce48eebe89a6ed7bb0398aefeec2827491e672dd4139

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'hs/loaders/initializers/code_initializers'
require 'hs/loaders/initializers/list_initializers'
require 'hs/loaders/initializers/other_initializers'
require 'hs/loaders/initializers/table_initializers'
require 'hs/loaders/initializers/text_initializers'

module HS
  module ElementLoader
    include HS::CodeInitializers
    include HS::ListInitializers
    include HS::OtherInitializers
    include HS::TableInitializers
    include HS::TextInitializers

    def load_element(data)
      name = data[:_name]
      element = initialize_element(name, data)
      children = load_elements(data[:_children])
      children.each { |child| element.children << child }

      element
    end

    def load_elements(data)
      return [] unless data
      data.map { |child_data| load_element(child_data) }
    end

    private

    def get_params(data, names = %i[class_name style])
      names.map do |name|
        data[name] ? [name, data[name]] : nil
      end.compact.to_h
    end

    def initialize_element(name, data)
      send("initialize_#{name}", data)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hs-cli-0.3.3 lib/hs/loaders/element_loader.rb
hs-cli-0.3.2 lib/hs/loaders/element_loader.rb
hs-cli-0.3.1 lib/hs/loaders/element_loader.rb