Skip to content
This repository

Extension is always appended to assets, config.assets.enabled changes behaviour #6310

Closed
Vanuan opened this Issue May 14, 2012 · 10 comments

5 participants

John Yani Carlos Antonio da Silva Thillai Arasu Vijay Dev Sergey Nartimov
John Yani
Vanuan commented May 14, 2012

Rails version: 3.2.3

As documented here: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper/StylesheetTagHelpers.html#method-i-stylesheet_link_tag
extension should not be appended if there is already one.
But when I create an empty rails app, add the asset file.ext.css to the app/assets/stylesheets folder and include it with <%= stylesheet_link_tag "file.ext", :media => "all" %>, css extension gets appended.

With config.assets.enabled = false it works as documented, i.e. css is not appended.

Probably this is the cause: #3715

So either the documentation should be changed or that patch should be reverted.
And the behaviour should not depend on config.assets.enabled flag.

Thillai Arasu

@vijaydev whether it needs a doc change or not ?

Vijay Dev
Collaborator

file.ext is the filename as far the helper method is concerned. cc @guilleiguaran @lest

John Yani
Vanuan commented May 16, 2012

So why is it expanded to file.ext.css?

Vijay Dev
Collaborator

I meant 'file.ext' is the filename without the extension. So it adds one.

John Yani
Vanuan commented May 16, 2012

So the rails's definition of extension is different from what intuition says?

If you don’t specify an extension, .css will be appended automatically.

What is an extension then? Only .css?

Vijay Dev
Collaborator

Yes, extension for a style tag is 'css'. And if it's not found in the filename, it's appended.

Vijay Dev
Collaborator

This is where the extension appending happens (in 3-2-stable). In master, this code is moved into sprockets-rails gem.

John Yani
Vanuan commented May 18, 2012

So, what about different behavour if config.assets.enabled = false?

Sergey Nartimov
lest commented May 18, 2012

When config.assets.enabled = false this method is used to rewrite extension.

I'm going to fix it.

John Yani
Vanuan commented May 18, 2012

Probably it should be moved to parent then.

Sergey Nartimov lest referenced this issue from a commit May 21, 2012
Commit has since been removed from the repository and is no longer available.
Carlos Antonio da Silva carlosantoniodasilva closed this issue from a commit May 21, 2012
Sergey Nartimov Assets: don't add extension if other given and file exists
We should lookup if asset without appended extension exists.
When sprockets are disabled the asset tag helpers incorporate
this logic. When sprockets are enabled we should have the same
logic.

For example, we have style.ext file in app/assets/stylesheets and
we use stylesheet_link_tag in the layout. In this case we should
have /assets/style.ext instead of /assets/style.ext.css in the
output.

Closes #6310
39f9f02
Carlos Antonio da Silva carlosantoniodasilva closed this in 39f9f02 May 21, 2012
Noah Silas noah256 referenced this issue from a commit in causes/rails June 08, 2012
Noah Silas Fix javascript_include_tag when no js runtime is available
In a production environment where the assets have been precompiled, we
don't want an assets compile step to happen on the application server at
all. To ensure this, a js runtime may not be available on the app
servers. In this environment, pages using javascript_include_tag for
assets with non-standard or chained extensions were throwing 500 errors.
For instance, `javascript_include_tag('jquery.min')` would blow up.

Sprockets was attempting to build the assets being included during the
rewrite_extension step (responsible for appending a '.js' extension to
assets being included by the basename rather than a fully qualified
name). This was happening as a step to resolve #6310, which required
checking for the presence of an asset with a non-standard extension
before appending the extension.

We can check for the presence of an asset without invoking the asset
build step by using Sprockets' resolve method, which will search for the
base file without building it (and is the method that find_asset uses
internally to get the path to the asset before attempting to build it).

When rewriting the extension on an asset, these are the steps:
- If the source does not have an extension, assume that the default
  extension is desired and append it.
