Sha256: f38f5d8b7fb04301851fbbe9916426bf03000f9e526db4982d65b4ca84e3ab72
Contents?: true
Size: 1.68 KB
Versions: 9
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true require "pakyow/support/class_state" require "pakyow/support/hookable" require "pakyow/support/makeable" require "pakyow/support/makeable/object_maker" module Pakyow module Presenter # Reusable functionality for a view component. # class Component extend Support::Makeable extend Support::ClassState class_state :__presenter_class, default: Presenter, inheritable: true class_state :inherit_values, default: false include Support::Hookable events :render attr_reader :connection def initialize(connection:, config: {}) @connection, @config = connection, config end def perform # intentionally empty end class << self def presenter(&block) @__presenter_class = Class.new(@__presenter_class) do class_eval(&block) end Support::ObjectMaker.define_object_on_target_with_constant_name( @__presenter_class, self, :Presenter ) end def parse(string) component, config_string = string.split("(") { name: component.strip.to_sym, config: parse_config(config_string) } end def parse_config(string) if string string.strip[0..-2].split(",").each_with_object({}) { |config_string_part, values| key, value = config_string_part.split(":") value = if value value.strip else true end values[key.strip.to_sym] = value } else {} end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems