Sha256: e6e9f823fd314adf239fbc3d5617537fb2be460441c5fcf11373c1dc2df996cd
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 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 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pakyow-presenter-1.0.0.rc3 | lib/pakyow/presenter/component.rb |