| CARVIEW |
documentcloud / jammit
- Source
- Commits
- Network (18)
- Issues (7)
- Downloads (21)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
I tried jammit with 3.0pre. Adding Jammit::Routes.draw(map) to the routes doesn't work.
Comments
-
Wrong place to be defining ASSET_ROOT and PUBLIC_ROOT
4 comments Created 2 months ago by railsjediSeems 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".
Comments
initial fix to at least make it not blow up in Rails3. Still pretty lame however...
https://github.com/railsjedi/jammit/commit/495c5426a0719ebb270fbbe2db6d4e5d94f2f70dvandrijevik Tue Apr 13 20:38:18 -0700 2010 | linkRailsjedi,
What is the problem with the existing code in jammit.rb? Your commit does not contain any tests, so I am not sure what problem you are solving with it, or what this issue is about.
Can you provide some examples where the current code would not work?
The issue is loading order. Rails is defined when this lib is being run, however Rails.root is not defined.
I'll add tests and examples soon. This was just a quick patch so I could get it running in my project.
Please log in to comment.Also, I would suggest these values should be class level variables with accessors. Constants really seems to me like the wrong way to define these paths.
-
Rails 2.3.5 reports Jammit missing on Windows, Ruby 1.9.1
7 comments Created about 1 month ago by empire29I 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.4so 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
Comments
The issue is Windows specific -- you must "gem install win32-open3" to use Jammit, and the win32-open3 gem is currently not compatible with Ruby 1.9.1. I rolled back to Ruby 1.8.7 and I was able to install win32-open3 gem and Jammit worked as expected.
Thanks for figuring that out and closing the ticket. It's good to have on the record.
Win32-open3 will never be compatible with Ruby 1.9.1. See: https://djberg96.livejournal.com/172756.html
So is this something that can be fixed and which module needs the fixing? Maybe open4 and popen4 aren't even needed.
I'm having this same problem and I only have one remaining box with 1.8.7 and can't use that as the only build box.
That blog posts suggests that win32-open3 is no longer necessary with Ruby 1.9.1. If you try to run the closure-compiler gem (which is where this issues is occurring), under Windows and Ruby 1.9.1, what do you see happening? Can you paste the error and stacktrace in this ticket?
I don't know if I'm doing this right, but here's my file:
test.rb ->
require 'rubygems'
require 'closure-compiler'
Closure::Compiler.new.compile(File.open('public/javascripts/file.js', 'r'))And output:
$ ruby test.rb --trace c:/ruby/lib/ruby/gems/1.9.1/gems/POpen4-0.1.4/lib/popen4.rb:9:in `require': no such file to load -- win32/ope
n3 (LoadError)
from c:/ruby/lib/ruby/gems/1.9.1/gems/POpen4-0.1.4/lib/popen4.rb:9:in `<top (required)>' from c:/ruby/lib/ruby/gems/1.9.1/gems/closure-compiler-0.2.2/lib/closure/compiler.rb:2:in `require' from c:/ruby/lib/ruby/gems/1.9.1/gems/closure-compiler-0.2.2/lib/closure/compiler.rb:2:in `<top (required)>'
from c:/ruby/lib/ruby/gems/1.9.1/gems/closure-compiler-0.2.2/lib/closure-compiler.rb:1:in `require' from c:/ruby/lib/ruby/gems/1.9.1/gems/closure-compiler-0.2.2/lib/closure-compiler.rb:1:in `<top (required)>'
from test.rb:2:in `require' from test.rb:2:in `<main>'Please log in to comment.It actually appeared to work with yui and 1.9.1 on windows (vista in this case)...good point that I was using closure which I was using because of a bug I was having with 1.8.7 and yui's Compressor...I may log it as a different bug...though I'm caring less about 1.8.7.
-
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 (https://github.com/agibralter/jammit/commits/dev) I just pushed my latest commit:
https://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_dirconfig 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.mustacheAnd 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.mustachefile? 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(...); })();Comments
Please log in to comment.agibralter Thu Apr 29 22:40:03 -0700 2010 | linkAlright so I added a template_base_path config option in my latest commit on the dev branch:
https://github.com/agibralter/jammit/commit/735c78cf459054287e1eeb0f197bb813270ca4d9
I went with the second approach:
window.JST['users/index'] = template(...);Thoughts?
-
Windows paths with spaces don't work with datauri
1 comment Created 27 days ago by triemstrEmbedding 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(EMBEDC:/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.
Comments
-
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
jammitcommand 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: 1dd5a5eabda693707672c8d84e99d450It also symlinks (or copies) each package to have its MD5 checksum as a name:
50bda6102c8dd57a5ead84e99d493776.js@ -> package1.js 50bda6102c8dd57a5ead84e99d493776.js.gz@ -> package1.js.gzThen, 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?
Comments
Please log in to comment. -
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: https://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
.htaccessin 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' https://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: gzipI think a possible solution could be the addition of a configuration option to omit filename extensions in production.
Comments
Please log in to comment.




There are a number of issues that need to be fixed before Jammit will work with Rails 3. Rails' entire plug-in system is being rewritten, and isn't completely finished yet, as far as I can tell. You're supposed to subclass a "Railtie", which provides the appropriate hooks for creating routes, etc.
I took a stab at it a couple of days ago, but couldn't find any documentation or examples of how it's done. If anyone knows how to do it, pointers or patches would be appreciated. Otherwise we'll wait until Rails 3 settles down a bit more.
I hacked up jammit to work on rails 3, but right now it only works as a plugin. If your'e feeling adventurous then type
./script/plugin install git://github.com/samgranieri/jammit.git -r rails3
Caveats: I havent run any tests yet, or tried my branch on rails 2. I also cant seem to install it as a gem.
Once nice thing: on my branch you dont need to insert Jammit::Routes.draw(map) into routes.rb.
Fantastic -- thanks for taking the time to make it work. I've got a couple of questions for you:
What documentation did you follow for the plugin structure? I'd love to take a peek.
What issues did you run into with gem installation? I would imagine that gems would be the preferred way to distribute plugins for Rails 3.
Do you have any thoughts about how we would best structure the changes to preserve Rails 2 compatibility? The mainline gem is going to need to support both for the foreseeable future.
Tests shouldn't be too hard for you to get running -- most of them are for the core compression and command-line client -- less for the Rails integration.
It's a little difficult to tell what changed in the diffs, because the files were moved -- did you have to make any changes to the real functionality for compatibility, or was it all just rearranging furniture?
Thanks again for the contribution!
I basically dug through the railties folder in edge. specifically, these two files: https://bit.ly/88UtQt and https://bit.ly/5HWXFF . Rails 3 plugins appear to resemble engines. They can have their own models, views, controllers, helpers, routes, rake tasks, and generators, in addition to init.rb, install.rb, and a lib folder.
Gem installation does not work at the moment. Yehuda Katz and Carl Lerche removed it with this commit: https://bit.ly/28lv1Z . I don't know what the preferred way to distribute plugins will be with Rails 3.
I'm not entirely sure how to preserve rails 2 compatibility until the issue of bundled gem plugins is resolved. Rails 2 uses config.gem, while Rails 3 (should) do the same with the new bundler, which is really really nice.
OK, I'll take your word for it.
Yeah, I should have broken up the commit I did.. In some ways it's rearranging furniture, with a little functionality work. I moved the controller and helper out of the lib folder and into app/controllers and app/helpers. I then removed the namespace. I moved the routes.rb out of library and into config/routes.rb. I then changed the route to reflect the newer style and was pleased when the route showed up on rake routes without having to include the boilerplate that rails 2 requires. Lastly, I moved the helper inclusion and the Jammit reloading to dependencies file.
Sounds good. I think that the plan will be to leave this ticket open for the time being. Folks who want to use Jammit with Rails 3 should use your branch. As soon as we hear the real story for Rails 3 gems, and Rails 2/3 compatibility, we'll merge and update accordingly.
There's no reason this plugin cant be Rails2/3 compatible. It'll require some surgery, but if you're ok with that I'll try to make things work between both.
This commit:
https://github.com/railsjedi/jammit/commit/a004d37d652eeb225a3dfc79bf85305c80aabfeb
initializes the Jammit routes correctly in Rails3
Verified it still works with Rails2 as well
The changes at https://github.com/railsjedi/jammit so far have made my rails3 project work with jammit. I think the setting paths via constants issue still need to be further resolved, but for now it seems to be working ok.