Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Rails 5 support
Browse files Browse the repository at this point in the history
The only notable difference seems to be that
`assets_environment.find_asset(pathname)` always returns
a single asset instead of an array of assets.

Does not yet include Rails 5 in the test matrix because it's alpha
  • Loading branch information
Elana Koren and Travis Grathwell committed Oct 1, 2015
1 parent d5e0d6a commit 6513121
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
8 changes: 4 additions & 4 deletions lib/jasmine/asset_expander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def expand(src_dir, src_path)

def asset_bundle
return Rails3AssetBundle.new if Jasmine::Dependencies.rails3?
return Rails4AssetBundle.new if Jasmine::Dependencies.rails4?
raise UnsupportedRailsVersion, "Jasmine only supports the asset pipeline for Rails 3 or 4"
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
Expand All @@ -38,7 +38,7 @@ def get_asset_context
end
end

class Rails4AssetBundle
class Rails4Or5AssetBundle
def assets(pathname)
context.get_original_assets(pathname)
end
Expand All @@ -51,7 +51,7 @@ def context

module GetOriginalAssetsHelper
def get_original_assets(pathname)
assets_environment.find_asset(pathname).to_a.map do |processed_asset|
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)
Expand Down
29 changes: 10 additions & 19 deletions lib/jasmine/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,29 @@ module Dependencies

class << self
def rails3?
running_rails3?
rails? && Rails.version.to_i == 3
end

def rails4?
running_rails4?
rails? && Rails.version.to_i == 4
end

def rails5?
rails? && Rails.version.to_i == 5
end

def rails?
running_rails?
defined?(Rails) && Rails.respond_to?(:version)
end

def legacy_rack?
!defined?(Rack::Server)
end

def use_asset_pipeline?
assets_pipeline_available = (rails3? || rails4?) && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets)
assets_pipeline_available = (rails3? || rails4? || rails5?) && Rails.respond_to?(:application) && Rails.application.respond_to?(:assets)
rails3_assets_enabled = rails3? && assets_pipeline_available && Rails.application.config.assets.enabled != false
assets_pipeline_available && (rails4? || rails3_assets_enabled)
end

private

def running_rails3?
running_rails? && Rails.version.to_i == 3
end

def running_rails4?
running_rails? && Rails.version.to_i == 4
end

def running_rails?
defined?(Rails) && Rails.respond_to?(:version)
assets_pipeline_available && (rails4? || rails5? || rails3_assets_enabled)
end
end
end
Expand Down

0 comments on commit 6513121

Please sign in to comment.