ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

Custom style (css) per project (Feature #1017)


Added by Fabio Torchetti at 2012-05-22 01:48 pm. Updated at 2012-06-21 10:32 am.


Status:Closed Start date:2012-05-22
Priority:Normal Due date:
Assignee:Felix Schäfer % Done:

0%

Category:Themes
Target version:3.3.0
Remote issue URL: Affected version:

Description

Hi,

one of my clients asked if we could change the logo and some of the style of the projects we are developing for him, I did a quick search and couldn't find anything to do this. I created a quick patch that we have been using for a while and it seems to work fine, what it does is quite straight forward:

- If the page we are serving is a project (@project is defined)
- AND there is a project related css ( under public/stylesheets/project/<project-id>/project.css )
- the project css is included in the page
cheers,
Fabio

custom-project-css.patch (913 Bytes) Fabio Torchetti, 2012-05-22 01:48 pm

custom-project-style-v2.patch - New patch version - fixes an issue when creating projects (836 Bytes) Fabio Torchetti, 2012-05-24 04:34 pm


Associated revisions

Revision 8b9fb29d
Added by Jean-Philippe Lang at 2008-04-13 02:25 pm

Translation updates (closes #1010, #1017, #1047):
  • Finnish (Antti Perkiömäki)
  • Spanish (Gumer Coronel)
  • Czech (Maxim KruÅ¡ina)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1347 e93f8b46-1217-0410-a6f0-8f06a7374b81

Revision 2f215224
Added by Felix Schäfer at 2012-06-21 10:28 am

Enable project-specific css #1017

History

Updated by Fabio Torchetti at 2012-05-24 04:34 pm

Changed the patch - very nasty bug found in such little code: when creating a new project @project is defined, but not @project.identifier. Second try to a patch.

Updated by Vladislav Poluhin at 2012-05-27 08:42 am

File's check in template? Is that normal in rails?

Updated by Fabio Torchetti at 2012-05-28 01:32 pm

Hi Vladislav,

my understanding is that something under "app/views/layouts" is not technically a template, but a view. I'll give it to you: there seems to be very little difference between the two, but I believe - and as anyone's beliefs mine is subject to scrutiny and possible fallacy as well - that the view is allowed to include some logic in it. In this case the logic is quite simple: include styles that are present. Of course you could dumb the view down and include the files, whether they exist or not, but that wouldn't be clean, since it would make the browser fetch a non existent resource every time it accesses a project without custom templates.

By including the check in the view, you move the check from handling a non existing file to the place that is including it.

just my 2€/cents

Updated by Felix Schäfer at 2012-06-05 03:45 pm

I'm not sure that's something that should go in the core, not in this form anyway. A more idiomatic way would be to add a project-${identifier} to the css classes of the body element, for example in source:/app/helpers/application_helper.rb#L433

  • Description changed from Hi, one of my clients asked if we could change the logo and some of the st... to Hi, one of my clients asked if we could change the logo and some of the sty... More

Updated by Holger Just at 2012-06-09 05:45 pm

Pulling this out of 3.2.0 as it was not fully reviewed on release day.

  • Target version deleted (3.2.0)

Updated by Felix Schäfer at 2012-06-12 09:48 am

I was thinking about that a bit and having project identifiers (potentially a list) in css file or filenames would leak information so we'd need to go with the numeric ids.

I was thinking of something like that:

 1diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
 2index 2ecf967..fcebc5d 100644
 3--- a/app/helpers/application_helper.rb
 4+++ b/app/helpers/application_helper.rb
 5@@ -436,6 +436,7 @@ module ApplicationHelper
 6       css << 'theme-' + theme.name
 7     end
 8
 9+    css << 'project-' + @project.id if @project.present?
10     css << 'controller-' + params[:controller] if params[:controller]
11     css << 'action-' + params[:action] if params[:action]
12     css.join(' ')
13

Holger, any comments? If something like that is good with you I'd prepare a pull request.

  • Status changed from Ready for review to Open

Updated by Felix Schäfer at 2012-06-20 04:34 pm

Fabio, would the proposed solution (adding a class to the body in the form project-my-awesome-project or project-23) work for you? It's a tad more work as you need to create a "full" theme with the added css for the project, but I don't think this should be a problem.

Furthermore: the project-my-awesome-project leaks the identifiers of projects for which you have custom css to the global css file, thus I'd favor project-23, which is a little less "discoverable" for the theme developer as the numerical id of projects isn't used anywhere else (you'd probably have to open a page in the project and inspect the classes of the body) but doesn't leak the identifiers. Fabio, thoughts?

  • Status changed from Open to Needs more information
  • Assignee set to Fabio Torchetti

Updated by Fabio Torchetti at 2012-06-21 09:50 am

I think the project-id tags would be good - I happen to like the "less info is more" approach. The only worry I have is that blindly adding css tags is a bit of HTML bloat that somehow could be avoided, it could be a configuration check "add project-specific css tags" so that projects that don't have custom templates won't need to add css (...and lookups in the css from the browsers).

Anyhow, I think it would be a good solution.

  • Status changed from Needs more information to Ready for review
  • Assignee changed from Fabio Torchetti to Felix Schäfer

Updated by Felix Schäfer at 2012-06-21 10:32 am

Fabio Torchetti wrote:

I think the project-id tags would be good - I happen to like the "less info is more" approach. The only worry I have is that blindly adding css tags is a bit of HTML bloat that somehow could be avoided, it could be a configuration check "add project-specific css tags" so that projects that don't have custom templates won't need to add css (...and lookups in the css from the browsers).

Thanks for the feedback. Regarding a config option: the point of having it as a body class was to reduce complexity, a config option would make it complicated again :-) As for html bloat, as long as it's not a problem I won't worry too much about it.

This solution is probably not the "bestest" possible, but it's available now, we still can improve on it down the road :-)

Committed in 2f21522.

  • Status changed from Ready for review to Closed
  • Target version set to 3.3.0

Also available in: Atom PDF