Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile aliased index assets. #85

Merged
merged 2 commits into from Aug 10, 2015
Merged

Conversation

Andreis13
Copy link
Contributor

The purpose ot this code is to give the possibility to compile the alias variant of an 'index' asset.
Suppose we have a file something/index.js. Sprockets can yield this file in two ways at the moment:

assets['something/index.js'].logical_path == 'something/index.js'
assets['something.js'].logical_path == 'something/index.js'

The thing is that when we precompile our asset we get only the 'index' version of it, regardless of how we list it in the manifest. This is because the location of the compiled file is derived from the logical path of the asset.

So, what this PR introduces is the ability do get a desired logical path depending on the way we request the asset:

assets['something/index.js'].logical_path == 'something/index.js'
assets['something.js'].logical_path == 'something.js'

This gives us the possibility to compile both versions, depending on our needs.

@@ -165,7 +167,9 @@ def resolve_index_under_path(load_path, logical_name, mime_exts)
if directory?(dirname)
candidates = find_matching_path_for_extensions(dirname, "index", mime_exts)
end
return candidates, deps
return candidates.map { |c|
{ filename: c[0], type: c[1], index_alias: c[0].sub(/\/index/, '') }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case were a string like assets/index/foo.js end up in c[0]? I think we can use gsub here and also use something like /\/index.\w{2,4}$/.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll write a test for that.

rafaelfranca added a commit that referenced this pull request Aug 10, 2015
Compile aliased index assets.
@rafaelfranca rafaelfranca merged commit 3075f9d into rails:master Aug 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants