# frozen_string_literal: true require "pakyow/support/extension" module Pakyow module Presenter class Renderer module Behavior # @api private module InsertPrototypeBar extend Support::Extension apply_extension do attach do |presenter| if Pakyow.env?(:prototype) presenter.render node: -> { if body = object.find_first_significant_node(:body) View.from_object(body) end } do view.object.append_html <<~HTML
#{InsertPrototypeBar.ui_modes_html(view, __modes || [:default])}
Prototype
HTML end end end expose do |connection| if Pakyow.env?(:prototype) connection.set(:__modes, connection.params[:modes]) end end end # @api private def self.ui_modes_html(view, current_modes) current_modes = current_modes.map(&:to_sym) modes = view.object.each_significant_node(:mode).map { |node| node.label(:mode) } modes.unshift( (view.info(:mode) || :default).to_sym ).uniq! options = modes.map { |each_mode| selected = if current_modes.include?(each_mode) " selected=\"selected\"" else "" end nice_mode = Support.inflector.humanize(Support.inflector.underscore(each_mode)) "" }.join <<~HTML UI Mode: HTML end end end end end end