lucasefe / themes_for_rails

Theme Support for Rails 3
This very same page :)
MIT License
308 stars 102 forks source link

Asset Pipeline support refs #54 #63

Open jasherai opened 12 years ago

jasherai commented 12 years ago

Add support for the asset pipeline by leveraging it. Automatically add themes to the pipeline when it is in use.

Could you please let me know what you think?

I'm still looking into sprockets to see if we can avoid the extra nested folders required to make the asset pipeline work cleanly.

ksheurs commented 12 years ago

ha i just happened to run that and was coming back here to let you know :)

thanks man, that was it. hope this gets merged in soon!

jasherai commented 12 years ago

awesome! thanks for the feedback!

ksheurs commented 12 years ago

have you noticed issues with calling theme_image_path directly?

example: <%= theme_image_tag 'test.png' %> == "/assets/:theme/images/test-{digest}.png" (correct)

<%= theme_image_path 'test.png' %> == ":theme/images/test-{digest}.png" (incorrect)

i would expect these to render the same paths, right? debugging now..

jasherai commented 12 years ago

hmmm... interesting... I'll have a look at my end too.

I assume you aren't referring to sass/css files here?

ksheurs commented 12 years ago

so far i've just been testing with theme_image_path. with config.assets.digest = false, it works as expected (path being /assets/:theme/images/test.png). if i set config.assets.digest = true, and precompile assets, that's when it breaks (path being :theme/images/test-{digest}.png).

have to run out for a few hours but will be back online later to continue debugging. thanks again!

jasherai commented 12 years ago

I've written this code so that if assets.digest if false it continues to use the original TFR code, the asset pipeline code is only enabled if assets.digest is true. (So you aren't' looking in the wrong place :) )

jasherai commented 12 years ago

I've just tested this locally, and I'm getting the equivalent of "test-{digest}.png" returned. Could you tell me the dir structure of your themes folders? and also any config in your initializer?

ksheurs commented 12 years ago

weird it seems to be working ok now. i was juggling a few things earlier, so maybe something else was off. for reference regardless my config/dir structure is below:

initializers/theme_for_rails.rb -> gist.github.com/3506433

directory structure is: app/assets/themes/:theme/{images|javascripts|stylesheets} app/assets/views/themes/:theme/layouts

ksheurs commented 12 years ago

actually sorry, the issue still exists. if config.assets.digest = false everything is ok w/ theme_image_path, theme_stylesheet_path, and theme_javascript_path.

with config.assets.digest = true all the theme tag functions work properly but the following is returned for theme path functions:

<%= theme_javascript_path 'home' %> --> 'home.js' (expected: /assets/:theme/javascripts/home-{digest}.js)

<%= theme_stylesheet_path 'home' %> --> 'home.css' (expected: /assets/:theme/stylesheets/home-{digest}.css)

<%= theme_image_path 'test.png' %> --> ':theme/images/test-{digest}.png' (expected: /assets/:theme/images/test-{digest}.png)

will continue debugging, but my config is above. thanks!

ksheurs commented 12 years ago

hey guys i came up with this and it seems to be working well for us:

https://github.com/vhx/themes_for_rails/commit/3aedd9cc4b082664287e4d52f4fa06ad6fc6dca1

i started from lucasefe/master and my approach was to stop using routes and send_file for assets and instead use the asset pipeline through rails. i'm guessing the previous reason for using routes was to support assets when the folder structure was not within app/assets/ (ex: app/themes/)?

i still have to get tests working etc but let me know what you think. i'm newer to rails so hopefully this isn't too off.

also fyi - having the gem within :assets group seemed to break in production for us. moving it out fixed.

jasherai commented 12 years ago

I had gone much the same route, you cannot take advantage of the asset pipeline and still use an assets_controller.

What I had done however overrode the asset_controller methods when the asset pipeline is activated but still enabled the original functionality when not.

Regarding the gem in the assets group, do you "initialize_on_precompile" ?

scytacki commented 11 years ago

@ksheurs can you open a pull request so it is easier to discuss your approach?

rxx commented 10 years ago

@jasherai Is this working?

jasherai commented 10 years ago

@mli-max its still working for us... :smile:

let me know if you have any issues or questions... more than happy to help.