Exemplo n.º 1
0
    def row(
        self,
        instance,
        cols=1,
        attributes=None,
        id=None,
        Class="row",
        header=None,
        style=None,
        stylesheet=None,
    ):

        id,Class=validate_names(id,Class)

        container = Node("div", attributes=attributes, id=id, Class=["row"])

        for i in range(0, cols):

            container.add(self.column(instance))

        return container
Exemplo n.º 2
0
    def table(
        self,
        instance,
        data,
        name="",
        attributes=None,
        id=None,
        Class=None,
        header_attributes=None,
        header_style=None,
        header_id=None,
        header_class=None,
        row_attributes=None,
        row_style=None,
        row_id=None,
        row_class=None,
        data_attributes=None,
        data_style=None,
        data_id=None,
        data_class=None,
        style=None,
        stylesheet=None,
        centerize=False,
    ):

        id,Class=validate_names(id,Class)
        row_id,row_class=validate_names(row_id,row_class)
        data_id,data_class=validate_names(data_id,data_class)

        if "table" in instance.content:

            instance.content["table"] += 1

        else:

            instance.content["table"] = 1

        if not stylesheet:

            if instance.def_stylesheet:

                stylesheet = instance.def_stylesheet

        Table = Node(
            "table",
            attributes=attributes,
            stylesheet=stylesheet,
            style=style,
            id=id,
            Class=None,
            centerize=centerize,
        )

        columns = []

        if header_attributes is None:

            header_attributes = row_attributes

        for headers in data:

            columns.append(headers)

        thead = Node("thead")
        print(id)
        header = Node("tr", attributes=row_attributes, id=id[0] + "-" + "row")

        for head in columns:

            header.add(
                Node(
                    "th",
                    attributes=header_attributes,
                    style=header_style,
                    stylesheet=stylesheet,
                    content=str(head),
                    id=id[0] + "-" + "head",
                )
            )

        thead.add(header)
        Table.add(thead)

        for index in data.index:
            row = Node(
                "tr",
                attributes=row_attributes,
                style=row_style,
                stylesheet=stylesheet,
                Class=Class,
                id=[id[0] + "-" + "rows"],
            )
            for column in list(data):

                row.add(
                    Node(
                        "td",
                        attributes=data_attributes,
                        content=str(data[column][index]),
                        style=data_style,
                        stylesheet=stylesheet,
                        id=[id[0] + "-" + "data"],
                    )
                )

            Table.add(row)

        return Table
Exemplo n.º 3
0
class Page:
    """The main class to be used to interact the componenets of PyReData"
    
       Args:
            
            name[str]: Name of the page
            template:  Template of the given webpage
            
    """
    def __init__(
        self,
        name,
        template="",
        style="",
        stylesheets=[],
        def_stylesheet=None,
        scripts=[],
    ):

        self.name = name
        self.stack = Tree("html", name=self.name)
        self.template = []
        self.stylesheets = stylesheets
        self.def_stylesheet = def_stylesheet
        self.scripts = scripts

        attributes = []
        if style:

            attributes = [["style", style]]

        self.widgets = Widgets()
        self.html = Node("html")
        self.head = Node("head")
        self.body = Node("body", attributes=attributes)
        title = Node("title", content="Hello Wo")
        self.html.add(self.head)
        self.html.add(self.body)
        self.head.add(title)
        self.init_head()
        self.content = {}

    def print_stack(self):

        for node in self.stack:

            print(node)

    def load_template(self):
        """Loads template for given webpage"""

        pass

    def init_head(self):
        """Initializes head of given webpage"""

        for style in self.stylesheets:

            self.head.add(
                Node("link",
                     attributes=[["rel", "stylesheet"], ["href", style]]))

        for link in self.scripts:

            self.head.add(Node("script", attributes=[["src", link]]))

    def addtable(self, data):

        man = self.widgets
        self.stack.writestack(man.table(data))

    def render(self,
               element,
               name,
               id="",
               Class="",
               content="",
               attributes=""):
        """Renders element on the webpage
        
        Args:
            
            element[Container,Item]: The element to be rendered.
            name[str]: Name given to the element
            
        """
        print("Writing")
        self.body.add(element)

    def compile(self):
        """Writes the stack as a HTML file"""

        self.stack.writestack(self.html)