Code Monkey home page Code Monkey logo

jammit's Introduction

This is the repository for the legacy DocumentCloud site, please see the current repository here:

https://github.com/muckrock/documentcloud

______                                      _   _____ _                 _
|  _  \                                    | | /  __ \ |               | |
| | | |___   ___ _   _ _ __ ___   ___ _ __ | |_| /  \/ | ___  _   _  __| |
| | | / _ \ / __| | | | '_ ` _ \ / _ \ '_ \| __| |   | |/ _ \| | | |/ _` |
| |/ / (_) | (__| |_| | | | | | |  __/ | | | |_| \__/\ | (_) | |_| | (_| |
|___/ \___/ \___|\__,_|_| |_| |_|\___|_| |_|\__|\____/_|\___/ \__,_|\__,_|

DocumentCloud is a catalog of primary source documents and a tool for annotating, organizing and publishing them on the web. Documents are contributed by journalists, researchers and archivists.

This codebase contains the entirety of DocumentCloud.org, and pulls together the rest of our open-source projects: Docsplit is used to extract data from incoming documents; that work is parallelized across CloudCrowd; data on the client-side is modeled by Backbone.js, which depends on Underscore.js for all of its abilities; Jammit concatenates and compresses the dozens of CSS and JS files into a single asset package; the NYTimes' Document Viewer displays the documents, while Pixel Ping records the traffic.

If you find a security issue while browsing the source, please email [email protected] to inform us of the problem.

Code contributed to this project is provided under the MIT license (see the LICENSE file). Some components of the project are subject to their own licenses as indicated (see /vendor and /public/javascripts/vendor directories).

jammit's People

Contributors

agibralter avatar apeckham avatar caifara avatar caseywebdev avatar chriseppstein avatar christoffer avatar dblock avatar didip avatar dramsay avatar ghazel avatar jashkenas avatar john-griffin avatar knowtheory avatar leemhenson avatar lukeasrodgers avatar mikz avatar mitio avatar mnutt avatar nathanstitt avatar nertzy avatar reefdog avatar rubymood avatar ryankshaw avatar samuelclay avatar sarcilav avatar stevecrozz avatar stricte avatar sutto avatar timriley avatar whitethunder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jammit's Issues

Warbler support

Summary

Using jammit with warbler breaks packaged assets.

Description

Warbler is used to package a rails app for deployment to a J2EE server (e.g. glassfish).

For some reason, warbler removes the /public/ from all asset folders, so that you application folder looks something like:

/javascripts/..
/images/...
/stylesheets/...
/WEB-INF/app/...
/WEB-INF/config/...

Anticipating this I configured my asset.yml file like so:

javascripts:
  common:
    - **/javascripts/foo.js
    - **/javascripts/bar.js

This worked find in development (even with package_assets:always) but once I deployed to glassfish the url http://localhost:8080/RailsApp/assets/common.js returned a 200 response code but with no text.

The log file contains a bunch of Jammit warnings:

Jammit Warning: No assets match '**/javascripts/foo.    
Jammit Warning: No assets match '**/javascripts/bar.js'

Is there a simple workaround for this issue or is this something that will require a modification to Jammit to get going?

Additional Info

  • Rails Version 2.2.2
  • Jammit Version 0.43
  • Warbler Version 0.9.14

Windows paths with spaces don't work with datauri

Embedding images with datauri doesn't work when you have a windows path with spaces.

Here's an example, with embed_assets set at 'datauri', run jammit. On one of my files (base-datauri.css), I find this inside

background:url(__EMBED__C:/Documents and Settings/username/My Documents/Website/public/images/embed/bg_body_int.png)

When I move the code to C:\code, and run jammit, I get the embedded binary image.

It's possible this is a relatively easy fix...delimiting or putting path in quotes so long as that doesn't screw up other platforms. There's also no error message stating the embedded function did not work.

Workaround: Move code to non-spaced path.

Setting different java path for different environments

What would be the preferred way of setting different java paths for different environments for the closure-compiler gem via jammit? I see how to do it globally:

compressor_options:
  java: /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java

but I've found that it'd be nice to be able to set it per-environment also. I'd be happy to submit a patch if it sounds like a good idea and there isn't already a way. (support for environments/debug-assets.yml? nested environment info in standard assets.yml? cattr_accessor on Closure::Compiler?).

cannot pass parameters to JavaScript files

If I include a '?' in the JS file path, the asset is no longer included in the HEAD. I want to pass a variable to a local script indicating a state e.g.

default_js:
- public/javascripts/ajax.js?enabled=false

Cheers,
Karl

jammit fails when rails 3 gems are installed

After installing the Rails 3.0 beta gems, jammit fails to run with the following error:

imac-home ~/code/rails/yougotpapped (master): jammit
/Library/Ruby/Gems/1.8/gems/jammit-0.4.1/lib/jammit/compressor.rb:27: undefined method `kilobytes' for 32:Fixnum (NoMethodError)
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from /Library/Ruby/Gems/1.8/gems/jammit-0.4.1/lib/jammit/dependencies.rb:19
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from /Library/Ruby/Gems/1.8/gems/jammit-0.4.1/lib/jammit.rb:145
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from /Library/Ruby/Gems/1.8/gems/jammit-0.4.1/bin/../lib/jammit/command_line.rb:2
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in`gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    from /Library/Ruby/Gems/1.8/gems/jammit-0.4.1/bin/jammit:3
    from /usr/bin/jammit:19:in`load'
    from /usr/bin/jammit:19

