Exemplo n.º 1
0
    def __str__(self):
        bootstrap = Component(
            "link",
            rel="stylesheet",
            href=self.BOOTSTRAP_URL,
            integrety=self.BOOTSTRAP_INTEGRITY,
            crossorigin="anonymous",
        )
        meta_charset = Component("meta", charset=self.META_CHARSET)
        meta_viewport = Component(
            "meta",
            name="viewport",
            content=self.META_VIEWPORT_CONTENT,
        )
        text = '<!doctype html>\n'
        text += '<html lang={}>\n'.format(self.LANG)
        text += '    <head>\n'
        text += '        <!-- Required met tags -->\n'
        text += '        {}\n'.format(meta_charset)
        text += '        {}\n'.format(meta_viewport)
        text += '\n'
        text += '        <!-- Bootstrap css -->\n'
        text += '        {}\n'.format(bootstrap.html_open())

        for script in self.scripts:
            text += '        ' + str(script)

        text += '\n'
        text += '        <title>{}</title>\n'.format(self.title)
        text += '    </head>\n'
        text += '    <body>\n'

        return text
Exemplo n.º 2
0
    def __init__(self, name, title, profile_pic=None):
        super().__init__(id="cv_titlebar")
        utils.add_class_attributes(self, "row", "p-3", "mb-2", "bg-primary",
                                   "text-white")

        self.body = Container(id="title_body")
        self.links = Table(id="title_links", rows=1, cols=2, border="0")

        if profile_pic:
            pic_col = Container(**{"class": "col-sm-2 align-self-center"})
            pic_col.add_component(
                Component("img",
                          src=profile_pic,
                          **{"class": "rounded-circle img-thumbnail"}))
            self.add_component(pic_col)
            utils.add_class_attributes(self.body, "col-sm-7")

        else:
            utils.add_class_attributes(self.body, "col-sm-9")

        self.links_container = Container(title="title_links_container")
        self.links_container.add_component(self.links)
        utils.add_class_attributes(self.links_container, "col-sm-3")

        self.body.add_component(
            Component("h3", id="title_body_name", text=name, inline=True))
        self.body.add_component(
            Component("h4", id="title_body_title", text=title, inline=True))
        self.body.add_component(Component("br"))
        self.add_component(self.body)
        self.add_component(self.links_container)
Exemplo n.º 3
0
    def add_social_media(self, media, href):
        self.links.add_rows(1)
        row = self.links.rows()

        self.links.get_col(row, 1).add_component(
            Component("a",
                      inline=True,
                      text=media,
                      style="color:white",
                      href=href))
        utils.add_class_attributes(self.links.get_col(row, 1), "text-right")

        span = Container("span", title=media)
        if media in font_awesome_classes:
            font_awesome = Component("i",
                                     inline=True,
                                     style="color:white",
                                     **{"aria-hidden": "true"})
            utils.add_class_attributes(font_awesome,
                                       font_awesome_classes[media])
            href = Container("a", href=href)
            href.add_component(font_awesome)

        span.add_component(href)
        self.links.get_col(row, 2).add_component(span)
Exemplo n.º 4
0
    def test_html_body(self):
        c = Component(COMPONENT_TAG)
        self.c.add_component(c)
        self.assertTrue(c in self.c.components)

        id = c.get_attribute("id").get_values()
        self.assertTrue(id in self.c.html_body())
Exemplo n.º 5
0
    def update_components(self, config_section):
        self._title.text = config_section['title']
        self._company.text = config_section['company']

        if config_section['to date']:
            self._date.text = config_section[
                'from date'] + ' - ' + config_section['to date']
        else:
            self._date.text = config_section['from date']

        col = 1
        row = 1
        for technology in config_list(config_section, 'technology'):
            self._technologies.get_col(row, col).add_component(
                Component("div", inline=True, text=config_section[technology]))
            col += 1
            if col > self.TECHNOLOGY_COLUMNS:
                col = 1
                row += 1
                self._technologies.add_rows(1)

        for bullet in config_list(config_section, 'bullet'):
            self._bullets.add_component(
                Component("li", text=config_section[bullet]))

        accomplishment_text = Component("b", text="accomplishment: ")
        for accomplishment in config_list(config_section, 'accomplishment'):
            accomplishment_html = Container()
            accomplishment_html.add_component(accomplishment_text)
            accomplishment_html.add_component(
                Component("i", text=config_section[accomplishment]))
            self._accomplishments.add_component(accomplishment_html)