- If there is an extension and it doesn't match the default extension,
  check to see if a file with the precise name specified exists amongst
  the assets; if it is present, do not append the default extension.
  (This is the step that resolves #6310).

Change-Id: I74e561db064ed21c4596ba6b6b0c9b4b236f8c06
8ce2c64
Noah Silas noah256 referenced this issue from a commit in causes/rails June 08, 2012
Noah Silas Fix javascript_include_tag when no js runtime is available
In a production environment where the assets have been precompiled, we
don't want an assets compile step to happen on the application server at
all. To ensure this, a js runtime may not be available on the app
servers. In this environment, pages using javascript_include_tag for
assets with non-standard or chained extensions were throwing 500 errors.
For instance, `javascript_include_tag('jquery.min')` would blow up.

Sprockets was attempting to build the assets being included during the
rewrite_extension step (responsible for appending a '.js' extension to
assets being included by the basename rather than a fully qualified
name). This was happening as a step to resolve #6310, which required
checking for the presence of an asset with a non-standard extension
before appending the extension.

We can check for the presence of an asset without invoking the asset
build step by using Sprockets' resolve method, which will search for the
base file without building it (and is the method that find_asset uses
internally to get the path to the asset before attempting to build it).

When rewriting the extension on an asset, these are the steps:
- If the source does not have an extension, assume that the default
  extension is desired and append it.
- If there is an extension and it doesn't match the default extension,
  check to see if a file with the precise name specified exists amongst
  the assets; if it is present, do not append the default extension.
  (This is the step that resolves #6310).

Change-Id: I74e561db064ed21c4596ba6b6b0c9b4b236f8c06
bb52f95
Noah Silas noah256 referenced this issue from a commit in causes/rails June 08, 2012
Noah Silas Fix javascript_include_tag when no js runtime is available
In a production environment where the assets have been precompiled, we
don't want an assets compile step to happen on the application server at
all. To ensure this, a js runtime may not be available on the app
servers. In this environment, pages using javascript_include_tag for
assets with non-standard or chained extensions were throwing 500 errors.
For instance, `javascript_include_tag('jquery.min')` would blow up.

Sprockets was attempting to build the assets being included during the
rewrite_extension step (responsible for appending a '.js' extension to
assets being included by the basename rather than a fully qualified
name). This was happening as a step to resolve #6310, which required
checking for the presence of an asset with a non-standard extension
before appending the extension.

We can check for the presence of an asset without invoking the asset
build step by using Sprockets' resolve method, which will search for the
base file without building it (and is the method that find_asset uses
internally to get the path to the asset before attempting to build it).

When rewriting the extension on an asset, these are the steps:
- If the source does not have an extension, assume that the default
  extension is desired and append it.
- If there is an extension and it doesn't match the default extension,
  check to see if a file with the precise name specified exists amongst
  the assets; if it is present, do not append the default extension.
  (This is the step that resolves #6310).

Change-Id: I0e500cb48c4f2f8a5bfe920eafc7d38bbba73390
6e154f4
Noah Silas noah256 referenced this issue from a commit in causes/rails June 08, 2012
Noah Silas Fix javascript_include_tag when no js runtime is available
In a production environment where the assets have been precompiled, we
don't want an assets compile step to happen on the application server at
all. To ensure this, a js runtime may not be available on the app
servers. In this environment, pages using javascript_include_tag for
assets with non-standard or chained extensions were throwing 500 errors.
For instance, `javascript_include_tag('jquery.min')` would blow up.

Sprockets was attempting to build the assets being included during the
rewrite_extension step (responsible for appending a '.js' extension to
assets being included by the basename rather than a fully qualified
name). This was happening as a step to resolve #6310, which required
checking for the presence of an asset with a non-standard extension
before appending the extension.

We can check for the presence of an asset without invoking the asset
build step by using Sprockets' resolve method, which will search for the
base file without building it (and is the method that find_asset uses
internally to get the path to the asset before attempting to build it).

When rewriting the extension on an asset, these are the steps:
- If the source does not have an extension, assume that the default
  extension is desired and append it.
- If there is an extension and it doesn't match the default extension,
  check to see if a file with the precise name specified exists amongst
  the assets; if it is present, do not append the default extension.
  (This is the step that resolves #6310).
9bc5e65
Noah Silas noah256 referenced this issue from a commit in causes/rails June 08, 2012
Noah Silas Fix javascript_include_tag when no js runtime is available
In a production environment where the assets have been precompiled, we
don't want an assets compile step to happen on the application server at
all. To ensure this, a js runtime may not be available on the app
servers. In this environment, pages using javascript_include_tag for
assets with non-standard or chained extensions were throwing 500 errors.
For instance, `javascript_include_tag('jquery.min')` would blow up.

Sprockets was attempting to build the assets being included during the
rewrite_extension step (responsible for appending a '.js' extension to
assets being included by the basename rather than a fully qualified
name). This was happening as a step to resolve #6310, which required
checking for the presence of an asset with a non-standard extension
before appending the extension.

We can check for the presence of an asset without invoking the asset
build step by using Sprockets' resolve method, which will search for the
base file without building it (and is the method that find_asset uses
internally to get the path to the asset before attempting to build it).

When rewriting the extension on an asset, these are the steps:
- If the source does not have an extension, assume that the default
  extension is desired and append it.
- If there is an extension and it doesn't match the default extension,
  check to see if a file with the precise name specified exists amongst
  the assets; if it is present, do not append the default extension.
  (This is the step that resolves #6310).

Change-Id: I0e500cb48c4f2f8a5bfe920eafc7d38bbba73390
caf454d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.