Embedded assets and existing conditional comments

We're looking into the possibility of using Jammit on Tender and Lighthouse and I've run into an issue with embedded assets and conditional comments.

We already have some Internet Explorer specific stylesheets, so this means we'll have markup like this:

This works fine until you turn on embedded assets. You end up with nested conditional comments and the IE mhtml stylesheets are included in other browsers such as Safari and Firefox. Below is what we end up with.

    <!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/frontend-datauri.css?1270158082" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/frontend-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/safari-datauri.css?1270158084" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/safari-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 6]>
<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/ie6-datauri.css?1270158080" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/ie6-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<![endif]-->
<!--[if IE 7]>
<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/ie7-datauri.css?1270158083" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/ie7-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<![endif]-->

Are there workarounds for this or perhaps I'm doing something wrong?

Jammit + Passenger + Nginx = Asset files are not created

I am running Nginx + Passenger on my Production environment (Ubuntu 9.10, Ruby 1.9.1). I am using Jammit to package my CSS/JS in /public/assets. Everything works fine on my OS X dev box. When deploying to Production Jammit does not create any asset files. I've ensured the entire app is owned/writable by the nginx user (which nginx runs under). Manually running the jammit command from the command line correctly creates the asset files.

Also, I checked the HTTP Response for requests for /public/assets/common.css and there were no X Response headers/returned the Nginx 404 page, which makes me think that the request isn't even getting routed to the Rails stack. (I verified I have the Jammit route config existed in routes.rb). Disclaimer: I'm not sure about the validity of this deduction. :)

I then tried to start the application on production using script/server -e production (running it under WEBrick) .. When I curl'd http://localhost:3000/public/assets/common.css the assets folder was created and the common.css was correctly created. So it appears when running under WEBrick Jammit functions properly.

Any counsel around using Jammit with Nginx + Passenger? Will I have to update my Capistrano recipe to manually execute the jammit command?

Errno::EACCES: Permission denied in Production

Instead of getting 404s in production, I'm getting 500s due to Errno::EACCES.

Errno::EACCES: Permission denied - /home/rails/myapp/releases/20091127033835/public/assets/anything.css
Errno::EACCES: Permission denied - /home/rails/myapp/releases/20091127033835/public/assets/anything.js

etc...

Here is a backtrace:

