rails / sprockets

Rack-based asset packaging system
MIT License
949 stars 789 forks source link

sprockets returning nil #95

Closed Thermatix closed 9 years ago

Thermatix commented 9 years ago

First of all, here's my code as a gist

Sprockets only returns nil, I've done this

 settings.assets.instance_exec(file_name,extention) do |file_name,extention|
    puts 'assets'
    puts @assets
    @assets[cache_key_for("#{file_name}#{extention}", {bundle: true})]
end

To see what files sprockets has and @assets is just {}

I know however that file name is being correctly passed becuase:

puts params[:captures].to_s # in my asset routes output
  #=> ["application", ".css"]
  #=> ["application", ".js"]

It also doesn't raise any errors.

I don't know what's wrong or how to fix this, what do I do?

schneems commented 9 years ago

What version of sprockets are you using and was this working before?

Thermatix commented 9 years ago

I'm currently using sprockets "2.12.4", I have no choice but to use this older version because a library I want to use (react.rb) won't work with sprockets "3.0.0" or above and "2.12.4" is the highest version I can use.

And it was never working :(

schneems commented 9 years ago

Thanks for the report can you give me an example github repo with a Gemfile and some assets that I can clone and run to reproduce the problem?

Thermatix commented 9 years ago

If you take out the Registry line and then just require + include the file, it should just work in a normal sinatra app, umm but an actual repo will have to wait as I'm about to leave work.

The gem version are "sinatra", "1.4.6" "sprockets", "2.12.4" "sass", "3.4.13" "yui-compressor", "0.12.0" "opal", "~> 0.6" "react.rb", "~> 0.3"

I can try building a small micro project for this tomorrow.

EDIT:

Here's a link to the repo you asked for:https://github.com/Thermatix/sprockets_problem just run executable from the command line and it should start the server.

EDIT: I updated the constraining library "reactrb" to the react-v0.13 branch which allowed me to install sprockets 3.3.0 and I ran the example again and yet I'm still having the same issue, sprockets is just returning nil for everything without erroring.

One difference however is that before puts @assets was returning {} now it's not returning anything, just nil most probably.

EDIT:

Even if I take out the opal stuff, it still just responds with nil, so It's not Opal that's causing this.

EDIT:

I copied what sinatra_asset_pipeline does and I changed the prock to this:


    @get_asset = Proc.new do |file_name,extention,asset_type=nil|
        content_type mime_types[extention]
        # settings.assets.instance_exec do 
        #   puts 'assets'
        #   puts @assets
        # end
        path = [settings.root,settings.asset_folder,asset_type,file_name + extention].compact.join('/')
        env_sprockets = request.env.dup
        env_sprockets['PATH_INFO'] = path
        puts path
        # puts env_sprockets['PATH_INFO']
        settings.assets.call env_sprockets
    end

It's actually now erroring out with a 404 (not good but at least it's doing something).

EDIT: Ok, so after several re-factors I got It working although I need to manually add the stylesheets folder path to the sass load path for it to find the stylesheets, and js code I've added to a opal file isn't being executed , other then that it's working.