Exemplo n.º 6
0
def add_class_attributes(component: Component, *values):
    if not component.get_attribute("class"):
        component.add_attribute(Attribute("class"))

    class_attribute = component.get_attribute("class")
    for value in values:
        class_attribute.add_value(value)
Exemplo n.º 7
0
    def test_del_component(self):
        c = Component(COMPONENT_TAG)
        self.c.add_component(c)
        self.assertTrue(c in self.c.components)

        id = c.get_attribute("id").get_values()
        self.c.del_component(id)
        self.assertFalse(c in self.c.components)
Exemplo n.º 8
0
    def test_add_class_attributes(self):
        c = Component("div")
        self.assertTrue(c.get_attribute("class") is None)

        utils.add_class_attributes(c, CLASS1, CLASS2)
        self.assertTrue(c.get_attribute("class") is not None)
        self.assertTrue(CLASS1 in c.get_attribute("class").values)
        self.assertTrue(CLASS2 in c.get_attribute("class").values)
Exemplo n.º 9
0
 def setUp(self):
     self.c = Component(
         COMPONENT_TAG,
         text=COMPONENT_TEXT,
         inline=COMPONENT_INLINE,
         indent=COMPONENT_INDENT,
         **{COMPONENT_ATTRIBUTE: COMPONENT_ATTRIBUTE_VALUE1}
     )
Exemplo n.º 10
0
    def test_get_component(self):
        component = Component(COMPONENT_TAG)
        container = Container()
        container.add_component(component)

        self.c.add_component(container)
        self.assertTrue(component in container.components)
        self.assertTrue(container in self.c.components)

        id = component.get_attribute("id").get_values()
        get_c = self.c.get_component(id)
        self.assertTrue(component is get_c)
        self.assertTrue(self.c.get_component('OBJECT_NOT_FOUND') is None)
Exemplo n.º 11
0
    def test_clear_components(self):
        c = Component(COMPONENT_TAG)
        self.c.add_component(c)

        self.assertTrue(self.c.components)
        self.c.clear_components()
        self.assertFalse(self.c.components)
Exemplo n.º 12
0
    def add_competency(self, competency, skill, confidence):
        competency_section = self.get_component("competency-" + competency)
        if competency_section is None:
            competency_section = Container(id="competency-" + competency)
            competency_section.add_component(
                Component("h3", inline=True, text=competency))
            self.competencies.add_item(competency_section)

        skill_text = Component("small", text=skill, style="margin-left: 5px")
        utils.add_class_attributes(skill_text, "justify-content-left",
                                   "d-flex", "position-absolute", "w-100")

        skill_bar = ProgressBar(valuenow=confidence)
        utils.add_class_attributes(skill_bar, "m-1")
        skill_bar.get_component(skill_bar.id +
                                '-progressbar').add_component(skill_text)
        competency_section.add_component(skill_bar)
Exemplo n.º 13
0
    def __init__(self, config_section=None):
        id = None
        if config_section:
            id = config_section.name

        super().__init__(id=id)

        self._company = Component('h4')
        self._title = Component('h5')
        self._date = Component('u')

        self._technologies = Table(rows=1,
                                   cols=self.TECHNOLOGY_COLUMNS,
                                   id=self.id + '-technologies',
                                   border="0",
                                   cellpadding="5")
        self._bullets = Container("ul", id=self.id + '-bullets')
        self._accomplishments = Container(id=self.id + '-accomplishments')

        self.add_component(self._company)
        self.add_component(self._title)
        self.add_component(self._date)
        self.add_component(Component("br"))
        self.add_component(Component("b", inline=True, text="Technologies"))
        self.add_component(self._technologies)
        self.add_component(Component("br"))
        self.add_component(Component("b", inline=True,
                                     text="Responsibilities"))
        self.add_component(self._bullets)
        self.add_component(self._accomplishments)

        if config_section:
            self.update_components(config_section)
Exemplo n.º 14
0
    def test_add_component(self):
        c = Component(COMPONENT_TAG)
        self.assertFalse(c.get_attribute("id"))
        self.assertFalse(c in self.c.components)

        # Test that ID is added to components
        self.c.add_component(c)
        self.assertTrue(c.get_attribute("id"))
        self.assertTrue(c in self.c.components)

        # Test that indent is updated on nested objects
        c1 = Container()
        c2 = Container()
        c1.add_component(c2)
        self.assertTrue(c1.indent == c2.indent-1)
        self.c.add_component(c1)
        self.assertTrue(self.c.indent == c1.indent-1)
        self.assertTrue(c1.indent == c2.indent-1)
