Sha256: 6fb4278c4f996d83b8d05e661cf2bd6e04bc7318fe5210aa21eb66137bd96029

Contents?: true

Size: 1.81 KB

Versions: 48

Compression:

Stored size: 1.81 KB

Contents

module Jasmine
  class AssetExpander
    def expand(src_dir, src_path)
      pathname = src_path.gsub(/^\/?assets\//, '').gsub(/\.js$/, '')

      asset_bundle.assets(pathname).flat_map { |asset|
        "/#{asset.gsub(/^\//, '')}?body=true"
      }
    end

    private

    UnsupportedRailsVersion = Class.new(StandardError)

    def asset_bundle
      return Rails3AssetBundle.new if Jasmine::Dependencies.rails3?
      return Rails4Or5AssetBundle.new if Jasmine::Dependencies.rails4? || Jasmine::Dependencies.rails5?
      raise UnsupportedRailsVersion, "Jasmine only supports the asset pipeline for Rails 3 - 5"
    end

    class Rails3AssetBundle
      def assets(pathname)
        context.asset_paths.asset_for(pathname, nil).to_a.map do |path|
          context.asset_path(path)
        end
      end

      private

      def context
        @context ||= get_asset_context
      end

      def get_asset_context
        context = ::Rails.application.assets.context_class
        context.extend(::Sprockets::Helpers::IsolatedHelper)
        context.extend(::Sprockets::Helpers::RailsHelper)
      end
    end

    class Rails4Or5AssetBundle
      def assets(pathname)
        context.get_original_assets(pathname)
      end

      private

      def context
        @context ||= ActionView::Base.new.extend(GetOriginalAssetsHelper)
      end

      module GetOriginalAssetsHelper
        def get_original_assets(pathname)
          Array(assets_environment.find_asset(pathname)).map do |processed_asset|
            case processed_asset.content_type
            when "text/css"
              path_to_stylesheet(processed_asset.logical_path, debug: true)
            when "application/javascript"
              path_to_javascript(processed_asset.logical_path, debug: true)
            end
          end
        end
      end
    end
  end
end

Version data entries

48 entries across 33 versions & 2 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/jasmine-2.99.0/lib/jasmine/asset_expander.rb