/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/jammit-0.2.4/lib/jammit/packager.rb:56:in `initialize'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/jammit-0.2.4/lib/jammit/packager.rb:56:in `open'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/jammit-0.2.4/lib/jammit/packager.rb:56:in `cache'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/jammit-0.2.4/lib/jammit/controller.rb:37:in `cache_package'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:178:in `send'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:178:in `evaluate_method'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:166:in `call'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/actionpack-2.3.4/lib/action_controller/filters.rb:662:in `run_after_filters'
/home/rails/myapp/releases/20091127033835/vendor/bundler_gems/gems/actionpack-2.3.4/lib/action_controller/filters.rb:619:in `call_filters'

Any thoughts?

How to get verbose output when compile javascript with errors

First, love this package.
Second, I noticed while integrating this with my site, I made a typo in one of my .js files. When it gets compressed via jammit, it just produces a zero length file. No errors, nothing...

I looked thru source and did not find anything obvious about how to make the ruby-yui-compressor generate errors (or whatever) when it compresses and discovers a problem.

Suggestions?

remove

just delete this. seems pointless since it won't be the preferred way to use jammit in rails 3 anyway.

Optional browsers

Every project I use Jammit + embed images is getting errors while loading images on IE8.

I think IE8 is not good enough for using embed images, so I would like to ask you if it's possible to have an option to choose what kind of DATA_URI_START the programmer wants.

Exception when running with ./script/server -d (detached mode)

This is too strange - if I run ./script/server, everything is great. If I do ./script/server -d, I get the trace below. I even manually added "javascript_compressor: yui" to my assets.yml just in case. Any thoughts? This env is Rails 2.3.4, mongrel 1.1.5.

ActionView::TemplateError (You have a nil object when you didn't expect it!
The error occurred while evaluating nil.merge) on line #7 of app/views/layouts/main.html.erb:
4:
5: <title><%= @page_title %></title>
6:
7: <%= include_stylesheets :core, :all %>
8:
9: <%= include_javascripts :core %>
10:

jammit (0.2.1) lib/jammit/compressor.rb:44:in `initialize'
jammit (0.2.1) lib/jammit/packager.rb:16:in `new'
jammit (0.2.1) lib/jammit/packager.rb:16:in `initialize'
jammit (0.2.1) lib/jammit.rb:60:in `new'
jammit (0.2.1) lib/jammit.rb:60:in `packager'
jammit (0.2.1) lib/jammit/helper.rb:43:in `individual_stylesheets'
jammit (0.2.1) lib/jammit/helper.rb:66:in `tags_with_options'
jammit (0.2.1) lib/jammit/helper.rb:66:in `map!'
jammit (0.2.1) lib/jammit/helper.rb:66:in `tags_with_options'
jammit (0.2.1) lib/jammit/helper.rb:43:in `individual_stylesheets'
jammit (0.2.1) lib/jammit/helper.rb:18:in `include_stylesheets'
app/views/layouts/main.html.erb:7
app/controllers/opportunities_controller.rb:58:in `index'

`#{java} -version 2>&1` every page load in development

This is only a minor nuisance, but perhaps it could be improved. It seems that every page load in development mode causes Jammit.reload!, which in turn checks the java version with #{java} -version 2>&1. This takes a bit of time - more than anything else on my pages. package_assets is set to "on", which prevents Jammit from actually doing anything with Java in development anyway.

Could this check be cached, or changed to only run if packaging will occur?

Rails 3.0 Support

I tried jammit with 3.0pre. Adding Jammit::Routes.draw(map) to the routes doesn't work.

Content Negotiation not working under Apache

Unfortunately Content Negotiation using MultiViews requires the requested file to not exist on the filesystem. This was already pointed out in the comment by Ches Martin to this post: http://afreshcup.com/home/2010/1/18/notes-on-using-jammit-with-rails.html.

So in other words, in order for asset pre-caching to work under Apache the URLs generated by Jammit should omit the file extension.

This can be tested using the following .htaccess in the assets folder:

AddEncoding x-gzip .gz
Options +MultiViews

<FilesMatch "\.css.gz$">
  ForceType text/css
</FilesMatch>

<FilesMatch "\.js.gz$">
  ForceType text/javascript
</FilesMatch>

Here is an example request:

% curl -I -H 'Accept-Encoding:gzip,deflate' http://site.local/assets/style   
HTTP/1.1 200 OK
Date: Thu, 27 May 2010 09:56:03 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 Phusion_Passenger/2.2.11
Content-Location: style.css.gz
Last-Modified: Thu, 27 May 2010 09:45:28 GMT
ETag: "75aef2-120f-4878c0f420a00;4878c75f4eec0"
Accept-Ranges: bytes
Content-Length: 4623
Cache-Control: max-age=31536000
Expires: Fri, 27 May 2011 09:56:03 GMT
Content-Type: text/css
Content-Encoding: gzip

I think a possible solution could be the addition of a configuration option to omit filename extensions in production.

Rails 2.3.5 reports Jammit missing on Windows, Ruby 1.9.1

I am trying to run "rake db:test:clone" in my Windows dev environment and am getting:

...
C:/Ruby19/bin/rake:19:in load
C:/Ruby19/bin/rake:19:in <main>
Missing these required gems:
  jammit