Exemplo n.º 15
0
    def __init__(self):
        super().__init__(id="cv_sidebar")
        utils.add_class_attributes(self, "col-3", "p-3", "mb-2",
                                   "bg-secondary", "text-white")

        self.competencies = Carousel(pause_on_hover=True,
                                     controls=True,
                                     interval=int(self.INTERVAL * 1000),
                                     ride="carousel")
        self.competencies.add_attribute(Attribute("style", "height: 200px;"))
        self.competencies.del_component(self.competencies.id + '-prev')
        self.competencies.get_component(self.competencies.id +
                                        '-next').add_attribute(
                                            Attribute("style", "height: 25%;"))
        utils.add_class_attributes(
            self.competencies.get_component(self.competencies.id + '-next'),
            "self-align-top")
        self.add_component(self.competencies)

        self.add_component(Component("br"))
        self.add_component(Component("h3", text="Personal Projects"))
        self.projects = Container("ul")
        self.add_component(self.projects)
Exemplo n.º 16
0
    def add_item(self, item: Component):
        item_index = str(len(self.inner.components))
        if self.indicators:
            # <li data-target="#carouselIndicators" data-slide-to="0" class="active"></li>
            indicator = Component(
                "li",
                inline=True,
                **{
                    "data-target": "#carouselIndicators",
                    "data-slide-to": item_index,
                },
            )
            if item_index == "0":
                add_class_attributes(indicator, "active")

            self.indicators.add_component(indicator)

        item_container = Container("div", **{"class": "carousel-item"})
        if item_index == "0":
            add_class_attributes(item_container, "active")

        item_container.add_component(item)
        self.inner.add_component(item_container)
Exemplo n.º 17
0
    def update_components(self):
        self.clear_components()

        self._titlebar = TitleBar(self.name, self.job_title, self.image)
        self._sidebar = SideBar()
        self._mainbody = MainBody()

        self.add_component(self._titlebar)

        row = Container(**{"class": "row"})
        row.add_component(self._sidebar)
        row.add_component(self._mainbody)
        self.add_component(row)

        for key in self.config['social-media'].keys():
            self._titlebar.add_social_media(key,
                                            self.config['social-media'][key])

        for competency in [
                c for c in self.config.keys() if c.startswith('competency-')
        ]:
            competency_name = competency.split('-')[1]
            for skill in self.config[competency].keys():
                self._sidebar.add_competency(
                    competency_name, skill,
                    int(self.config[competency][skill]))

        for project in [
                p for p in self.config.keys() if p.startswith('project-')
        ]:
            self._sidebar.add_project(self.config[project]["text"],
                                      self.config[project]["link"])

        for job in config_list(self.config, "job", reverse=True):
            self._mainbody.add_component(Component("hr"))
            self._mainbody.add_component(Job(self.config[job]))
Exemplo n.º 18
0
class TestComponent(unittest.TestCase):
    def setUp(self):
        self.c = Component(
            COMPONENT_TAG,
            text=COMPONENT_TEXT,
            inline=COMPONENT_INLINE,
            indent=COMPONENT_INDENT,
            **{COMPONENT_ATTRIBUTE: COMPONENT_ATTRIBUTE_VALUE1}
        )

    def test_init(self):
        self.assertTrue(hasattr(self.c, "tag"))
        self.assertTrue(self.c.tag == COMPONENT_TAG)

        self.assertTrue(hasattr(self.c, "text"))
        self.assertTrue(self.c.text == COMPONENT_TEXT)

        self.assertTrue(hasattr(self.c, "inline"))
        self.assertTrue(self.c.inline == COMPONENT_INLINE)

        self.assertTrue(hasattr(self.c, "indent"))
        self.assertTrue(self.c.indent == COMPONENT_INDENT)

        self.assertTrue(hasattr(self.c, "attributes"))
        self.assertTrue(COMPONENT_ATTRIBUTE in self.c.attributes)

    def test_add_attribute(self):
        a = Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE1)

        self.assertFalse(a in self.c.attributes)
        self.c.add_attribute(a)
        self.assertTrue(a in self.c.attributes)

        # Test adding existing attribute appends values
        a = Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE2)
        self.c.add_attribute(a)
        self.assertTrue(ATTRIBUTE_VALUE1 in self.c.get_attribute(a).values)
        self.assertTrue(ATTRIBUTE_VALUE2 in self.c.get_attribute(a).values)

    def test_del_attribute(self):
        a = Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE1)
        self.c.add_attribute(a)

        self.assertTrue(ATTRIBUTE_NAME in self.c.attributes)
        self.c.del_attribute(ATTRIBUTE_NAME)
        self.assertFalse(ATTRIBUTE_NAME in self.c.attributes)

    def test_add_attributes(self):
        self.c.del_attribute(ATTRIBUTE_NAME)

        self.assertFalse(ATTRIBUTE_NAME in self.c.attributes)
        self.c.add_attributes(**{ATTRIBUTE_NAME: ATTRIBUTE_VALUE1})
        self.assertTrue(ATTRIBUTE_NAME in self.c.attributes)

    def test_get_attribute(self):
        a = self.c.get_attribute(COMPONENT_ATTRIBUTE)
        self.assertTrue(a is not None)
        self.assertTrue(isinstance(a, Attribute))
        self.assertTrue(a.name == COMPONENT_ATTRIBUTE)

    def test_clear_attributes(self):
        self.assertTrue(self.c.attributes)
        self.c.clear_attributes()
        self.assertFalse(self.c.attributes)

    def test_str(self):
        html_open = self.c.html_open()
        html_body = self.c.html_body()
        html_close = self.c.html_close()

        self.assertTrue(html_open in str(self.c))
        self.assertTrue(html_body in str(self.c))
        self.assertTrue(html_close in str(self.c))
