Sha256: c37ce3ce20aa880648a2c1d7fe817ce36590c6170fb64082280ba42fca74195d

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

module Pakyow
  module Presenter
    class Renderer
      module Behavior
        # @api private
        module PlaceInMode
          extend Support::Extension

          apply_extension do
            build do |view, modes:|
              unless Pakyow.env?(:prototype)
                PlaceInMode.perform(view, modes)
              end
            end

            attach do |presenter|
              if Pakyow.env?(:prototype)
                presenter.render node: -> {
                  object.find_significant_nodes(:mode, descend: true).map { |node|
                    View.from_object(node)
                  }
                } do
                  PlaceInMode.perform(view, __modes)
                end
              end
            end

            expose do |connection|
              if Pakyow.env?(:prototype)
                connection.set(:__modes, connection.params[:modes] || [:default])
              end
            end
          end

          # @api private
          def self.perform(view, modes)
            if modes.length == 1 && modes.first.to_sym == :default
              modes = view.info(:modes) || modes
            end

            modes.map!(&:to_sym)

            if view.object.is_a?(StringDoc::Node) && view.object.significant?(:mode) && !modes.include?(view.object.label(:mode))
              view.remove
            else
              view.object.each_significant_node(:mode, descend: true).select { |node|
                !modes.include?(node.label(:mode))
              }.each(&:remove)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pakyow-presenter-1.0.6 lib/pakyow/presenter/renderer/behavior/place_in_mode.rb
pakyow-presenter-1.0.5 lib/pakyow/presenter/renderer/behavior/place_in_mode.rb
pakyow-presenter-1.0.4 lib/pakyow/presenter/renderer/behavior/place_in_mode.rb
pakyow-presenter-1.0.3 lib/pakyow/presenter/renderer/behavior/place_in_mode.rb
pakyow-presenter-1.0.2 lib/pakyow/presenter/renderer/behavior/place_in_mode.rb