
import shlex

from reportlab.platypus import Spacer

from flowables import *


def parseRaw(data):
    """Parse and process a simple DSL to handle creation of flowables.

    Supported (can add others on request):

    * PageBreak

    * Spacer width, height

    """
    elements = []
    lines = data.splitlines()
    for line in lines:
        lexer = shlex.shlex(line)
        lexer.whitespace += ','
        tokens = list(lexer)
        command = tokens[0]
        if command == 'PageBreak':
            if len(tokens) == 1:
                elements.append(MyPageBreak())
            else:
                elements.append(MyPageBreak(tokens[1]))
        if command == 'Spacer':
            elements.append(Spacer(int(tokens[1]), int(tokens[2])))
        if command == 'Transition':
            elements.append(Transition(*tokens[1:]))
    return elements


# Looks like this is not used anywhere now:
# def depth(node):
#    if node.parent == None:
#        return 0
#    else:
#        return 1 + depth(node.parent)


import shlex

from reportlab.platypus import Spacer

from flowables import *
from styles import adjustUnits

def parseRaw(data):
    """Parse and process a simple DSL to handle creation of flowables.

    Supported (can add others on request):

    * PageBreak

    * Spacer width, height

    """
    elements = []
    lines = data.splitlines()
    for line in lines:
        lexer = shlex.shlex(line)
        lexer.whitespace += ','
        tokens = list(lexer)
        command = tokens[0]
        if command == 'PageBreak':
            if len(tokens) == 1:
                elements.append(MyPageBreak())
            else:
                elements.append(MyPageBreak(tokens[1]))
        if command == 'Spacer':
            elements.append(Spacer(adjustUnits(tokens[1]), 
                adjustUnits(tokens[2])))
        if command == 'Transition':
            elements.append(Transition(*tokens[1:]))
    return elements


# Looks like this is not used anywhere now:
# def depth(node):
#    if node.parent == None:
#        return 0
#    else:
#        return 1 + depth(node.parent)

Add unit support for spacers
Add unit support for spacers

git-svn-id: 305ad3fa995f01f9ce4b4f46c2a806ba00a97020@779 3777fadb-0f44-0410-9e7f-9d8fa6171d72

  
  import shlex
  
  from reportlab.platypus import Spacer
  
  from flowables import *
- 
+ from styles import adjustUnits
  
  def parseRaw(data):
      """Parse and process a simple DSL to handle creation of flowables.
  
      Supported (can add others on request):
  
      * PageBreak
  
      * Spacer width, height
  
      """
      elements = []
      lines = data.splitlines()
      for line in lines:
          lexer = shlex.shlex(line)
          lexer.whitespace += ','
          tokens = list(lexer)
          command = tokens[0]
          if command == 'PageBreak':
              if len(tokens) == 1:
                  elements.append(MyPageBreak())
              else:
                  elements.append(MyPageBreak(tokens[1]))
          if command == 'Spacer':
-             elements.append(Spacer(int(tokens[1]), int(tokens[2])))
+             elements.append(Spacer(adjustUnits(tokens[1]), 
+                 adjustUnits(tokens[2])))
          if command == 'Transition':
              elements.append(Transition(*tokens[1:]))
      return elements
  
  
  # Looks like this is not used anywhere now:
  # def depth(node):
  #    if node.parent == None:
  #        return 0
  #    else:
  #        return 1 + depth(node.parent)
  
Add unit support for spacers
## Code Before:

import shlex

from reportlab.platypus import Spacer

from flowables import *


def parseRaw(data):
    """Parse and process a simple DSL to handle creation of flowables.

    Supported (can add others on request):

    * PageBreak

    * Spacer width, height

    """
    elements = []
    lines = data.splitlines()
    for line in lines:
        lexer = shlex.shlex(line)
        lexer.whitespace += ','
        tokens = list(lexer)
        command = tokens[0]
        if command == 'PageBreak':
            if len(tokens) == 1:
                elements.append(MyPageBreak())
            else:
                elements.append(MyPageBreak(tokens[1]))
        if command == 'Spacer':
            elements.append(Spacer(int(tokens[1]), int(tokens[2])))
        if command == 'Transition':
            elements.append(Transition(*tokens[1:]))
    return elements


# Looks like this is not used anywhere now:
# def depth(node):
#    if node.parent == None:
#        return 0
#    else:
#        return 1 + depth(node.parent)

## Instruction:
Add unit support for spacers
## Code After:

import shlex

from reportlab.platypus import Spacer

from flowables import *
from styles import adjustUnits

def parseRaw(data):
    """Parse and process a simple DSL to handle creation of flowables.

    Supported (can add others on request):

    * PageBreak

    * Spacer width, height

    """
    elements = []
    lines = data.splitlines()
    for line in lines:
        lexer = shlex.shlex(line)
        lexer.whitespace += ','
        tokens = list(lexer)
        command = tokens[0]
        if command == 'PageBreak':
            if len(tokens) == 1:
                elements.append(MyPageBreak())
            else:
                elements.append(MyPageBreak(tokens[1]))
        if command == 'Spacer':
            elements.append(Spacer(adjustUnits(tokens[1]), 
                adjustUnits(tokens[2])))
        if command == 'Transition':
            elements.append(Transition(*tokens[1:]))
    return elements


# Looks like this is not used anywhere now:
# def depth(node):
#    if node.parent == None:
#        return 0
#    else:
#        return 1 + depth(node.parent)
