2

While I recognize the dependency handling of sprockets is awesome, I have little knowledge on how to use it properly to make it meet my needs. I'm actually working on a php 5.3 application (lithium framework powered #li3), and I'm beginning the development of a public javascript file meant to send request to our servers and build DOM snippets with the results. Basically, I'm willing to keep my sources organized in modules, each dedicated to one task (ajax request, json parsing, DOM generating etc...), and feel the urge to use sprockets.

BUT how could sprockets be nicelly and somehow transparently integrated to my workflow (I want to avoid CLI tasks every time I modify one of my files) on my local env. ?

I'm sure this is somehow possible, but my knowledge of sprockets doesn't allow me to discover this by myself.

Have been exprimenting with the same problematics ? How could this be solved ? Thanks

pixelboy
  • 739
  • 1
  • 12
  • 36
  • Well, you should actually automatically build your software then. Just run the build, you're local env. is ready to run then. – hakre Oct 10 '11 at 12:27

1 Answers1

2

Generally on your local environment you'll run sprockets as a web server. Generally that will involve adding a config.ru file in you app with something like

require 'sprockets'
map '/assets' do
  environment = Sprockets::Environment.new
  environment.append_path 'app/assets/javascripts'
  environment.append_path 'app/assets/stylesheets'
  run environment
end

and run it with rackup config.ru. This should reload your assets every time you change them.

Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
  • Please, bare with me, but ruby facts and figures is'nt yet my world. I need a little more info : each time I want my assets to get compiled, I have to launch rakup ? The map parameter "binds" whatever passes throuht "assets" will get sprocetized ? – pixelboy Oct 11 '11 at 12:16
  • Nope. When you run rackup it will run a server that will serve your assets at http://localhost:SOME_PORT/assets. Where your assets are actually saved is determined by the `append_path` calls (in this case 'app/assets/javascripts' and 'app/assets/stylesheets'). The server should automatically recompile your assets every time they are requested (some caching does occur, but you don't have to care about that). – Jakub Hampl Oct 12 '11 at 01:02
  • Any chance to find something ( tutorial I mean) about running both rack and apache side by side? If apache requires one of the assets files, rack will take over and handle that request? – pixelboy Oct 12 '11 at 06:18
  • I don't know. I don't use Apache myself. I think that googling about passenger might help you. – Jakub Hampl Oct 12 '11 at 11:20
  • @pixelboy with Ruby, you use an application server like passenger or thin (to serve rack applications) and apache is just used to configure where the application server is running when someone goes to your domain. – Andrew Jun 29 '12 at 18:50
  • @JakubHampl even though I am familiar with Ruby, I don't understand this solution and how it works in both dev and production environments or how it differs. Could you provide a little more explanation to how requesting assets in these environments would work? – Andrew Jun 29 '12 at 18:52