Exemplo n.º 1
0
    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]]))
Exemplo n.º 2
0
    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 = {}
Exemplo n.º 3
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.º 4
0
    def image(
        self,
        instance,
        path,
        name="",
        attributes=None,
        id=None,
        Class=None,
        style=None,
        centerize=False,
        stylesheet=None,
        style_id=None,
        style_class=None,
    ):

        id,Class=validate_names(id,Class)

        if "img" in instance.content:

            instance.content["img"] += 1

        else:

            instance.content["img"] = 1

        if attributes is None:

            attributes = []

        attributes.append(["src", path])

        if not stylesheet:

            if instance.def_stylesheet:

                stylesheet = instance.def_stylesheet

        image = Node(
            "img",
            name=name,
            attributes=attributes,
            id=id,
            Class=Class,
            centerize=centerize,
            stylesheet=stylesheet,
            style=style,
        )

        return image
Exemplo n.º 5
0
    def container(
        self,
        instance,
        name="",
        attributes=None,
        id=None,
        Class=None,
        header=None,
        centerize=False,
        style=None,
        stylesheet=None,
    ):

        id,Class=validate_names(id,Class)

        if not stylesheet:

            if instance.def_stylesheet:

                stylesheet = instance.def_stylesheet

        if "div" in instance.content:

            instance.content["img"] += 1

        else:

            instance.content["img"] = 1

        if not stylesheet:

            if instance.def_stylesheet:

                stylesheet = instance.def_stylesheet

        container = Node(
            "div",
            name=name,
            attributes=attributes,
            id=id,
            Class=Class,
            centerize=centerize,
            stylesheet=stylesheet,
            style=style,
        )

        return container
Exemplo n.º 6
0
    def column(
        self,
        instance,
        attributes=None,
        id=None,
        Class="col",
        header=None,
        style=None,
        stylesheet=None,
    ):

        id,Class=validate_names(id,Class)

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

        if not stylesheet:

            if instance.def_stylesheet:

                stylesheet = instance.def_stylesheet

        return container
Exemplo n.º 7
0
    stylesheets=[
        "http://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css",
        "Styles.css",
    ],
    scripts=[
        "http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js",
        "http://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js",
        "http://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js",
    ],
)

jumbotron = widgets.container(page,
                              Class=["jumbotron", "bg-dark"],
                              id="YAAS",
                              attributes=["style", "color:white"])
jumbotron.add(Node("p", content="HELLO WORLD"))

Data = Data.reset_index()
pd = Data.head(n=5)

container = widgets.container(
    page,
    name="container",
    attributes=[
        "style",
        "border:1px solid black;margin-left:100px;margin-right:100px;",
    ],
)

container.add(jumbotron)
Exemplo n.º 8
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.º 9
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)