You're running:
  ruby 1.9.1.378 at C:/Ruby19/bin/ruby.exe
  rubygems 1.3.5 at C:/Users/Shaun/.gem/ruby/1.9.1, C:/Ruby19/lib/ruby/gems/1.9.1

Run `rake gems:install` to install the missing gems.

I the same error message (with a different stack trace of course) when i run "ruby script/server"

I've tried running "rake gems:install" of course and that appears to execute correctly.

I have also tried to manually run "gem install jammit" which looks like it works:
Successfully installed jammit-0.4.4
1 gem installed
Installing ri documentation for jammit-0.4.4...
Updating class cache with 1187 classes...
Installing RDoc documentation for jammit-0.4.4...

When i run "gem list --local" is lists
jammit 0.4.4
so i assume that its installed. Im not sure Rails doesnt think its there.

Also, I am able to run "rake db:create" without issue.

The same project on an OS X system runs without issue. Any thoughts on why this issue is occurring and how to fix?

Thanks

jammit development --watch (-w) mode

Now that I'm using jammit, I no longer keep javascript in public/javascripts; rather, I keep un-compiled, uncompressed javascripts in app/javascripts and only expose jammit-compiled scripts to the end user at public/assets... The only problem is that the include_javascripts helper in development mode expands all the script tags in the HTML and my scripts are not accessible since they're not in public/. I had to add package_assets: always in assets.yml.

Now I was just thinking it might be cool to have something like compass's (http://github.com/chriseppstein/compass) compass -w feature that would watch everything listed in assets.yml and recompile the asset packages when they change... jammit -w maybe?

Wrong place to be defining ASSET_ROOT and PUBLIC_ROOT

Seems like a terrible idea to be using Rails.root and Rails.public path directly in your jammit.rb. Assigning to a constant no less so ruby will throw errors if you redefine it later.

There's a ton of other solutions. Lets move them into mattr_accessors or something...

Really doesn't make sense to use constants to define very dynamic data such as app paths. This is configurable stuff, not "set once and leave it".

@media support?

The CSS @media directive can be used to mark sections of the stylesheet for different media using media queries. An interesting idea would be to support including the print stylesheet in the "jammed" stylesheet by embedding it within @media print { ...content here... }.

The downside is that the content would not be conditionally downloaded in cases where the media query matches.

include :cache => true when calling javascript/stylesheet_include_tag?

hey,

I organize my files with a few default groupings (:defaults, :auth, etc) and then mix those on a page-by-page basis with some custom javascript. using :cache => true merges all these files together in production so there is only one include.

Jammit doesn't use that flag, so if I call include_javascripts(:defaults, :my_page), it will use two script tags, and two tcp connections.

I guess I should stop and ask if it's possible to combine the files in the assets.yml file? I would like to avoid setting up packages that contain mostly duplicate files. If it isn't possible do to in the assets.yml file, would it be possible to add a :cache => file_name to the *_include_tag? File_name could be something like tags.flatten.hash.to_s, to make it unique.

Thanks

I know that if I put all assets into a package in the assets.yml file, that this functionality won't

javascript_include_tag

Jammit + browser caching + CDNs

I was just wondering... would it make sense to build some sort of system into Jammit to allow the browser caching of JS and CSS assets? What I imagine is something like this:

When the jammit command gets run, it calculates a MD5 checksum of each package and creates a file, assets.lock.yml in config/. That file could look something like:

package1: 50bda6102c8dd57a5ead84e99d493776
package2: 1dd5a5eabda693707672c8d84e99d450

It also symlinks (or copies) each package to have its MD5 checksum as a name:

50bda6102c8dd57a5ead84e99d493776.js@ -> package1.js
50bda6102c8dd57a5ead84e99d493776.js.gz@ -> package1.js.gz

Then, when the Rails app is running in production, include_javascripts(:package1) could instead generate:

<script src="/assets/50bda6102c8dd57a5ead84e99d493776.js" type="text/javascript"></script>

Also, a deployment script could copy these MD5-named assets to CDNs after running jammit.

Is this a crazy idea? Is there a way to do something similar already?

enabling custom includes in packaging

Just a feature idea -- I won't be offended at all if you close this right away. Have you ever thought about the ability to do custom includes in JS code to require library files within other JS files, rather than packaging them sequentially? I was just looking through the jquery code (http://github.com/jquery/jquery/tree/master/src/) and it looks like they build up jquery from all the parts separately in a specific order. Jammit could have something where you parse files for:

/* @include item.js */

