#!/usr/bin/env python
# -*- coding: UTF-8 -*-


class Tag(object):
    """Tag class"""

    def __init__(self, content=None):
        self.content = content
        self.attrs = ' '.join(['%s="%s"' % (attr, value)
                               for attr, value in self.attrs])

    def __str__(self):
        return '<%s%s>\n    %s\n</%s>' % (self.name, self.attrs and ' ' + self.attrs or '', self.content, self.name)


class ScriptTag(Tag):
    name = 'script'
    attrs = (('type', 'text/javascript'),)


class AnonymousFunction(object):
    def __init__(self, arguments, content):
        self.arguments = arguments
        self.content = content

    def __str__(self):
        return 'function(%s) { %s }' % (self.arguments, self.content)


class Function(object):

    def __init__(self, name):
        self.name = name
        self.statements = []

    def __str__(self):
        operations = [self.name]
        operations.extend(str(statement) for statement in self.statements)
        return '%s' % ('.'.join(operations),)

    def __getattr__(self, attr):
        self.statements.append(attr)
        return self

    def __call__(self, args=None):
        if args is not None and not isinstance(args, basestring):
            self.statements[-1] = self.statements[-1] + '(%s)' % (args)
        return self


if __name__ == '__main__':
    nv = Function('nv').addGraph(
        AnonymousFunction('', Function('nv').models.pieChart(
            ).x(
                AnonymousFunction('d', 'return d.label;')
            ).y(
                AnonymousFunction('d', 'return d.value;')
            ).showLabels('true')
        )
    )

@@ -1168,48 +1168,53 @@
  if 
-args is not None and not isinstance(args
+isinstance(args, (Function, AnonymousFunction
 , ba
@@ -1222,16 +1222,17 @@
 estring)
+)
 :%0A      
@@ -1295,16 +1295,17 @@
  %25 (args
+,
 )%0A      
@@ -1306,27 +1306,366 @@
         
-return self
+else:%0A            self.statements%5B-1%5D = self.statements%5B-1%5D + '()'%0A        return self%0A%0A%0Aclass Assignment(object):%0A%0A    def __init__(self, key, value, scoped=True):%0A        self.key = key%0A        self.value = value%0A        self.scoped = scoped%0A%0A    def __str__(self):%0A        return '%25s%25s = %25s;' %25 (self.scoped and 'var ' or '', self.key, self.value)
 %0A%0A%0Aif __
@@ -1749,16 +1749,48 @@
 tion('',
+ Assignment('chart',%0A           
  Functio
@@ -1814,16 +1814,20 @@
 eChart(%0A
+    
         
@@ -1843,32 +1843,36 @@
                 
+    
 AnonymousFunctio
@@ -1913,13 +1913,21 @@
     
+   
+ 
 ).y(%0A
+    
     
@@ -1992,16 +1992,20 @@
         
+  
+  
 ).showLa
@@ -2029,12 +2029,39 @@
     
-)%0A
+    )%0A   
     
+ 
 )%0A
+    )%0A    print nv%0A

Add assignment