I wish I knew how to make your life easier

I wish I knew how to make your life easier

by Tim Hunt -
Number of replies: 11
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This discussion is spun out of MDL-23664.

Basically, when I am developing a new feature, I don't really know what class names I should use, so that themes can display the feature nicely, so I am asking for guidance. That is, please can someone update and expand Development:XHTML#Styling.

There are two options that would be easy to explain, but which I think are clearly wrong.

  1. wrap every bit of functionality in <div class="generalbox">, because that kind-of looks quite nice. This gives no way to style different features differently.
  2. wrap every bit of functionality in <div class="myfeatureXYZ">. That means themes have to change for every new features.

We need some sort of middle way, but I am not quite sure what that is. I think the middle ground needs to be chosen to make it is easy as possible to create themes that style things the way theme designers want them styled, so I think the people in this forum (not me) are best placed to decide where in the middle-ground best practice lies.

The other question is, who is responsible for making sure the new feature looks nice in every theme. This time, I think that there are two extreme positions that are clearly right, but there is also another middle area which is not clear to me.

  1. the feature developer should add the any extra CSS required to the base theme, to make sure the feature basically looks OK, but these style rules should not involve any colour or anything else too specific.
  2. exactly how the features looks in a specific theme like binarius or boxxie etc. is the responsibility of the theme developer.

The question is, who is responsible for updating canvas? I am happy if the answer to that is the feature developer (although a more skilled theme developer would always be welcome to improve any canvas CSS I write) however, again I think this needs to be made clear on Development:XHTML#Styling.

Thanks for considering this. I find really annoying at the moment when I am writing code. I want to do the 'right' thing, but I don't know what that is. So I guess, and if all features developers guess, we will just end up with a mess that is hard to style. Oh, ... hmm ... that sounds a bit familiar wink

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: I wish I knew how to make your life easier

by Frank Ralf -
Hi Tim,

Semantic DIV IDs? might show a solution to the first problem how to have one's cake and eat it by generously using more specific ids and more general class names. That way a themer can either aim for a specific feature's look or for a general look of similar features.

Just my 2 € cents wink
Frank
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: I wish I knew how to make your life easier

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Might I say at the start of this Tim that the Base theme and the Standard theme are looking good so far, so thanks for taking the time to improve them.

As for ID's & Classes I think what Frank has to say is about right.

What I do detest are the borders around the general boxes which use the color specified in the body. If we are to see borders around boxes, can the color be element specific? And while I am at it, the fact that YUI jumps in at ever opportunity is a pain in the proverbial! No matter the ID or CLASS YUI adds another as long as your arm! What's that all about?

As for updating CANVAS I would be pleased if that theme got dropped.

In reply to Tim Hunt

Re: I wish I knew how to make your life easier

by Sam Hemelryk -
Hi all,

This is an interesting one, and I bet every developer & designer has his or her own opinions and preferences.

Myself I heavily favour classes over ID's, and I prefer to use a dual classing system.
Before you ask I'll explain it all here.

First up the easy part, avoid ID's except where the generated content needs to be 100% specific, normally this is only required when JavaScript is on the scene.
Thanks to JS libraries such as YUI navigating the DOM using classes is more accessible but it can still be a nightmare and it's hell of performance hole.
The backup to that is that Moodle is huge, and contrib doubly so. There have been some nasty ID clashes in the past which of course breaks XHTML and sometimes JavaScript as well. If we went with an ID solution we would need to create some sort of structure for creating ID's so that people create unique id's and don't create id's such as 'dock' ;)

The dual classing system I prefer; Lets say I want to print a list of a forum posts on a new page I am creating within the forum module. So to start with I have a ul + n*li. The first thing I am going to do is wrap it in a div because a list is structure not design.
I want the list to look like a normal container on the page, so I add the class 'generalbox'. But I don't stop there because generalbox tells me nothing about the container just that it is one (duh!) so I add a second class 'forum-user-posts' which describes the element.
The next step is to add content descriptive classes, an example for this scenario is 'noposts' which could be added to the container if the user has not made any posts.
At the end I have added three classes of classes:
  • A class to give the element the most basic of general looks.
  • A class to describe the nature of the element.
  • 0..n classes that describe the content or state of the element.


