rstacruz / sinatra-assetpack

Package your assets transparently in Sinatra.
http://ricostacruz.com/sinatra-assetpack/
MIT License
541 stars 97 forks source link

Doesn't compile all listed files, and other issues... #74

Closed rupe closed 11 years ago

rupe commented 11 years ago

Using the following as an example:

js :main, 'js/plugins.js', [
  '/js/plugins.js',
  '/js/script.js',
  '/js/vendor/**/*.js'
]

First off, if I don't include a "target" file (ie just 'js :main, [...]), AP will serve the compiled file into a non-existent "assets" folder.

Next, when listing multiple files, only one gets included (js/plugins.js in my example).

Also, I cannot find any documentation on what exactly the "*" and "" wildcards do. I assume "**" refers to all subfolders?

j15e commented 11 years ago

/path/**/*.something refer to Ruby Dir#glob syntax.

Where are your files js files? Should be in app/js as this is the default serve source for /js

rupe commented 11 years ago

Yes, two files (plugins.js, script.js) are in app/js, along with others in app/js/vendor and 'app/js/bootstrap`.

I have serve "/js", from "app/js"

rupe commented 11 years ago

As mentioned, if I leave out the second argument (destination file) js/plugins.js it serves up an incomplete (doesn't include script.js or any js files in subdirectories) plugins0043535.js, or something like that, in an assets/js subfolder which assetpack created (no such folder structure in my app). Very odd.

Anyway, I want to resolve this before even trying to serve up CSS/LESS files, let alone image files...

rupe commented 11 years ago

Alright, after creating a new fresh RVM gemset I got the js serving to work. Now my problem is with serving up css.

With the following:

css  :style, '/css/style.css', [
  '/css/style.css'
]

where an uncompressed CSS file style.css resides in app/css, after a few minutes waiting for the file to be served up, I get a 'style.25134.css failed to load resource: 500 internal server error' in an empty public/css/style.24134.css with the following log output:

NameError - uninitialized constant Rack::Mime::MIME_TYPES:
    /Users/upe/.rvm/gems/ruby-1.9.3-p327@global/gems/rack-1.5.1/lib/rack/mime.rb:17:in `mime_type'
    /Users/upe/.rvm/gems/ruby-1.9.3-p327@sinatra-wip/gems/sinatra-1.3.4/lib/sinatra/base.rb:1158:in `mime_type'
    /Users/upe/.rvm/gems/ruby-1.9.3-p327@sinatra-wip/gems/sinatra-1.3.4/lib/sinatra/base.rb:256:in `mime_type'
    /Users/upe/.rvm/gems/ruby-1.9.3-p327@sinatra-wip/gems/sinatra-1.3.4/lib/sinatra/base.rb:264:in `content_type'
    /Users/upe/.rvm/gems/ruby-1.9.3-p327@sinatra-wip/gems/sinatra-assetpack-0.1.2/lib/sinatra/assetpack/class_methods.rb:31:in `block (2 levels) in add_compressed_routes!'
   ....

I'm thinking this may be due to the size of the CSS file (256K).

rupe commented 11 years ago

I tried with a smaller CSS file (3K), but still get same error, so size is not the cause.

rupe commented 11 years ago

Ok, I tracked down the cause of the uninitialized constant Rack::Mime::MIME_TYPES: error.

The output (served) filename must be different from input file. I changed:

css :style, '/css/style.css`, [
    '/css/style.css'
]

to: css :styles, '/css/main.css`, [ '/css/style.css' ]

and goodbye error.