Sha256: 729b8fac54c42a4cb36bdc198339e6e6f462015b952bff815bff202bae587a58

Contents?: true

Size: 752 Bytes

Versions: 8

Compression:

Stored size: 752 Bytes

Contents

# frozen_string_literal: true

module Phlexible
  #
  # Create an alias at `element` to the `view_class`.
  #
  # So instead of:
  #
  #   class MyView < Phlex::HTML
  #     def template
  #       div do
  #         render My::Awesome::Component.new
  #       end
  #     end
  #   end
  #
  # You can instead do:
  #
  #   class MyView < Phlex::HTML
  #     extend Phlexible::AliasView
  #
  #     alias_view :awesome, -> { My::Awesome::Component }
  #
  #     def template
  #       div do
  #         awesome
  #       end
  #     end
  #   end
  #
  module AliasView
    def alias_view(element, view_class)
      define_method element do |*args, **kwargs, &blk|
        render view_class.call.new(*args, **kwargs), &blk
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
phlexible-1.0.0 lib/phlexible/alias_view.rb
phlexible-1.0.0.beta.1 lib/phlexible/alias_view.rb
phlexible-0.7.0 lib/phlexible/alias_view.rb
phlexible-0.6.2 lib/phlexible/alias_view.rb
phlexible-0.6.1 lib/phlexible/alias_view.rb
phlexible-0.6.0 lib/phlexible/alias_view.rb
phlexible-0.5.0 lib/phlexible/alias_view.rb
phlexible-0.4.2 lib/phlexible/alias_view.rb