<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -50,20 +50,25 @@ For example, consider the simplest situation where you wanted to display AdSense
 Now lets say you want to display a link to an Amazon Affiliate's search results page when targetted on a list containing ``django`` (and otherwise default back to an Adsense ad unit):
 
     MONETIZE_TARGET = {
-        'django':['django_monetize/amazon_search.html','Django books','Buy some Django books today!'],
+        'django':['django_monetize/amazon_search.html',('amazon_search_terms','Django books'),('amazon_search_title','Buy some Django books today!')],
     }
     MONETIZE_DEFAULT = 'django_monetize/adsense_ad_unit.html'
 
+If you specify a monetization method using a list/tuple instead of a string, then the zeroth value is the template's string, and the remaining values are 2-tuples (or 2-lists) containing a key and a value, which are used to overwrite values in ``MONETIZE_CONTEXT`` for this specfic monetization.
+
 Now lets say you have three ad slots on your page: 'header','footer', and 'side'. You can customize the contents of each slot for each term. For this example, lets not show any ads by default.
 
     MONETIZE_TARGET = {
         'django':{
             'header':'django_monetize/adsense_ad_unit.html',
             'footer':'django_monetize/slicehost_referral.html',
-	    # if you don't specify an ad for a slot, it uses the default ad instead
+            None:'django_monetize/dreamhost_referral.html',
+            # Value for None specifies value for non-listed slots.
+	    # if you don't specify an ad for a slot, and don't specify
+            # a value default, then it won't display an ad.
         },
     }
-    MONETIZE_DEFAULT = None
+    MONETIZE_DEFAULT = False
 
 Specifying an ad you either pass a string with the ads template, or you pass a list (or tuple) where the zeroth object is the template's string and the other objects are parameters for the rendering function. Whether or not a specific monetization option takes parameters varies, so you'll have to consult the documentation (or the source, if documentation is lacking).
 </diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -5,13 +5,13 @@ Usage (from within a template):
 
     {% load monetize %}
     
-    {% monetize-slot &quot;top&quot; object.tags %}
+    {% monetize_slot &quot;top&quot; object.tags %}
 
     &lt;p&gt; Some content. &lt;/p&gt;
-    {% monetize-slot &quot;bottom&quot; request.META.HTTP_USER_AGENT %}
+    {% monetize_slot &quot;bottom&quot; request.META.HTTP_USER_AGENT %}
 
     &lt;div class=&quot;sidebar&quot;&gt;
-    {% monetize-slot &quot;side bar&quot; request.META object.tags &quot;django&quot; %}
+    {% monetize_slot &quot;side bar&quot; request.META object.tags &quot;django&quot; %}
     &lt;/div&gt;
 
 
@@ -41,3 +41,106 @@ The first value matching a targeting value will be used. Values will be matched
 Don't be fooled by the above example: ``django_monetize`` doesn't help you inject ``request`` into your templates' context; you'll have to handle that yourself.
 &quot;&quot;&quot;
 
+from django import template
+from django.con import settings
+
+register = template.Library()
+
+@register.tag(name=&quot;monetize_slot&quot;)
+def monetize_slot(parser, token):
+    'Template tag for displaying a monetization option in a slot.'
+    lst = token.split_contents()
+    return MonetizeSlotNode(lst[1:])
+
+
+class MonetizeSlotNode(template.Node):
+    def __init__(self, *vals):
+        if len(vals) &gt; 0:
+            self.slot = vals[0]
+            self.params = vals[1:]
+        else:
+            self.slot = None
+            self.params = ()
+
+    def render(self,context):
+        'Apply targeting and render monetization option for value/slot combo.'
+        target = self.acquire_target(self.params,context)
+        return self.target(target,self.slot,context)
+
+    def acquire_target(self,params,context):
+        'Go through parameters and try to find a valid targeting parameter.'
+        logic_dict = getattr(settings,'MONETIZE_TARGET',{})
+
+        for param in params:
+            try:
+                param = template.resolve_variable(param,context)
+            except template.VariableDoesNotExist:
+                pass
+            if type(param) == list or type(param) == tuple):
+                for x in param:
+                    x = unicode(x)
+                    if logic_dict.has_key(x):
+                        return x
+            elif type(param) == dict:
+                for x in dict.iteritems():
+                    x = unicode(x)
+                    if logic_dict.has_key(x):
+                        return x
+            else:
+                param = unicode(param)
+                if logic_dict.has_key(param):
+                    return param
+
+        return None
+
+    def target(self,value,slot,context):
+        '''
+        Returns the rendered text for 'value'. 'value' should be
+        the output of the 'choose_target' method.
+
+        Also be aware the distinction being made between
+        False and None. None refers to the concept of using
+        the default monetization option, while False refers
+        to not using a monetization option.
+        '''
+        logic_dict = getattr(settings,'MONETIZE_TARGET',{})
+        if logic_dict.has_key(value):
+            logic = logic_dict[value]
+        else:
+            logic = getattr(setting,&quot;MONETIZE_DEFAULT&quot;,False)
+
+        # Deconstruct slot specific logic from dict.
+        if type(logic) == dict:
+            if logic.has_key(slot):
+                # Check for slot specific logic.
+                logic = logic[slot]
+            elif logic.has_key(None):
+                # Check for value specific default logic.
+                logic = logic[None]
+            else:
+                # Otherwise display nothing.
+                logic = False
+
+        if type(logic) == tuple or type(logic) == list:
+            context_dict = getattr(settings.'MONETIZE_CONTEXT',{}).copy()
+            if len(logic) == 0:
+                logic = False
+            else:
+                # load extra context from list
+                for key,val in logic[1:]:
+                    context_dict[key] = val
+        else:
+            context_dict = getattr(settings.'MONETIZE_CONTEXT',{})
+
+        # At this point ``logic`` should be a string for a template, or False
+
+        
+        if logic == False:
+            # False means no monetization option, so return empty string.
+            rendered = u&quot;&quot;
+        else:           
+            new_context = Context(context_dict,context.autoescape)
+            t = template.loader.get_template(logic)
+            rendered = t.render(new_context)
+
+        return rendered</diff>
      <filename>django_monetize/templatetags/monetize.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6004d5f45f5db309b2cefb0f0cd511dbe43805d5</id>
    </parent>
  </parents>
  <author>
    <name>Will Larson</name>
    <email>lethain@gmail.com</email>
  </author>
  <url>http://github.com/lethain/django-monetize/commit/7592cafc7385b3f3f9c7565374fab1a0b9c3e7c8</url>
  <id>7592cafc7385b3f3f9c7565374fab1a0b9c3e7c8</id>
  <committed-date>2008-08-29T07:36:01-07:00</committed-date>
  <authored-date>2008-08-29T07:36:01-07:00</authored-date>
  <message>Initial implementation of monetize.py, the templatetag library that supports django_monetize, and also updated README to reflect minor change in usage.</message>
  <tree>3b07cd39badf176f603e32a7a2654a3592b0f6e9</tree>
  <committer>
    <name>Will Larson</name>
    <email>lethain@gmail.com</email>
  </committer>
</commit>
