Sha256: 71bb484d5cd43f82fecbc840bcd3f2929995f209a4840842457981da95d01b8f

Contents?: true

Size: 1.88 KB

Versions: 19

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

class Proscenium::SideLoad
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  module Monkey
    module TemplateRenderer
      private

      def render_template(view, template, layout_name, locals)
        layout = find_layout(layout_name, locals.keys, [formats.first])
        renderable = template.instance_variable_get(:@renderable)

        if Object.const_defined?(:ViewComponent) &&
           template.is_a?(ActionView::Template::Renderable) &&
           renderable.class < ::ViewComponent::Base && renderable.class.format == :html
          # Side load controller rendered ViewComponent
          Proscenium::SideLoad.append "app/views/#{layout.virtual_path}" if layout
          Proscenium::SideLoad.append "app/views/#{renderable.virtual_path}"
        elsif template.respond_to?(:virtual_path) &&
              template.respond_to?(:type) && template.type == :html
          # Side load regular view template.
          Proscenium::SideLoad.append "app/views/#{layout.virtual_path}" if layout

          # Try side loading the variant template
          if template.respond_to?(:variant) && template.variant
            Proscenium::SideLoad.append "app/views/#{template.virtual_path}+#{template.variant}"
          end

          # The variant template may not exist (above), so we try the regular non-variant path.
          Proscenium::SideLoad.append "app/views/#{template.virtual_path}"
        end

        super
      end
    end

    module PartialRenderer
      private

      def build_rendered_template(content, template)
        path = Rails.root.join('app', 'views', template.virtual_path)
        cssm = Proscenium::CssModule::Resolver.new(path)
        super cssm.compile_class_names(content), template
      end
    end
  end
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
proscenium-0.9.1-x86_64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.9.1-aarch64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.9.1-arm64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.9.1-x86_64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.9.0-x86_64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.9.0-aarch64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.9.0-arm64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.9.0-x86_64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.8.2-x86_64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.8.2-aarch64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.8.2-arm64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.8.2-x86_64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.8.0-aarch64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.8.0-arm64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.8.0-x86_64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.7.0-x86_64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.7.0-aarch64-linux lib/proscenium/side_load/monkey.rb
proscenium-0.7.0-arm64-darwin lib/proscenium/side_load/monkey.rb
proscenium-0.7.0-x86_64-darwin lib/proscenium/side_load/monkey.rb