Sha256: ecdb3102244ffd9d775f5b9b75c49ece243261b48202afa71118050f06a16279

Contents?: true

Size: 1.7 KB

Versions: 23

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require 'phlex-rails'

module Proscenium
  class Phlex < ::Phlex::HTML
    extend ActiveSupport::Autoload
    include Proscenium::CssModule

    autoload :Page
    autoload :ReactComponent
    autoload :ResolveCssModules
    autoload :ComponentConcerns

    extend ::Phlex::Rails::HelperMacros
    include ::Phlex::Rails::Helpers::JavaScriptIncludeTag
    include ::Phlex::Rails::Helpers::StyleSheetLinkTag

    define_output_helper :side_load_stylesheets
    define_output_helper :side_load_javascripts

    # Side loads the class, and its super classes that respond to `.path`. Assign the
    # `abstract_class` class variable to any abstract class, and it will not be side loaded.
    # Additionally, if the class responds to `side_load`, then that method is called.
    module Sideload
      def before_template
        klass = self.class

        if !klass.abstract_class && respond_to?(:side_load, true)
          side_load
          klass = klass.superclass
        end

        while !klass.abstract_class && klass.respond_to?(:path) && klass.path
          Proscenium::SideLoad.append klass.path
          klass = klass.superclass
        end

        super
      end
    end

    class << self
      attr_accessor :path, :abstract_class

      def inherited(child)
        unless child.path
          child.path = if caller_locations(1, 1).first.label == 'inherited'
                         Pathname.new caller_locations(2, 1).first.path
                       else
                         Pathname.new caller_locations(1, 1).first.path
                       end
        end

        child.prepend Sideload if Rails.application.config.proscenium.side_load

        super
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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