That replaces the entire comment with the contents of item.js...

P.S. Sorry to constantly bug you with all these tickets! :)

css_compressor options

It seems there's no way to pass custom options to the YUI::CssCompressor instance.
According to the initialize method, the compressor_option holds the options for the Js compressor.

def initialize
  @css_compressor = YUI::CssCompressor.new # <-- options?
  flavor          = Jammit.javascript_compressor
  @options        = DEFAULT_OPTIONS[flavor].merge(Jammit.compressor_options)
  @js_compressor  = COMPRESSORS[flavor].new(@options)
end

What about providing the ability to configure additional css options in the assets.yml file using a css_compressor_options node?

Fail loudly when java is not installed

Jammit fails with pretty cryptic errors (actually from yui-compressor) about broken pipes when java is not installed. Obviously yui-compressor requires java, but it would still be nice to get some sort of warning about not finding java in PATH.

Hope this saves someone a few hours of debugging ;)

incorrect image paths in packaged CSS

I have a CSS file in S:/public/stylesheets/kawaii/datatable.css
Inside that file are references to url(sprite.png) which exists at S:/public/stylesheets/kawaii/sprite.png

However after using Jammit to package that CSS file with a few others in the same directory, I get
http://localhost:3000/assets/kawaii.css which contains incorrect paths in the CSS like this: url(../S:/public/stylesheets/kawaii/sprite.png)

I know putting images inside the stylesheets directory is probably a bad idea, but I try to keep from editing the kawaii project ( http://code.google.com/p/kawaii/ ) files.

Distributed Asset Hosts

Yar wrote:

There is only one thing that seems to be missing: support for distributed asset hosts
in the processed CSS files.

Some piece of code that would replace pieces like
background: url('/images/backgrounds/topcapA1.jpg');

with

background: url('http://w2.domain-assets.com/images/backgrounds/topcapA1.jpg');

in accordance with config.action_controller.asset_host directive in production.rb. What procedure > or script do you actually use for this purpose?

combine JST with JS

Back on the subject of JST... have you ever considered combining JST and JS in assets.yml? It doesn't seem like there's any need to have separate JS files for the templates. Instead you could have:

javascripts:
  main:
    - app/javascripts/vendor/jquery-1.4.js
    - app/javascripts/vendor/json2.js
    - app/views/jst/**/*.jst

I'm thinking this would be nice because I have a JS file that defines a widget that people can put on their blogs. Right now I have that JS file making a separate call to load up the JST files, but it would be really sweet if I could just bundle them all together in one widget.js file.

Another thing that might be nice would be the ability to customize the namespace used for the jst files (rather than forcing window.JST). Since I'm writing code that will get embedded on other sites, I'd like to make sure my namespace is unique: window.mysiteJST.

If you agree with the premise of these two ideas, I'd be happy to make a patch.

Oh -- I'm thinking there's one catch: the development behavior. The templates are dynamically compiled on every request but the JS files just get linked... maybe it could be:

templates:
  all:
    - app/views/jst/**/*.jst
javascripts:
  main:
    - app/javascripts/vendor/jquery-1.4.js
    - app/javascripts/vendor/json2.js
    - all.jst

Any thoughts?

turn off embedding on a per-package

I'm using compass/blueprint in my CSS and it uses an IE6/7-only stylesheet:

    /[if lt IE 8]
      = stylesheet_link_tag 'compiled/ie.css', :media => 'screen, projection'

I was thinking I would use the Jammit include_stylesheets helper just for consistency in code and in keeping all my assets in public/assets; however, this causes trouble because of double HTML comments... If I do:

    /[if lt IE 8]
      = include_stylesheets :ie, :media => 'screen, projection'

I get:

<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/assets/ie-datauri.css?1259696203" media="screen, projection" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/assets/ie.css?1259696202" media="screen, projection" rel="stylesheet" type="text/css" />
<![endif]>
<![endif]>

I know this is a bit of a corner case, but perhaps some something like

include_stylesheets :ie, :media => 'screen, projection', :no_embed => true

would make sense. Any thoughts?

less/more support

it seems that jammit and Less (using the More rails plugin) are not compatible. In dev mode, More redirects all /stylesheet requests to a controller, so the file doesn't exist on disk and jammit can't find it, combine, and compress it. That is not an issue for production (or if perform_cache) is enabled.

Their is definitely overlap, but their areas of focus are complimentary (css mixins, variables on one side and robust package management and compression on the other). I'm not sure if there is a 'right' way to get them to work together as one requires files on disk (jammit) and the other is all dynamic (more in development).

thoughts on if this is worth even trying to make work?

Ideally, I would like to be able to specify

embed_images and IE conditionals

If you already enabled conditionals and want to use a stylesheet for IE, and turn embed_images on, then you get conditionals within conditionals. Need a way to combine these, or provide a way of overriding this.

For example, I have a stylesheet just for IE8 or lower.
/[if lte IE 7]
= include_stylesheets :ie, :media => 'screen, projection'

Then ends up looking like this in HTML




<![endif]-->

the "java" command could not be found (Jammit::JavaNotFound)

I'm creating a new ticket since the issue I'm having is different from the other java issue.

I'm deploying to dreamhost, and when I log in, my user has access to java 1.6 in /usr/bin/java
I can run script/console just fine, since the user also has access to java.

When I try to view the website, it crashes with the error above, below are the last 2 lines of stack trace:
/home/app.com/current/vendor/bundler_gems/gems/jammit-0.3.1/lib/jammit.rb 122 in check_java_version' /home/app.com/current/vendor/bundler_gems/gems/jammit-0.3.1/lib/jammit.rb 66 inload_configuration'

I'm not "live" bundling the assets, and the rake bundle:all task works (again because it's my user account which has access).

