This will be an in-depth guide to gemming, focused specifically on DPS classes (much of the advice will hold for other roles, but not all of it).
Basics
Gems are divided up into 8 types: red, orange, yellow, green, blue, purple, prismatic, meta. The first 6 are going to be the primary ones used for gemming. Gem sockets in items are divided into 5 categories: red, yellow, blue, prismatic, meta.
Meta sockets can only take meta gems, and meta gems may only be socketed in meta sockets. Prismatic sockets will take any color (at present, the only prismatic sockets are the ones from an Eternal Beltbuckle and the Blacksmithing-specific wrist and glove socket modifications).
The colored sockets will take any color of gem (excluding meta), but require a gem of a color corresponding to the socket color in order to count towards the socket bonus. Socket bonuses are granted if all of the baseline sockets (ie. excluding Blacksmithing sockets and Beltbuckles) are socketed with gems matching their color. Red, yeloow, and blue gems match only sockets corresponding to their color (though they may be socketed in any socket except a meta socket). Orange, green, and purple gems match two colors of sockets, red/yellow, yellow/blue, and red/blue respectively. They will activate a socket of either color if placed in it.
Each of the primary gem colors (red, yellow, blue) has certain stats assigned to it, and gems will have a balance of stats from all colors present. Red generally has the most direct upgrade stats, yellow tends to have the combat ratings, and blue tends to have the endurance-related stats. A full list of stats obtainable from each color follows:
Red - Strength, Agility, Attack Power, Expertise, Armor Penetration, Spell Power, Parry, Dodge.
Yellow - Intellect, Resilience, Haste, Hit, Crit, Defense
Blue - Stamina, Spirit, mp5, Spell Penetration
Each meta gem has a certain set of gemming requirements in order to be activated (for example, 2 blue gems, or more yellow gems than red gems, etc.). For the purposes of these meta requirements, gems that count for multiple colors count for all of those colors at the same time regardless of which slot they are socketed in. For example, a Relentless Earthsiege Diamond requires 1 red, 1 yellow, and 1 blue gem. Socketing an orange gem will fulfill both the red and yellow gem requirements, even if the orange gem is put into a blue socket. A Siren's Tear or Nightmare's Tear will fulfill all 3 requirements on it's own.
Metas and Socket Bonuses
Almost all dps classes will use one of two different gems: Relentless Earthsiege Diamond or Chaotic Skyflare Diamond. Casters will almost universally use a Chaotic Skyflare. Similarly, agility-based physical dps will almost universally use a Relentless Earthsiege. Strength-based physical dps may use either, and there are pros and cons to each (explained in detail below in the Advanced section). Thus nearly all dps classes will require either 1 or 2 blue gems, and 0 or 1 yellow gems.
As stated above, both the blue and the yellow gem requirement for the Relentless Earthsiege may be filled with a single Nightmare's Tear (which will similarly fit any socket (excluding meta) in your gear), and will fill the first of the two blue gem requirements for the Chaotic Skyflare. The second blue requirement is usually filled with a purple gems, as the red color portion tends to grant a greater benefit than the yellow portion of a green gem (the blue portion will be the same in both cases).
The general rule of thumb for dps classes (see the Advanced section for exceptions) is to socket the minimum number of blue-colored gems needed for your meta gem using your spec's optimal blue gem, which for most is a Nightmare's Tear in one socket and (if a second is needed) a purple gem with Str/Stam, AP/Stam, Agi/Stam, SP/Stam, or SP/Spi, depending on class and spec. All other slots are filled with your spec's best overall gem (see Advanced).
Advanced Gemming
This section relies rather heavily on having accurate stat weights for your spec. Ideal places to gather these are from the forums on
Elitist Jerks,
Rawr's Pawn export, and any simulators being maintained for your class.
For all examples in this section, I will be using the following stat weight scale (which comes from Kahorie's DK Simulator from the EJ forums, using my current gear and spec). I've specifically excluded Hit and Expertise rating, as I always gem for the cap for those stats, so their effective weight is approximately identical to strength (the stat that I'd be replacing, though in reality, hit is worth slightly less then strength on gear and slightly more than strength on gems because the additional yellow gems allow me to get socket bonuses that otherwise would not be worth socketing for the bonus).
Strength - 2.88
Agility - 1.59
Crit - 2.24
Haste - 1.32
ArP - 2.58
To find the ideal gem of each color for your spec, simply add the total overall value of the stats for each eligible gem and pick the one with the highest total value. For example, a 20 strength gem using the above scale would be worth 20 * 2.88 = 57.6 points, while a 10 strength / 10 crit gem would be worth 10 * 2.88 + 10 * 2.24 = 51.2 points, so the 20 strength one would be the superior gem for a red socket color. For a yellow socket, strength is my most valuable stat (so the ideal gem will be an orange Str/- gem, rather than a pure yellow), and crit is the more valuable of the two secondary stats, so Str/Crit is my ideal gem. However, Str/Hit technically ranks higher so long as at least 7 of the hit rating is pre-melee cap.
Evaluating meta gems (for strength-based plate, at least) is somewhat more complex, but not a great deal more difficult. Since the secondary (non-stat) portion of both the Relentless Earthsiege and the Chaotic Skyflare are the same, the only value I need to take into account is the difference between agility and crit. Using the above scale, the Relentless Earthsiege is worth 21 * 1.59 = 33.39 while the Chaotic Skyflare is worth 21 * 2.24 = 47.04.
However, the Relentless Earthsiege requires a single blue gem to activate, while the Chaotic Skyflare requires two. Thus the value for the Relentless Earthsiege must also include the value for the half of the gem that would otherwise be blue. Since that socket will without fail turn into a 20 Strength gem (all blue sockets except those needed for the meta are socketed pure Strength for me, as there's not a socket bonus yet in existence powerful enough to overrule 10 strength), the half that would normally be blue being 10 strength, the Relentless Earthsiege effectively gains an additional 28.8 value, totaling 62.19. Thus for the Chaotic Skyflare to be better, I must have a second item requiring a blue socket with a socket bonus equal in value to at least the difference between the metas, or 15.15 points. This equates to a minimum of 6 strength, 6 ArP, or 7 Crit. If the item with the blue socket also requires one or more yellow gem sockets, the socket bonus value would need to be increased by 6.4 points per yellow socket, or a minimum of 8 strength for a single yellow socket, and it's impossible to out-value if the meta bonus is crit, ArP, or requires more than 1 yellow or blue socket.
This same technique can be applied to items that only require red and yellow sockets (or even just yellow ones). Since pure red gems are almost universally better for dps classes than orange ones, the value of the socket bonus can be used to calculate whether it is worthwhile to socket pure red gems or socket orange gems in yellow slots to gain the socket bonus. For example, my gloves require a single yellow socket for a +4 Strength bonus. The value of the socket bonus is 4 * 2.88 = 11.52. The value of socketing it with a red 20 Str gem would be just the value of the red gem: 57.6 points. The value of socketing it with an orange 10 Str/10 Crit gem would be the value of the gem (51.2) plus the value of the socket bonus, totaling 62.72. Thus I gain more dps benefit from socketing a less powerful Str/Crit gem to gain the socket bonus than I would from socketing the more power pure Str gem and ignoring the socket bonus.
To generalize, the value of the socket bonus must equal a minimum of the difference between your most powerful gem overall (in my case, 20 Str) and the value of the gem required to match the socket in question (in my case, 10 Str/10 Crit), times the number of sockets of that color required (in this case, 1).
As an example, the plate dps chestpiece from Emblems of Frost (Castle Breaker's Battleplate) requires 1 red, 1 yellow, and 1 blue socket for a +8 Strength bonus. The red socket has no value difference if socketed for best overall (pure Str) or for the bonus (also pure Str). The yellow socket sees a decrease of 57.6 - 51.2 = 6.4 if socketed for the bonus, and the blue socket sees a decrease of 57.6 - 28.8 = 28.8. Thus the socket bonus must equal at least the value of those two decreases combined for it to be more valuable to socket for the bonus, in this case at least 35.2 points. The 8 strength socket bonus is worth 23.04, well below the required value, so it is more valuable to socket pure strength and ignore the socket bonus.
Blue gems (including Nightmare's Tears) should be used to gain the most amount of overall stat benefit from gear. If you have more blue sockets than you need blue gems, calculate the total value of the gems and socket bonus for each item both when socketed with the for the socket bonus with the blue gem and socketed for your best overall gem (ignoring the socket bonus). Whichever item shows the the smallest decrease in value from when it was gemmed for best overall gems is the one in which you should socket the blue gem. Generally this will be the item requiring only a single blue socket with the largest amount of your most valuable stat. If you need a second blue gem, repeat this process with all remaining items with a blue socket, excluding the one you used the first blue gem on.
Extrapolation to Other Areas
These same techniques can be applied to other areas of gear optimization as well. For example, there are three available glove enchants for melee dps (excluding Engineers): +44 AP, +20 Hit, and +15 Expertise. Since most melee classes will gem for the hit cap, the value of hit can be weighted the same as Strength. While technically orange -/Hit gems maybe replaced with other orange gems (-/Crit usually), they will only be so replaced if the socket bonus value exceeds the value of the lost additional red-color stat, and can thus be ignored (although this is why the hit on gems is worth slightly more than strength for me, as it allows me to gain yellow sockets that I otherwise wouldn't, effectively allowing me to gain socket bonuses that require yellow sockets with a gem that weights the same as my best overall gem, a pure red. Correspondingly, since it decreases the amount of hit I am required to gem for and therefore decreases the socket bonuses I receive, hit on gear and enchants is slightly decreased in value compared to strength). Thus the 20 hit enchant effectively has a weight of 57.8 points, while the AP enchant has an effective weight of 44 points.
Again, though, a balance point can be found. If I am currently hitcapped with the 20 hit enchant and have a yellow socket on an item that would grant a socket bonus if filled with an orange gem (but the socket bonus is small enough that it isn't worth gemming for Str/Crit), then it would be superior to gem for the hit and use the 44 AP glove enchant if the socket bonus is worth at least the difference between the enchants, in this case 13.8. However, since the socket bonus value required for it to be better to gem Str/Crit for me is only 6.4 points, this situation will never occur, as that yellow socket would have already been filled with a Str/Crit gem (in other words, the value loss of swapping the enchants needs to be less than the value loss of swapping from a my best overall gem to my best yellow gem in order for the situation to even be possible).