lucasefe / themes_for_rails

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

Public folder and already existing views. #15

Closed matheusmoreira closed 13 years ago

matheusmoreira commented 13 years ago

Rather than having to work entirely inside each theme's folder, we should use already existing views and assets inside the public folder as the "default" theme.

Rationale

Applications usually have a default theme and make other themes selectable by the user. If we adapted the themes_for_rails workflow to take that into account we would gain several advantages:

themes_for_rails will not add a view path if a theme isn't valid. The behavior for assets, however, is still undefined.

We could simply not route the request to a specific theme if the user has not set a theme or set it to something like "default".

# lib/generators/themes_for_rails/assets_controller.rb

def asset_path_for(asset_url, asset_prefix)
  path = unless not valid_theme? or theme_name == "default"
           theme_path_for params[:theme]
         else
           'public'
         end
  File.join path, asset_prefix, asset_url # asset_url == params[:asset]
end

Side note

Can't the install generator add themes_for_rails to the list of routes?

# lib/generators/themes_for_rails/install_generator.rb

def add_themes_for_rails_routes
  route "themes_for_rails"
end
lucasefe commented 13 years ago

Sorry for the delay. Crazy days...

First, the Side has been added (not released as a new version yet). Thank your that. You make my job a lot easier.

Regarding the main issue, let me get back to you later, alright? I gotta go now. thanks

Lucas

matheusmoreira commented 13 years ago

I've found that setting the current theme to nil causes the views inside the app directory to be used. If that's where they're located, one can just use the regular asset inclusion methods to achieve what I described above.

Closing; in the end this isn't an issue at all. Thanks for implementing the side note!