I tried forcing the java location in the assets.yml file without success.

If I disable the checks by commenting out the "raise Exception" code, the application will launch.

Jammit with RAILS_ENV=development seems to mess up app/controllers/application_controller.rb

If I add config.gem "jammit" to my config/environment.rb and then run my app, it appears that Jammit is somehow keeping app/controllers/application_controller.rb from being processed. As a result, any custom code I have in my application_controller.rb doesn't work. For example, my filter_parameter_logging call has no effect when using Jammit. If I remove the config.gem line, it starts working again for me. I'm guessing it has something to do with the end of Jammit's controller.rb where it sets up the before_filter in the ApplicationController class...

turning off package_assets in different environments

Is there a way to set package_assets to false on a per-environment basis? Or what would you recommend for cucumber/integration tests? Right now the first time my cucumber features run they generate JS/CSS, and after that, they don't.

include assets from other directories

I'm not sure if this is possible already, but it didn't seem to work. What I'd like to do is load JS/CSS from other directories, e.g.

javascripts:
  playing:
    - app/javascripts/playing/*.js
    - ~/sprockets/play.js

Is this possible ?

include_templates in development

I've been using jammit's default development behavior (i.e. not compiling/compressing javascript files and css files), but I can't quite figure out what to do with JST files. Is there any way to have jammit compile only JST files on every request in development so I don't have to run jammit every time I change my JST files?

Dynamic Packages

It would be cool to have something like "dynamic packages" supported. We need this feature for packaging assets for different accout types and user levels multiplied with different booked packages.. No fun to "pre-" configure this.

We've build a "desktop class" application with several hundreds of js files. A normal user downloads about 400 js scripts (ofc bundled to one in production). This can be up to 800 scripts. The bundled and compressed script is still about 1-2 mb (without libs). Also a script can require css, flash and java applets. You might agree that it is not an option for us to provide all scripts to all users at once.

What we have in production is jsrequire [1] for js dependency management (quiet similar to Sprockets [2], but more flexible (see loadpaths -> webpath helper, customizable hooks)) and a (very small) patched version of jammit [3] for bundeling with an interchanged Jammit::Packager. Enough written, here is a little code how we did it:

Jammit.configured_packager = :dynamic_packager

class DynamicPackager < Jammit::Packager
  def not_found(package, extension)
    dynamic_package_for(package, extension) || super
  end

  def dynamic_package_for(package, extension)
    # app specific code
  end
end

Hope you understand the needs of "dynamic packages" for us. Is this a way for jammit? Other ideas or solutions on that problem? Thanks.


[1] http://github.com/aekym/jsrequire
[2] http://getsprockets.org/
[3] http://github.com/aekym/jammit/tree/0.4.4.aekym

jammit is running forever with closure-compiler and don't compress anything

I set javascript_compressor: closure in assets.yml
and run the jammit in the home dir of my app.
It never stops and my public/assest folder is emtpy.

It's working with YUI and closure-compiler works when I try it in script/console
(closure.compile method).

I use Ubuntu karmic, ruby 1.8.7 p72, jammit 0.3.3, closure-compiler 0.1.5.

Thanks

render external css files

When a css file has an reference to another css file via the import directive, the referenced file shoud be included in the generated css file, for saving http requests.

S3 Feature Request

I'm looking for an asset packager that would work with a read-only file system like Heroku. From what I can see, the only way to achieve this would be to upload the packaged files to a service like S3 and serve them from there. Any thought about adding this? I think it would make this plugin wildly popular for anyone using Heroku as there aren't many (or any that i know of) asset packagers that comply with the read-only fs.

JST revisited

Hi there -- I'm back for more trouble :).

Recently I realized that soon I'm going to need better JST functionality than 0.4.4 has (putting JST in with the JS, etc.), so I decided to take another stab at it. I know you want to wait for Rails 3 for 0.5.x, but I think this JST stuff is worthwhile enough to release as a 0.5.0 and then have 0.6.0 be Rails 3 (since the JST changes introduce deprecations, it shouldn't be 0.4.5).

In my dev branch (http://github.com/agibralter/jammit/commits/dev) I just pushed my latest commit:

http://github.com/agibralter/jammit/commit/2be5d1ae76eea6131d147aa2b75bec170c8b7b3a

The commit message say most of it, but basically, I rearranged test fixture names because they were becoming a little bit hard to maintain, I added a controller test finally :), and I made it so that people can specify template extensions with a config option (e.g. template_extension: "html.mustache"). I also made a pretty important change to how dynamically generated JS templates are handled (see the __templates__ stuff in the commit). I think this change makes Jammit's development behavior a lot more understandable.

I think there's one more piece of functionality that I want to add: proper scoping for JS templates with a template_base_dir config option. The way I see this working is that if a user specifies this config option, Jammit will build a nested object for all JST files located in this base directory.

For assets.yml:

template_base_dir: app/mustache_templates
template_extension: "html.mustache"
javascripts:
  default:
    - app/javascripts/*.js
    - app/mustache_templates/**/*.html.mustache

