Rails assets keep CSS license comments when stylesheet assets are minified - ruby-on-rails-3

How do I preserve CSS comments in Rails stylesheet assets that are minified?
This is similar to this question, but for CSS instead of JavaScript.

Rails currently uses YUI Compressor to minify CSS stylesheets during asset precompilation. See this section of the Rails asset guide.
To prevent certain comments from being removed, just add an exclamation point to the comment block as follows:
/*!
License comment here won't be removed
*/
This is documented here.

Related

How to rename bundled static files(ProjectName.style.css and blazor.server.js) in The Blazor App

I wanna hide that i use The Blazor.
so, I should modify name of bundled css and js files.
How to do this?
According to this article, CSS isolation occurs at build time. During this process, Blazor rewrites CSS selectors to match markup rendered by the component. These rewritten CSS styles are bundled and produced as a static asset at {PROJECT NAME}.styles.css, where the placeholder {PROJECT NAME} is the referenced package or product name.
That means we could only disable the bundle not modify it during develop environment.
But after publish, it will generate the file like this:
You could modify the {PROJECT NAME}.styles.css to {other}.styles.css and modify the index.html css name as below:
<link href="{other}.styles.css" rel="stylesheet" />

Referencing Images in Stencil Themes

For BigCommerce stencil themes having references to assets, the docs do not mention CSS and SASS URL references.
Is there a specialized SASS function for referencing images in the asserts directory, in BigCommerce stencil themes? Or, will CDN reference strings be converted automatically?
If you are referencing images that are bundled with your theme, you can use a path like ../images/myimage.png and it will load from the CDN. If you are referencing images from outside of the theme, there is no SASS function and you will need to hardcode the CDN URL (or use inline css to utilize the CDN handlebars helper).
Alyss's answer helped, in your CSS you can reference theme assets with the path he provided:
../images/myimage.png
For inline, you can refence them by using the CDN handlebars syntax:
<link href="{{cdn '/assets/css/invoice.css'}}" rel="stylesheet">
More info here:
https://stencil.bigcommerce.com/docs/css-resources

How to include css pie in Rails 3.2 with asset pipeline?

I would like to include PIE.htc in my Rails application to make CSS3 easier for IE. I can't seem to figure out how to include the PIE.htc file.
I tried to include PIE.htc in my assets folder as well as assets/stylesheets folder, but I no routes matching error.
How do I include PIE.htc with rails asset pipeline?
Try the solution in this post: Using PIE.htc in rails
Basically, it should be:
behavior: url(/assets/PIE.htc);
Also, if you want to be completely sure that the PIE.htc file is being loaded, open it and add an alert as so:
<script type="text/javascript">
alert("PIE works);
If the file if being loaded, a popup should appear showing the message.

Is there a "Rails Way" include a jQuery plugin in the Asset Pipeline?

Many jQuery plugins have the following directory structures:
/<plugin name>
../css
../images
../js
The CSS files usually have relative links to the images in them. What I want to do is include these plugins in the Rails Way under the Asset Pipeline, and hopefully that doesn't involve having to renamed the file references to remove the relative links. Is there such a Rails Way?
Could it also be that it's overkill to include an already-minified jQuery plugin in the Asset Pipeline?
You should try to add your assets to the load path which is the recommended way, as far as I know. If the application you're running has the assets-pipeline activated, it should find your assets after expanding the path in your application.rb
config.assets.paths << Rails.root.join("plugins/plugin_name/assets/")
Not shure, if this is what you asked for but if not, you should check: http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
Remeber to restart your server
I had the same issue and also tried to find "the Rails way" to do this. And this is what I ended up with at the end of the day:
As Rob already mentioned:
vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.
Source: 2.1 Asset Organization
Lets take a practical example: using the jquery_datepicker gem (Note: we had to use a workaround because of this issue: bundle pack does not work with git sources).
1) Installing the gem (pretty straighforward):
cd vendor/gems
git clone https://github.com/albertopq/jquery_datepicker.git
2) Add this to your Gemfile
gem 'jquery_datepicker', :path => 'vendor/gems/jquery_datepicker'
3) Install a jquery-ui theme
From ThemeRoller select a theme, check Datepicker and Slider
and the jQUery version
Download and extract the content of the package
CSS/images from the css/theme-name folder move them:
jquery-ui-1.8.xx.custom.css to app/vendor/stylesheets/
the images folder to app/vendor/images/ (yes, move the entire folder images so you end up with something like this app/vendor/images/images/ui-icons_256x240.png
i18n from the development-bundle/ui/i18n folder (optional) move them to:
Create a folder i18n under app/vendor/javascripts/
move jquery.ui.datepicker-xx.js to this folder app/vendor/javascripts/i18n/
make sure the i18n folder is loaded so include in application.js
//= require_directory ./i18n
vendor/assets is loaded automatically AFAIK so you don't have to include the path in the asset pipeline.
I'd like to see how others are approaching this, it's a very good question.
I think the reason you haven't received an answer is because it's kind of unclear what you're asking. Are you asking if it's overkill to put your plugins in the asset pipeline? Are you asking if you have to rename file references?
I always put all my jquery plugins in my asset pipeline. Overkill or not, there all in one place and they only get compiled once so even if compiling them takes longer, it doesn't affect my app.

Styling static Rails HTML using stylesheet assets

I am looking to create static error pages (like the 404, 422 and 500 pages given by Rails) which have the same theme as the app does.
The theme of the app is in stylesheets in my assets pipeline. How do I connect to the stylesheets from my static pages?
I'm just trying to this myself and it looks like http://neovintage.blogspot.de/2012/02/precompile-static-html-pages-with-rails.html is a good way to do it.
What it Rimas Silkaitis suggests there is to add an html assets folder (for your error pages) which is then precompiled along with your other assets. This allows you to use ERB and the asset helper functions.
This does not easily work in your development environment though.