Next for styling, I try to never add styles to the generic classes (generalbox) I always try to style on the specific class ('forumposts').
The general class needs to be kept that, styling it can be dangerous as you can never be sure what the future for the page holds, and it's likely at some point or another more generalboxs are going to be added to the content, perhaps even by JS and your CSS is going to need to tidied up by an enraged designer or developer.
The only thing to keep in mind with this system is good old IE6 (if you still care about that) because when processing a chain of classes in CSS IE6 only processes the first two classes in the chain. Because of this I try to avoid using cumulative descriptive classes, usually I can get around this through wrapping the element in additional descriptive structure or through restructuring the plan I had for classes.

The final thing I try to do (although I forget to often) is to describe the id and class structure in the CSS comments or in a doc somewhere so that designers can get an instant feel for what is going on rather than having to try to generate all possible states for a system, or worse yet refer to code.
This is probably one of the biggest things we could do for designers, as a developer I have no problem with reviewing code to work out the structure of a system but I bet that's not how most people feel.

Anyway enough about what I do, what could be done to create an overall better system.
Well I think asking all developers to become designers as well is about as silly as asking all designers to become developers. Because of this the structure that gets created around the place is likely never right the first time ( I realise of course right is the wrong word to use ).
I think the biggest problems we have at the moment are that we have no guidelines for coming up with class names and id's, and second that the structure we as developers create is often lost the moment we commit it with only the creator of the code actually knowing what's there and/or possible.
It's such an important part of design and I think often we don't give it any prior thought or spec it in proposals.

So to combat that:
  • Come up with some guidelines/conventions for naming and look to improve sections starting probably with the 2.1 push on plugins.
  • Start promoting the ideas of outlining UI in proposals... yes often it changes but we can update and continue documenting and it does give us a chance to gather feedback from the designers well before we get entrenched in the code we are creating.
  • Come up with a system of documenting the structure we develop! I don't really know where it would be best to organise this information? In the code as comments or CSS files, or within the docs? Either way somewhere where it can be reviewed and commented on.


As for theme maintainability, that's a whole other barrel of fish!
I think/hope using the general classes to create only the general look aids that, if the theme styles them liberally things should look OK in most cases.
Then making sure that the CSS for the base theme (or the plugins styles.css file) contains liberal CSS as well helps ensure that the general look is maintained.
As for canvas, it is already used everywhere, but it does extend base. So provided you don't try to do anything more than basic you shouldn't need to specifically add anything to canvas. It should be covering you with it's general styles.
But then, who is responsible for the 20 theme's that are/will be in core and making sure that they look right? The developer in me instantly says the theme designer/creator. Why, because I've seen the hideous mess developers who aren't designers can create! A couple of bad lines of CSS can cause a lot of chaos.
The designer in me argues that I have no clue what has changed, what the new structure is, and that there is no way to even know things have changed.
The reality is no one wants to, developers would need to skill up, designers don't really have support systems for it.
Of course once 2.0 comes out things won't change quite so often hopefully.

Anyway thats my thoughts on the matter.

Cheers
Sam
In reply to Sam Hemelryk

Re: I wish I knew how to make your life easier

by Dan Humpherson -

Does anyone design there plugin/mod/resource/activity before you start actually coding the finished product.

Imean design from a usability perspective, do you lay all the elements your creating out on screen and find the best layout for all your buttons, drop downs, text fields etc..

Do you visualise the flow of how the screens/pages your creating fit together.

Personal view is that if developoers started doing this and working towards a 'standard' it would make it much easier to start naming elements and thus increase the power of thememing.

Whats wrong with creating an ID of 'Dock' if its unique?

In reply to Dan Humpherson

Re: I wish I knew how to make your life easier

by Sam Hemelryk -
Hi Dan,

I certainly don't think there is enough done on design planning, laying out out the elements on the screen and such.
As for page flow, within HQ yes I think this is usually looked into. It would be great to say that it is always there but I highly doubt it is, in fact I'm certain it's not.

The standard is likely the key to success. But developers cannot, and more importantly should not create the standard alone because without a combined effort it'd be very likely the standard were flawed.

