1. Patrick Guido Arminio
  2. django-fb_social_plugins

Commits

Patrick Guido Arminio  committed be177e9

Changed file structure and removed novar tags

  • Participants
  • Parent commits e7b8553
  • Branches default

Comments (0)

Files changed (6)

File fb_social_plugins/__init__.py

Empty file removed.

File fb_social_plugins/templatetags/__init__.py

Empty file removed.

File fb_social_plugins/templatetags/fb_social_plugins.py

-from django import template
-
-register = template.Library()
-
-def parse_arguments(string):
-    """
-    Accepts a string in this format:
-    "arg1=val1, arg2=val2, arg3=val3"
-    and returns something like this:
-    [
-        ('arg1', 'val1'),
-        ('arg2', 'val2'),
-        ('arg3', 'val3'),
-    ]
-    """
-    string = string.replace('"', '')
-    
-    arguments = string.split(',')
-    pars = []
-    
-    for arg in arguments:
-        a = map(lambda x: x.strip(), arg.split('='))
-        pars.append((a[0], a[1]))
-        
-    return pars
-
-def new_or_default(arguments, defaults):
-    """
-    changes values within a default dict with new values or
-    uses the first value from the dict.
-    """
-    for arg, value in arguments:
-        try:
-            if value in defaults[arg]:
-                defaults[arg] = (value, )
-        except KeyError:
-            defaults[arg] = (value, )
-    
-    pars = {}
-    for value in defaults:
-        pars[value] = defaults[value][0]
-    
-    return pars
-
-def check_arguments(token):
-    bits = token.split_contents()[1:]
-    
-    if len(bits) < 1:
-        raise template.TemplateSyntaxError, '%r tag requires at least one argument' % token.contents.split()[0]
-    
-    if len(bits) > 1:
-        if not (bits[1].startswith('"') and bits[1].endswith('"')):
-            raise template.TemplateSyntaxError, '%r second argument should be in quotes' % token.contents.split()[0]
-            
-    return bits
-
-def render_button(args):
-    tpl = '<iframe src="http://www.facebook.com/plugins/like.php?href=%(url)s&amp;layout=%(layout)s&amp;show_faces=%(show_faces)s&amp;width=%(width)s&amp;action=%(verb)s&amp;font=%(font)s&amp;colorscheme=%(color_scheme)s" \
-           scrolling="no" frameborder="0" allowTransparency="true" \
-           style="border:none; overflow:hidden; width:%(width)spx; height: %(height)spx"></iframe>'
-
-    return tpl % args
-
-def render_recommendation(args):
-    tpl = '<iframe src="http://www.facebook.com/plugins/recommendations.php?site=%(url)s&amp;width=%(width)s&amp;height=%(height)s&amp;header=%(header)s&amp;colorscheme=%(color_scheme)s&amp;font=%(font)s&amp;border_color=%(border_color)s" \
-           scrolling="no" frameborder="0" allowTransparency="true" \
-           style="border:none; overflow:hidden; width:%(width)s; height:%(height)s"></iframe>'
-    
-    return tpl % args
-
-def render_actvity_feed(args):
-    tpl = '<iframe src="http://www.facebook.com/plugins/activity.php?site=%(url)s&amp;width=%(width)s&amp;height=%(height)s&amp;header=%(header)s&amp;colorscheme=%(color_scheme)s&amp;font=%(font)s&amp;border_color=%(border_color)s" \
-          scrolling="no" frameborder="0" allowTransparency="true" \
-          style="border:none; overflow:hidden; width:%(width)s; height:%(height)s"></iframe>'
-    
-    return tpl % args
-
-def render_like_box(args):
-    tpl = '<iframe src="http://www.facebook.com/plugins/likebox.php?profile_id=%(profile_id)s&amp;width=%(width)s&amp;height=%(height)s&amp;connections=%(connection)s&amp;stream=%(stream)s&amp;header=%(header)s" \
-          scrolling="no" frameborder="0" allowTransparency="true" \
-          style="border:none; overflow:hidden; width:%(width)s; height:%(height)s"></iframe>'
-    
-    return tpl % args
-     
-class PluginNode(template.Node):
-    def __init__(self, args, function):
-        self.args = args
-        self.function = function
-        
-        try:
-            self.url = self.args['url']
-        except KeyError:
-            try:
-                self.url_var = template.Variable(self.args['url_var'])
-            except template.VariableDoesNotExist:
-                self.url = ''    
-    
-    def render(self, context):
-        try:
-            url = self.url_var.resolve(context)
-        except NameError:
-            if self.url == '':
-                return ''
-        
-        self.args['url'] = url
-
-        return self.function(self.args)
-
-@register.tag(name="like_button")
-def like_button(parser, token, no_var=False):
-    """
-   	This will render facebook like button
-   	
-   	Usage::
-   	
-   	{% load fb_social_plugins %}
-   	{% like_button url_var "args"  %}
-   	
-   	
-   	Parameters::
-   	{% like_button url_var "layout=standard, width=450"  %}
-    
-   	* url: url to like
-   	- layout: layout of the button, standard (shows the button and
-   	  something like 7,550 people like this. Be the first of your friends.) or
-   	  button_count (shows only button and likes count). Default standard
-   	- show_faces: if true shows profile picture under the button. Default false
-   	- width: in pixels, the width of the plugin and the iframe. Default 450
-   	- height: in pixels, the height of the iframe. Default 200
-   	- verb: the verb to display in the button, can be like (default) or recommend
-   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
-   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
-   	- color_scheme: the color scheme of the plugin, can be light (default),
-   	  dark or evil
-   	
-   	"""
-   	
-    bits = check_arguments(token)
-    
-    defaults = {
-        'layout': ('standard', 'button_count'),
-        'show_faces': ('true', 'false'),
-        'verb': ('like', 'recommend'),
-        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
-        'color_scheme': ('light', 'dark', 'evil'),
-    }
-    
-    try:
-        arguments = parse_arguments(bits[1])
-    except IndexError:
-        arguments = []
-    
-    pars = new_or_default(arguments, defaults)
-
-    if no_var:
-        pars['url'] = bits[0]
-    else: 
-        pars['url_var'] = bits[0]
-    
-    if not 'width' in pars.keys():
-        pars['width'] = '450'
-    if not 'height' in pars.keys():
-        pars['height'] = '200'
-
-    return PluginNode(pars, function=render_button)
-
-@register.tag(name="recommendations")
-def recommendations(parser, token, no_var=False):
-    """
-   	This will render facebook recommendations
-
-   	Usage::
-
-   	{% load fb_social_plugins %}
-   	{% recommendations url_var "args"  %}
-
-
-   	Parameters::
-   	{% recommendations url_var "header=false, width=450"  %}
-
-   	* url: url for recommendations
-   	- header: true (default) if you want to show the facebook header
-   	- width: in pixels, the width of the plugin and the iframe. Default 450
-   	- height: in pixels, the height of the iframe. Default 200
-   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
-   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
-   	- color_scheme: the color scheme of the plugin, can be light (default),
-   	  dark or evil
-   	- border_color: color of the borders
-
-   	"""
-
-    bits = check_arguments(token)
-    
-    defaults = {
-        'header': ('true', 'false'),
-        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
-        'color_scheme': ('light', 'dark', 'evil'),
-    }
-
-    try:
-        arguments = parse_arguments(bits[1])
-    except IndexError:
-        arguments = []
-
-    pars = new_or_default(arguments, defaults)
-    
-    if no_var:
-        pars['url'] = bits[0]
-    else: 
-        pars['url_var'] = bits[0]
-
-    if not 'width' in pars.keys():
-        pars['width'] = '450'
-    if not 'height' in pars.keys():
-        pars['height'] = '200'
-    if not 'border_color' in pars.keys():
-        pars['border_color'] = ''
-
-    return PluginNode(pars, function=render_recommendation)
-
-@register.tag(name="activity_feed")
-def activity_feed(parser, token, no_var=False):
-    """
-   	This will render facebook activity feed
-
-   	Usage::
-
-   	{% load fb_social_plugins %}
-   	{% activity_feed url_var "args"  %}
-
-
-   	Parameters::
-   	{% activity_feed url_var "header=false, width=450"  %}
-
-   	* url: url for the activity feed
-   	- header: true (default) if you want to show the facebook header
-   	- width: in pixels, the width of the plugin and the iframe. Default 450
-   	- height: in pixels, the height of the iframe. Default 200
-   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
-   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
-   	- color_scheme: the color scheme of the plugin, can be light (default),
-   	  dark or evil
-   	- border_color: color of the borders
-
-   	"""
-
-    bits = check_arguments(token)
-    
-    defaults = {
-        'header': ('true', 'false'),
-        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
-        'color_scheme': ('light', 'dark', 'evil'),
-    }
-
-    try:
-        arguments = parse_arguments(bits[1])
-    except IndexError:
-        arguments = []
-
-    pars = new_or_default(arguments, defaults)
-    
-    if no_var:
-        pars['url'] = bits[0]
-    else: 
-        pars['url_var'] = bits[0]
-
-    if not 'width' in pars.keys():
-        pars['width'] = '450'
-    if not 'height' in pars.keys():
-        pars['height'] = '200'
-    if not 'border_color' in pars.keys():
-        pars['border_color'] = ''
-
-    return PluginNode(pars, function=render_activity_feed)
-
-@register.tag(name="like_box")
-def like_box(parser, token):
-    """
-   	This will render facebook like box
-
-   	Usage::
-
-   	{% load fb_social_plugins %}
-   	{% like_box profile_id "args"  %}
-
-
-   	Parameters::
-   	{% like_box profile_id "header=false, width=450"  %}
-
-   	* url: url for the activity feed
-   	- header: true (default) if you want to show the facebook header
-   	- width: in pixels, the width of the plugin and the iframe. Default 450
-   	- height: in pixels, the height of the iframe. Default 200
-   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
-   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
-   	- color_scheme: the color scheme of the plugin, can be light (default),
-   	  dark or evil
-   	- border_color: color of the borders
-
-   	"""
-
-    bits = check_arguments(token)
-    
-    defaults = {
-        'header': ('true', 'false'),
-        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
-        'color_scheme': ('light', 'dark', 'evil'),
-    }
-
-    try:
-        arguments = parse_arguments(bits[1])
-    except IndexError:
-        arguments = []
-
-    pars = new_or_default(arguments, defaults)
-    
-    if no_var:
-        pars['url'] = bits[0]
-    else: 
-        pars['url_var'] = bits[0]
-
-    if not 'width' in pars.keys():
-        pars['width'] = '450'
-    if not 'height' in pars.keys():
-        pars['height'] = '200'
-    if not 'border_color' in pars.keys():
-        pars['border_color'] = ''
-
-    return PluginNode(pars, function=render_activity_feed)
-
-"""
-No Var Template Tags
-"""
-
-@register.tag(name="like_button_novar")
-def like_button_novar(parser, token):
-    return like_button(parser, token, no_var=True)
-
-@register.tag(name="recommendations_novar")
-def recommendations_novar(parser, token):
-    return recommendations(parser, token, no_var=True)
-
-@register.tag(name="activity_feed_novar")
-def activity_feed_novar(parser, token):
-    return activity_feed(parser, token, no_var=True)

