sbecker / asset_packager Goto Github PK
View Code? Open in Web Editor NEWJavaScript and CSS Asset Compression for Production Rails Apps
Home Page: http://synthesis.sbecker.net/pages/asset_packager
JavaScript and CSS Asset Compression for Production Rails Apps
Home Page: http://synthesis.sbecker.net/pages/asset_packager
I'm using jquery plugins. Each is a separate folder in my javascript directory. These folders contain css files and images that are referred to from the css files.
When asset_packager combined these files the path to the images is not adapted to find the images in their original folder. An example:
Part of my .yml file:
Given the following files
javascript/tools/styles.css => in this file a reference to url(tooltip.png) refers to the following file:
javascript/tools/tooltip.png
After packaging the image reference hasn't changed and the image can't be found.
Can this be accomplished?
Thanks
All HTML strings should be marked as safe on Rails 3; otherwise, the tags will be escaped.
You can do this by calling the "html_safe" method before returning the strings.
JS package is broken when merging a hash followed by a typical jquery plugin.
Example:
<first.js>
Tools={
myfn: function() {}
}
<second.js>
(function($){...})(jQuery)
after packaging this essentially produces the following:
Tools={...}(function($){...})(jQuery)
which, upon execution, crashes with the following error:
({myfn:(function () {...}) is not a function
...and the rest of the package may be broken as well to a varying extent.
to fix that, one must explicitly separate the hash and the plugin with a semicolon:
<first.js>
Tools={
...
}; //<-- !!!
bottomline is - that sucks
I have the jquery.cookie.js file in my public javascripts folder and here is my yml, It seem to include the rest of the .js files but for some reason does not include the jquery.cookie in the development environment pages, it does seem to include it in the base_packaged.js file?
--- javascripts: - base: - jquery.tools.min - jquery.cookie - application stylesheets: - base: - custom - screen - formtastic - jquery-ui-1.8.2.custom # - reset # - ie
vendor/plugins/asset_packager/lib/jsmin.rb:113:in `action': Unterminated string literal (RuntimeError)
from vendor/plugins/asset_packager/lib/jsmin.rb:195:in `jsmin'
from vendor/plugins/asset_packager/lib/jsmin.rb:205
Which is caused by code such as:
styleSheet.addRule(
'.typeface-js-selected-text',
'-ms-filter:
"Chroma(color=black)
progid:DXImageTransform.Microsoft.MaskFilter(Color=white)
progid:DXImageTransform.Microsoft.MaskFilter(Color=blue)
alpha(opacity=30)" !important;
color: black;
font-family: Modern;
position: absolute;
white-space: pre;
filter: alpha(opacity=0);'
);
The Rails 3 requires the "tasks" directory to be inside "lib". This can be safely moved out since it works on previous versions as well.
I'm compulsively organized—organized to a fault, some might say—and I was trying to organize my JavaScript files according to the section of the site they pertain to:
javascripts
javascripts/application.js
javascripts/section1/base.js
javascripts/section2/base.js
etc.
but they don't seem to be loading at all with the configuration I have set up:
---
javascripts:
- section1:
- application
- section1/base
Is there any support for nested assets on the horizon? Or does such a thing already exist and I'm a complete moron?
Any help or just a general reply would be great!
Dallas
It's simple to fix in lib/synthesis/asset_package_helper.rb:
sources.collect {|source| javascript_include_tag(source, options) }.join("\n").html_safe
... and ...
sources.collect { |source| stylesheet_link_tag(source, options) }.join("\n").html_safe
Hi,
I'm getting this error when I try to run my app. Any suggestion ?
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/var/lib/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement
/var/lib/gems/1.8/gems/asset_packager-0.2.0/lib/synthesis/asset_package.rb:6: undefined local variable or method `config' for Synthesis::AssetPackage:Class (NameError)
Thanks in advance
DEPRECATION WARNING: Rake tasks in vendor/plugins/asset_packager/tasks are deprecated. Use lib/tasks instead. (called from [...]/vendor/isolated/gems/rails-2.3.8/lib/tasks/rails.rb:10)
If you have a js file that's rendered through a controller, or use the js_named_routes(http://github.com/jsierles/js_named_routes ) plugin, there doesn't seem to be a way to get them packaged.
Perhaps instead of opening files, it could call for the resources the regular way (through a url) then build them from there. That way it would work for absolutely any method of serving resources.
installing with rails plugin install git://github.com/sbecker/asset_packager.git
i see this error:
~/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require': no such file to load -- asset_packager (LoadError)
I haven't been able to suss out a reason yet - but I have two servers that refuse to build the packages on demand. Rake tasks for creating them work just fine. Have any ideas on debugging them?
The problem:
A solution:
We have several apps that get deployed in serial. When using Google's Closure service to compile JS, the resulting JavaScript files contained only the following:
Error(22): Too many compiles performed recently. Try again later.
This was obviously causing catastrophic failure with our JS. To avoid this problem, perhaps asset_packager should check for the presence of this string in resulting JS files and re-try after a set period?
Hi,
I am new to Rails and my question may be very trivial.
I have asset_packager plugin installed in my app. I installed JasonKing's inline_attachment plugin for sending out emails with inline images. But when I try to send a email I am getting a error message (undefined method 'request') and this error seems to happen in 'compute_public_path' in asset_package_helper class of asset_packager plugin and it is working fine when asset packager is uninstalled.
Is there any workaround for this? Please let me know if you need more details.
Thanks,
Sivakumar.
I really like your tool and it works great with the default rails cache busting approach of adding a timestamp after ?. However when you use with the amazon CDN the ?timestamp part of the URL is not taken into account.
It would be great if the asset packager could help busting the CDN cache without requiring additional steps to the current workflow. One approach would be to:
I can help with the implementation once we reach a consensus on an approach that works...
The helpers (with the should_merge? method) always consider the env to development, consequently the compressed files are never included in production.
The RAILS_ENV var does not exist anymore in rails 3.
You may should Rails.env instead.
I've run into an interesting use case where I'd like to get back an array of files included in the package (instead of the style tags).
For instance, if the method were called stylesheet_files_merged, one could do:
# in development
stylesheet_files_merged(:base) = ["/stylesheets/screen.css", "/stylesheets/header.css"]
# in production
stylesheet_files_merged(:base) = ["/stylesheets/base_packaged.css"]
I took a look through the source, but the right combination of methods didn't jump out at me. Any advice?
Rails 3 deprecated the RAILS_ROOT constant in favor of Rails.root.
I have to exclude prototype.js (v 1.7_rc2) from the asset package, and load it with javascript_include_tag in order to get prototype to load. The rake task asset:packager:build_all succeeds with prototype in the package, but it still fails to load.
Hi,
I've installed your plugin and uses it for development, but on attempt to create production package i see following error
$ rake asset:packager:build_all
(in /Users/alec/Documents/Projects/Workspaces/my_projects/cyberberry_geeks)
rake aborted!
No such file or directory - /Users/alec/Documents/Projects/Workspaces/my_projects/cyberberry_geeks/tmp/base_packaged_uncompressed.js
How can i solve it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.