As for the dock example, I picked that as an example because it was the first example that sprung to mind of a carelessly picked id, not because it is not unique, but because I didn't check it was!
The dock isn't a new idea, the style of display I choose to create with it may be?
In hindsight I should have certainly checked that the ID was unique, especially with everything going on in YUI, in fact a quick search shows that while YUI doesn't use it directly they do use it (the id dock) in examples they have and I know how developers love to cut and paste.
At the end of the day using dock is probably fine, a quick search of Moodle contrib shows up only the subject dock you created Dan, and I see you used #dock2 so we are safe ;) but it is certainly still one area that could be improved.
Hehe I know if Petr were to look here he'd probably be telling us to use the frankenstyle name scheme he uses elsewhere throughout Moodle.

Anyway enough from me.

Cheers
Sam
In reply to Sam Hemelryk

Re: I wish I knew how to make your life easier

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I like the way that Balsamiq is integrated with the tracker. That is so nice to use that I always try to sketch the UI I am trying to build before I build it.

However, experience has also taught me that up front, when you are doing your UI sketch, you don't know everything. Asking other people to review catches some things you miss, but not everything). You learn a lot during implementation, and when the first uses try to use the system, so you have to be prepared to change from your initial designs as you learn things.

In reply to Sam Hemelryk

Re: I wish I knew how to make your life easier

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sam, as I said above, the problem with specific classes on everything (for example .quizintro, .forumintro) is that it means that themes have to have style rules for each individual activity. We need some consistent names for common things, so you can write a new activity module that can just be plugged in, and where most of the bits will look good using existing style rules from the theme. I think .generalbox is too vague, or at least has been abused in too many places. .activityintro might be OK, or might be a bit too specific.

Of course, we don't want to break existing themes (again, in 2.1) so whatever rules we try to define have to try to maintain continuity with the past.

In reply to Tim Hunt

Re: I wish I knew how to make your life easier

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I was reading MDL-23664 yeaterday, and seeing the reference to the border collapsing to a line accross the top of the quiz, brought to mind a post I made here, some months ago, which highlighted the fact that if you add...

border: 5px solid red;

to the CSS for #page in Base theme, you get a 10px solid red line right across the top of the page, no matter if you are viewing the frontpage or a general page. The fix for this is just adding a 'clearfix' div just above the closing div tag for page at the bottom of frontpage.php and general.php in base theme, but no one picked up on the idea. Surely fixing this in Base theme will save time for others when themeing with 'Base' as the parent theme.

Perhaps it might be an idea if we had a set of 'feature-widgit' styles each with it's own set of unique IDs and 'feature-widgit' prefixed classes. These could then be dropped into, and work with, any theme.

Guidlines and Standards for developers are a 'must have' which will help keep things tidy.

Mary

In reply to Tim Hunt

Re: I wish I knew how to make your life easier

by Paul Nicholls -

Hi Tim,
That's the beauty of dual-classing - you have a generic class that the theme will style, providing some degree of styling so that it hopefully won't look too bad, and the plugin's own CSS should then cover the plugin-specific classes.  Each element draws from up to two stylesheets - the theme's styles for the generic class and the plugin's for the plugin-specific ones.

Ideally, things like background colours, border styles, etc should be inherited from the theme (via the generic classes) - but you're certainly right that it could require some overrides in the theme's styles to make the plugin fit in 100% with the theme in some cases.  I don't really see any way around that, as different plugins have different structures which need to have specific layouts or appearances which won't necessarily have parallels in other plugins (or in anything in core), so without theme designers being required to be psychic, I'm not really sure what could be done... perhaps we need a good, well-defined set of generic colours attached to each theme which can be used in stylesheets via a token replacement system - plugins could then use those if they need a colour to suit a specific situation (similar to the [[pix:theme|imgname]] tokens).

In reply to Sam Hemelryk

Re: I wish I knew how to make your life easier

by Frank Ralf -
Just for illustration purposes a body-tag from a Drupal page:

<body class="not-front logged-in node-type-forum one-sidebar sidebar-left page-node-31715 section-node">

"page-node-31715" is actually a unique identifier and could very well be an id but using a class instead prevents clashes if the same value is accidentally used somewhere else on the page.
In reply to Frank Ralf

Re: I wish I knew how to make your life easier

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Have you looked at the body tag in Moodle 2.0 for comparison? Or even 1.9 for that matter. We are already doing most of this.