And a dir structure of:

  • app/mustache_templates/home.html.mustache
  • app/mustache_templates/users/index.html.mustache
  • app/mustache_templates/users/show.html.mustache
  • app/mustache_templates/posts/index.html.mustache
  • app/mustache_templates/posts/show.html.mustache

You would get a jst part:

(function(){
window.JST = window.JST || {};
var template = function(str){var fn = new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push(\''+str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');"); return fn;};
window.JST['home'] = template(...);
window.JST['users'] = {};
window.JST['users']['index'] = template(...);
window.JST['users']['show'] = template(...);
window.JST['posts'] = {};
window.JST['posts']['index'] = template(...);
window.JST['posts']['show'] = template(...);
})();

The problem I see here is what happens if you also have a app/mustache_templates/users.html.mustache file? Perhaps it could be:

(function(){
...
window.JST['home'] = template(...);
window.JST['users/index'] = template(...);
window.JST['users/show'] = template(...);
window.JST['posts/index'] = template(...);
window.JST['posts/show'] = template(...);
})();

asset tag timestamps

I see that Jammit.asset_url takes mtime optionally, but I do not see asset tag timestamps in the urls to packages or to urls in CSS files.

In addition, you could ues the Rails asset tag timestamp cache easily. Something like:

# Generates the server-absolute URL to an asset package.
def self.asset_url(package, extension, suffix=nil)
  source = "/#{package_path}/#{filename(package, extension, suffix)}"
  # ActionView::Helpers::AssetTagHelper#
  rewrite_asset_path(source)
end

Timestamps and packages not generated in production

when I use jammit on Linux64/ruby 1.8.7/rails 2.3.5/java 1.6, the packaging works fine, but when I use Freebsd/ruby 1.8.6/rails 2.3.5/java 1.5 the asset url is generated without timestamps and the package itself is not generated. Is there any issue about ruby version ?

Generated files js/css have current time file times

May be it's possible somehow to do it in that way, that when file is generating it will have max mtime from all the files that it was generated from.

For example, we have two JS files, we generated using jammit a new concatenated and compressed (packaged) .JS file, then we executing jammit again, and this file will have the previous mtime, but not the Time.now (it is how it behave right now).

Extended example and realizations you can find here:
http://github.com/pyromaniac/smart_link_tags/blob/master/lib/smart_link_tags.rb#L41

Thanks,
Dmitry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.