Exemplo n.º 19
0
    def __init__(self,
                 controls=False,
                 indicators=False,
                 interval=5000,
                 keyboard=True,
                 pause_on_hover=False,
                 ride=False,
                 wrap=True,
                 **attributes):
        attributes["class"] = "carousel slide"
        super().__init__("div", **attributes)

        self.indicators = indicators
        self.interval = interval
        self.keyboard = keyboard
        self.ride = ride
        self.wrap = wrap

        self.add_attributes(**{"data-interval": str(interval)})
        self.add_attributes(**{"data-keyboard": str(keyboard).lower()})
        self.add_attributes(**{"data-ride": str(ride).lower()})
        self.add_attributes(**{"data-wrap": str(wrap).lower()})

        if pause_on_hover:
            self.add_attributes(**{"data-pause": "hover"})

        if indicators:
            self.indicators = Container("ol",
                                        **{"class": "carousel-indicators"})
            self.add_component(self.indicators)

        self.inner = Container("div", **{"class": "carousel-inner"})
        self.add_component(self.inner)

        if controls:
            control_prev = Container(
                "a",
                id=self.id + "-prev",
                href="#{}".format(self.id),
                role="button",
                **{
                    "class": "carousel-control-prev",
                    "data-slide": "prev",
                },
            )
            control_prev.add_component(
                Component("span",
                          id=control_prev.id + '-icon',
                          inline=True,
                          **{
                              "class": "carousel-control-prev-icon",
                              "aria-hidden": "true"
                          }))
            control_prev.add_component(
                Component("span",
                          inline=True,
                          **{"class": "sr-only"},
                          text="Previous"))

            control_next = Container(
                "a",
                id=self.id + "-next",
                href="#{}".format(self.id),
                role="button",
                **{
                    "class": "carousel-control-next",
                    "data-slide": "next",
                },
            )
            control_next.add_component(
                Component("span",
                          id=control_next.id + '-icon',
                          inline=True,
                          **{
                              "class": "carousel-control-next-icon",
                              "aria-hidden": "true"
                          }))
            control_next.add_component(
                Component("span",
                          inline=True,
                          **{"class": "sr-only"},
                          text="Next"))

            self.add_component(control_prev)
            self.add_component(control_next)
Exemplo n.º 20
0
import sys

sys.path.append("bootstrap")

import argparse
import configparser
from pybootstrap.core import Component, Container, Attribute
from pybootstrap.collections import ProgressBar, Carousel, Table
from pybootstrap import utils

# You probably want FontAwesome-Pro...
script_fontawesome = Component(
    "link",
    inline=True,
    rel="stylesheet",
    src="https://use.fontawesome.com/releases/v5.4.1/css/all.css",
    integrity=
    "sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz",
    crossorigin="anonymous",
)

script_bootstrap_min = Component(
    "script",
    inline=True,
    src=
    "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js",
    integrety=
    "sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy",
    crossorigin="anonymous",
)
Exemplo n.º 21
0
 def add_project(self, text, href):
     list_item = Container("li")
     list_item.add_component(
         Component("a", href=href, text=text, **{"class": "text-white"}))
     self.projects.add_component(list_item)
Exemplo n.º 22
0
 def __init__(self):
     super().__init__(id="cv_main_body")
     utils.add_class_attributes(self, "col-9", "p-3", "mb-2", "bg-light",
                                "text-dark")
     self.add_component(Component("h3", inline=True, text="Work History"))