File fbsocialplugins/__init__.py

Empty file added.

File fbsocialplugins/templatetags/__init__.py

Empty file added.

File fbsocialplugins/templatetags/fb_social_plugins.py

View file
+from django import template
+
+register = template.Library()
+
+def parse_arguments(string):
+    """
+    Accepts a string in this format:
+    "arg1=val1, arg2=val2, arg3=val3"
+    and returns something like this:
+    [
+        ('arg1', 'val1'),
+        ('arg2', 'val2'),
+        ('arg3', 'val3'),
+    ]
+    """
+    string = string.replace('"', '')
+    
+    arguments = string.split(',')
+    pars = []
+    
+    for arg in arguments:
+        a = map(lambda x: x.strip(), arg.split('='))
+        pars.append((a[0], a[1]))
+        
+    return pars
+
+def new_or_default(arguments, defaults):
+    """
+    changes values within a default dict with new values or
+    uses the first value from the dict.
+    """
+    for arg, value in arguments:
+        try:
+            if value in defaults[arg]:
+                defaults[arg] = (value, )
+        except KeyError:
+            defaults[arg] = (value, )
+    
+    pars = {}
+    for value in defaults:
+        pars[value] = defaults[value][0]
+    
+    return pars
+
+def check_arguments(token):
+    bits = token.split_contents()[1:]
+    
+    if len(bits) < 1:
+        raise template.TemplateSyntaxError, '%r tag requires at least one argument' % token.contents.split()[0]
+    
+    if len(bits) > 1:
+        if not (bits[1].startswith('"') and bits[1].endswith('"')):
+            raise template.TemplateSyntaxError, '%r second argument should be in quotes' % token.contents.split()[0]
+            
+    return bits
+
+def render_button(args):
+    tpl = '<iframe src="http://www.facebook.com/plugins/like.php?href=%(url)s&amp;layout=%(layout)s&amp;show_faces=%(show_faces)s&amp;width=%(width)s&amp;action=%(verb)s&amp;font=%(font)s&amp;colorscheme=%(color_scheme)s" \
+           scrolling="no" frameborder="0" allowTransparency="true" \
+           style="border:none; overflow:hidden; width:%(width)spx; height: %(height)spx"></iframe>'
+
+    return tpl % args
+
+def render_recommendation(args):
+    tpl = '<iframe src="http://www.facebook.com/plugins/recommendations.php?site=%(url)s&amp;width=%(width)s&amp;height=%(height)s&amp;header=%(header)s&amp;colorscheme=%(color_scheme)s&amp;font=%(font)s&amp;border_color=%(border_color)s" \
+           scrolling="no" frameborder="0" allowTransparency="true" \
+           style="border:none; overflow:hidden; width:%(width)s; height:%(height)s"></iframe>'
+    
+    return tpl % args
+
+def render_actvity_feed(args):
+    tpl = '<iframe src="http://www.facebook.com/plugins/activity.php?site=%(url)s&amp;width=%(width)s&amp;height=%(height)s&amp;header=%(header)s&amp;colorscheme=%(color_scheme)s&amp;font=%(font)s&amp;border_color=%(border_color)s" \
+          scrolling="no" frameborder="0" allowTransparency="true" \
+          style="border:none; overflow:hidden; width:%(width)s; height:%(height)s"></iframe>'
+    
+    return tpl % args
+
+def render_like_box(args):
+    tpl = '<iframe src="http://www.facebook.com/plugins/likebox.php?profile_id=%(profile_id)s&amp;width=%(width)s&amp;height=%(height)s&amp;connections=%(connection)s&amp;stream=%(stream)s&amp;header=%(header)s" \
+          scrolling="no" frameborder="0" allowTransparency="true" \
+          style="border:none; overflow:hidden; width:%(width)s; height:%(height)s"></iframe>'
+    
+    return tpl % args
+     
+class PluginNode(template.Node):
+    def __init__(self, args, function):
+        self.args = args
+        self.function = function
+        
+        try:
+            self.url = self.args['url']
+        except KeyError:
+            try:
+                self.url_var = template.Variable(self.args['url_var'])
+            except template.VariableDoesNotExist:
+                self.url = ''    
+    
+    def render(self, context):
+        try:
+            url = self.url_var.resolve(context)
+        except NameError:
+            if self.url == '':
+                return ''
+        
+        self.args['url'] = url
+
+        return self.function(self.args)
+
+@register.tag(name="like_button")
+def like_button(parser, token, no_var=False):
+    """
+   	This will render facebook like button
+   	
+   	Usage::
+   	
+   	{% load fb_social_plugins %}
+   	{% like_button url_var "args"  %}
+   	
+   	
+   	Parameters::
+   	{% like_button url_var "layout=standard, width=450"  %}
+    
+   	* url: url to like
+   	- layout: layout of the button, standard (shows the button and
+   	  something like 7,550 people like this. Be the first of your friends.) or
+   	  button_count (shows only button and likes count). Default standard
+   	- show_faces: if true shows profile picture under the button. Default false
+   	- width: in pixels, the width of the plugin and the iframe. Default 450
+   	- height: in pixels, the height of the iframe. Default 200
+   	- verb: the verb to display in the button, can be like (default) or recommend
+   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
+   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
+   	- color_scheme: the color scheme of the plugin, can be light (default),
+   	  dark or evil
+   	
+   	"""
+   	
+    bits = check_arguments(token)
+    
+    defaults = {
+        'layout': ('standard', 'button_count'),
+        'show_faces': ('true', 'false'),
+        'verb': ('like', 'recommend'),
+        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
+        'color_scheme': ('light', 'dark', 'evil'),
+    }
+    
+    try:
+        arguments = parse_arguments(bits[1])
+    except IndexError:
+        arguments = []
+    
+    pars = new_or_default(arguments, defaults)
+
+    if no_var:
+        pars['url'] = bits[0]
+    else: 
+        pars['url_var'] = bits[0]
+    
+    if not 'width' in pars.keys():
+        pars['width'] = '450'
+    if not 'height' in pars.keys():
+        pars['height'] = '200'
+
+    return PluginNode(pars, function=render_button)
+
+@register.tag(name="recommendations")
+def recommendations(parser, token, no_var=False):
+    """
+   	This will render facebook recommendations
+
+   	Usage::
+
+   	{% load fb_social_plugins %}
+   	{% recommendations url_var "args"  %}
+
+
+   	Parameters::
+   	{% recommendations url_var "header=false, width=450"  %}
+
+   	* url: url for recommendations
+   	- header: true (default) if you want to show the facebook header
+   	- width: in pixels, the width of the plugin and the iframe. Default 450
+   	- height: in pixels, the height of the iframe. Default 200
+   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
+   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
+   	- color_scheme: the color scheme of the plugin, can be light (default),
+   	  dark or evil
+   	- border_color: color of the borders
+
+   	"""
+
+    bits = check_arguments(token)
+    
+    defaults = {
+        'header': ('true', 'false'),
+        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
+        'color_scheme': ('light', 'dark', 'evil'),
+    }
+
+    try:
+        arguments = parse_arguments(bits[1])
+    except IndexError:
+        arguments = []
+
+    pars = new_or_default(arguments, defaults)
+    
+    if no_var:
+        pars['url'] = bits[0]
+    else: 
+        pars['url_var'] = bits[0]
+
+    if not 'width' in pars.keys():
+        pars['width'] = '450'
+    if not 'height' in pars.keys():
+        pars['height'] = '200'
+    if not 'border_color' in pars.keys():
+        pars['border_color'] = ''
+
+    return PluginNode(pars, function=render_recommendation)
+
+@register.tag(name="activity_feed")
+def activity_feed(parser, token, no_var=False):
+    """
+   	This will render facebook activity feed
+
+   	Usage::
+
+   	{% load fb_social_plugins %}
+   	{% activity_feed url_var "args"  %}
+
+
+   	Parameters::
+   	{% activity_feed url_var "header=false, width=450"  %}
+
+   	* url: url for the activity feed
+   	- header: true (default) if you want to show the facebook header
+   	- width: in pixels, the width of the plugin and the iframe. Default 450
+   	- height: in pixels, the height of the iframe. Default 200
+   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
+   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
+   	- color_scheme: the color scheme of the plugin, can be light (default),
+   	  dark or evil
+   	- border_color: color of the borders
+
+   	"""
+
+    bits = check_arguments(token)
+    
+    defaults = {
+        'header': ('true', 'false'),
+        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
+        'color_scheme': ('light', 'dark', 'evil'),
+    }
+
+    try:
+        arguments = parse_arguments(bits[1])
+    except IndexError:
+        arguments = []
+
+    pars = new_or_default(arguments, defaults)
+    
+    if no_var:
+        pars['url'] = bits[0]
+    else: 
+        pars['url_var'] = bits[0]
+
+    if not 'width' in pars.keys():
+        pars['width'] = '450'
+    if not 'height' in pars.keys():
+        pars['height'] = '200'
+    if not 'border_color' in pars.keys():
+        pars['border_color'] = ''
+
+    return PluginNode(pars, function=render_activity_feed)
+
+@register.tag(name="like_box")
+def like_box(parser, token):
+    """
+   	This will render facebook like box
+
+   	Usage::
+
+   	{% load fb_social_plugins %}
+   	{% like_box profile_id "args"  %}
+
+
+   	Parameters::
+   	{% like_box profile_id "header=false, width=450"  %}
+
+   	* url: url for the activity feed
+   	- header: true (default) if you want to show the facebook header
+   	- width: in pixels, the width of the plugin and the iframe. Default 450
+   	- height: in pixels, the height of the iframe. Default 200
+   	- font: font of the plugin. You can choose between Arial (default), Lucida Grande, 
+   	  Segoe Ui, Tahoma, Trebuchet Ms or Verdana
+   	- color_scheme: the color scheme of the plugin, can be light (default),
+   	  dark or evil
+   	- border_color: color of the borders
+
+   	"""
+
+    bits = check_arguments(token)
+    
+    defaults = {
+        'header': ('true', 'false'),
+        'font': ('arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'),
+        'color_scheme': ('light', 'dark', 'evil'),
+    }
+
+    try:
+        arguments = parse_arguments(bits[1])
+    except IndexError:
+        arguments = []
+
+    pars = new_or_default(arguments, defaults)
+    
+    if no_var:
+        pars['url'] = bits[0]
+    else: 
+        pars['url_var'] = bits[0]
+
+    if not 'width' in pars.keys():
+        pars['width'] = '450'
+    if not 'height' in pars.keys():
+        pars['height'] = '200'
+    if not 'border_color' in pars.keys():
+        pars['border_color'] = ''
+
+    return PluginNode(pars, function=render_activity_feed)