class Pakyow::Presenter::BindingParts

@api private

Public Class Methods

new() click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 7
def initialize
  @parts = {}
end

Public Instance Methods

accept(*parts) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 38
def accept(*parts)
  return if parts.empty?
  parts = parts.map(&:to_sym)
  @parts.keep_if { |key, _| parts.include? key }
end
content(view) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 19
def content(view)
  @parts[:content].call(view.text)
end
content?() click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 15
def content?
  @parts.include?(:content)
end
define_part(name, block) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 11
def define_part(name, block)
  @parts[name] = block
end
non_content_values(view) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 27
def non_content_values(view)
  values_for_parts(@parts.reject { |name, _|
    name == :content
  }, view)
end
reject(*parts) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 33
def reject(*parts)
  parts = parts.map(&:to_sym)
  @parts.delete_if { |key, _| parts.include? key }
end
to_json(*) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 44
def to_json(*)
  @parts.to_json
end
values(view) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 23
def values(view)
  values_for_parts(@parts, view)
end

Private Instance Methods

values_for_parts(parts, view) click to toggle source
# File lib/pakyow/presenter/binding_parts.rb, line 50
def values_for_parts(parts, view)
  Hash[parts.map { |name, block|
    value = if block.arity == 0
      block.call
    else
      view.attrs[name].tap do |current_value|
        block.call(current_value)
      end
    end

    [name, value]
  }]
end