Exemplo n.º 1
0
 def button(self, text, link, color="#ffffff", background_color="#B200FD"):
     return tags.Center(
         tags.Div(
             attributes.InlineStyle(margin="48px 0"),
             tags.A(
                 attributes.Class("button"),
                 attributes.Href(link),
                 attributes.InlineStyle(
                     background_color=background_color,
                     color=color,
                     border_radius="4px",
                     display="inline-block",
                     font_family="sans-serif",
                     font_size="18px",
                     font_weight="bold",
                     line_height="60px",
                     text_align="center",
                     text_decoration="none",
                     width="300px",
                     _webkit_text_size_adjust="none",
                 ),
                 tags.Text(text),
             ),
         )
     )
Exemplo n.º 2
0
 def button(
     self,
     link,
     text="Open",
     width="auto",
     color="white",
     background_color="black",
 ):
     self.deprecatedPrint()
     return tags.Center(
         tags.Div(
             attributes.InlineStyle(margin="48px 0"),
             tags.A(
                 attributes.Class("button"),
                 attributes.Href(link),
                 attributes.InlineStyle(
                     background_color=background_color,
                     color=color,
                     border_radius="4px",
                     display="inline-block",
                     font_family="sans-serif",
                     font_size="18px",
                     font_weight="bold",
                     line_height="60px",
                     text_align="center",
                     text_decoration="none",
                     width=width,
                     max_width="300px",
                     padding_left="10px",
                     padding_right="10px",
                     _webkit_text_size_adjust="none",
                 ),
                 tags.Text(text),
             ),
         ))
Exemplo n.º 3
0
 def link(self, link, title="Open", color="#B200FD"):
     self.deprecatedPrint()
     return tags.A(
         attributes.Href(link),
         attributes.InlineStyle(color=color, text_decoration="underline"),
         tags.Text(title),
     )
Exemplo n.º 4
0
 def image(self,
           src,
           link=None,
           name="Cover",
           align="left",
           width="100%",
           height="80%"):
     self.deprecatedPrint()
     if src is None:
         return None
     elems_img = [
         attributes.Src(f"{src}?naas_uid={str(uuid.uuid4())}"),
         attributes.Height(height),
         attributes.Width(width),
         {
             "name": "border",
             "value": 0
         },
         attributes.InlineStyle(
             border_radius="4px",
             margin=self.__align(align),
             display="block",
         ),
         {
             "name": "alt",
             "value": name
         },
     ]
     if link:
         return tags.A(attributes.Href(link), tags.Img(elems_img))
     else:
         return tags.Img(elems_img)
Exemplo n.º 5
0
 def table(self, data, border=True):
     elems = []
     table_arr = None
     if isinstance(data, pd.DataFrame):
         table_arr = list(data.values.tolist())
     elif isinstance(data, list):
         table_arr = data
     else:
         raise ValueError("Table should be array")
     for row in table_arr:
         res = []
         if isinstance(row, list):
             for i in range(len(row)):
                 cell = row[i]
                 if isinstance(data, pd.DataFrame):
                     col = list(data.columns)[i]
                     res.append(tags.Td(self.__convert(cell, col)))
                 else:
                     res.append(
                         tags.Td(tags.Text(cell) if isinstance(cell, str) else cell)
                     )
         else:
             res.append(tags.Td(tags.Text(row) if isinstance(row, str) else row))
         elems.append(tags.Tr(res))
     tab = tags.Table(
         attributes.InlineStyle(width="100%"),
         attributes.Class("table_border") if border else None,
         elems,
     )
     return tags.P(tab)
Exemplo n.º 6
0
 def text(self, text, font_size="18px"):
     self.deprecatedPrint()
     return tags.P(
         tags.Text(text),
         attributes.InlineStyle(font_size=font_size,
                                padding_left="10px",
                                padding_right="10px"),
     )
Exemplo n.º 7
0
 def info(self, *elems):
     return tags.Div(
         attributes.InlineStyle(
             background_color="ghostwhite",
             border_radius="4px",
             padding="24px 48px",
         ),
         *elems,
     )
Exemplo n.º 8
0
 def title(self, title, heading=None):
     self.deprecatedPrint()
     return tags.H1(
         attributes.InlineStyle(
             color="#000000",
             font_size="32px",
             font_weight="800",
             line_height="32px",
             margin="48px 0",
             text_align="center",
         ),
         tags.Text(title),
         tags.Br(),
         (tags.Span(
             attributes.InlineStyle(
                 font_size="24px", font_weight="600", color="darkgray"),
             tags.Text(heading),
         ) if heading else None),
     )
Exemplo n.º 9
0
 def address(self, title, content):
     return tags.Address(
         attributes.InlineStyle(
             font_size="16px",
             font_style="normal",
             font_weight="400",
             line_height="24px",
         ),
         tags.Strong(tags.Text(title)),
         tags.Text(content),
     )
Exemplo n.º 10
0
 def footer(self, text, first=None, *elems):
     one = [
         attributes.InlineStyle(
             font_size="16px",
             font_weight="400",
             line_height="24px",
             margin_top="48px",
         ),
         tags.Text(text),
         first,
     ]
     return tags.Footer(tags.P(one), *elems)
Exemplo n.º 11
0
 def subtitle(self, subtitle):
     return tags.H2(
         attributes.InlineStyle(
             color="#000000",
             font_size="28px",
             font_weight="600",
             line_height="32px",
             margin="48px 0 24px 0",
             text_align="center",
         ),
         tags.Text(subtitle),
     )
Exemplo n.º 12
0
 def table(self, data, border=True):
     self.deprecatedPrint()
     elems = []
     table_arr = None
     row_link = False
     row_link_index = -1
     if isinstance(data, pd.DataFrame):
         table_arr = list(data.values.tolist())
         row_link = True if "row_link" in data.columns else False
         try:
             row_link_index = list(data.columns).index("row_link")
         except ValueError:
             pass
     elif isinstance(data, list):
         table_arr = data
     else:
         error_text = f"Table should be array, not {data.__name__}"
         self.print_error(error_text)
         return None
     for row in table_arr:
         res = []
         if isinstance(row, list):
             for i in range(len(row)):
                 cell = row[i]
                 if isinstance(data, pd.DataFrame):
                     col = list(data.columns)[i]
                     if row_link:
                         if col != "row_link":
                             link = row[row_link_index]
                             res.append(
                                 tags.Td(
                                     tags.A(
                                         attributes.Href(link),
                                         self.__convert(cell, col),
                                     )))
                     else:
                         res.append(tags.Td(self.__convert(cell, col)))
                 else:
                     res.append(
                         tags.Td(
                             tags.Text(cell) if isinstance(cell, str
                                                           ) else cell))
         else:
             res.append(
                 tags.Td(tags.Text(row) if isinstance(row, str) else row))
         elems.append(tags.Tr(res))
     tab = tags.Table(
         attributes.InlineStyle(width="100%"),
         attributes.Class("table_border") if border else None,
         elems,
     )
     return tags.P(tab)
Exemplo n.º 13
0
 def heading(self, text):
     self.deprecatedPrint()
     return tags.H2(
         attributes.InlineStyle(
             color="#000000",
             font_size="28px",
             font_weight="600",
             line_height="32px",
             margin="48px 0 24px 0",
             text_align="center",
         ),
         tags.Text(text),
     )
Exemplo n.º 14
0
 def title(self, title, subtitle=None):
     return tags.H1(
         attributes.InlineStyle(
             color="#000000",
             font_size="32px",
             font_weight="800",
             line_height="32px",
             margin="48px 0",
             text_align="center",
         ),
         tags.Text(title),
         tags.Br(),
         (
             tags.Span(
                 attributes.InlineStyle(
                     font_size="24px", font_weight="600", color="darkgray"
                 ),
                 tags.Text(subtitle),
             )
             if subtitle
             else None
         ),
     )
Exemplo n.º 15
0
 def cover(self, src, link=None, name="Cover"):
     if src is None:
         return None
     elems_img = [
         attributes.Src(f"{src}?naas_uid={str(uuid.uuid4())}"),
         attributes.Height(80),
         attributes.Width(600),
         {"name": "border", "value": 0},
         attributes.InlineStyle(
             border_radius="4px",
             display="block",
             max_width="100%",
             min_width="100px",
             width="100%",
         ),
         {"name": "alt", "value": name},
     ]
     if link:
         return tags.A(attributes.Href(link), tags.Img(elems_img))
     else:
         return tags.Img(elems_img)
Exemplo n.º 16
0
 def table(self, cells, column=2, border=False):
     elems = []
     if len(cells) > column:
         sliced = slice_per(cells, column)
         for row in sliced:
             res = []
             for cell in row:
                 res.append(
                     tags.Td(tags.Text(cell) if isinstance(cell, str) else cell)
                 )
             elems.append(tags.Tr(res))
     else:
         row = cells
         res = []
         for cell in row:
             res.append(tags.Td(tags.Text(cell) if isinstance(cell, str) else cell))
         elems.append(tags.Tr(res))
     tab = tags.Table(
         attributes.InlineStyle(width="100%"),
         attributes.Class("table_border") if border else None,
         elems,
     )
     return tags.P(tab)
Exemplo n.º 17
0
 def generate(self,
              title,
              logo=None,
              display="embed",
              footer=None,
              **kwargs):
     self.deprecatedPrint()
     gen_html = tags.Html(
         attributes.Lang("en"),
         tags.Head(
             tags.Meta(
                 attributes.HttpEquiv("Content-Type"),
                 attributes.Content("text/html; charset=utf-8"),
             ),
             tags.Meta(
                 attributes.HttpEquiv("Content-Type"),
                 attributes.Content("width=device-width, initial-scale=1"),
             ),
             tags.Meta(
                 attributes.Name("viewport"),
                 attributes.Content("width=device-width, initial-scale=1"),
             ),
             tags.Meta(
                 attributes.HttpEquiv("X-UA-Compatible"),
                 attributes.Content("IE=edge"),
             ),
             tags.Style(tags.Text(base_style)),
             tags.Title(tags.Text(title)),
         ),
         tags.Body(
             attributes.InlineStyle(margin="0 !important",
                                    padding="0 !important"),
             tags.Div(
                 attributes.InlineStyle(display="none",
                                        max_height="0",
                                        overflow="hidden"),
                 tags.Text(title),
             ),
             tags.Div(
                 attributes.InlineStyle(display="none",
                                        max_height="0",
                                        overflow="hidden"),
                 tags.Text(" ‌" * 240),
             ),
             tags.Text(table_ie9),
             tags.Div(
                 {
                     "name": "role",
                     "value": "article"
                 },
                 {
                     "name": "aria-label",
                     "value": title
                 },
                 attributes.Lang("en"),
                 attributes.Class("basic_font"),
                 attributes.InlineStyle(
                     background_color="white",
                     color="#2b2b2b",
                     font_size="18px",
                     font_weight="400",
                     line_height="28px",
                     margin="0 auto",
                     max_width="720px",
                     padding="40px 20px 40px 20px",
                 ),
                 self.header(logo, self.title(title)),
                 self.main(**kwargs),
                 footer,
             ),
             tags.Text(table_ie9_close),
         ),
     )
     res = gen_html.render()
     self.__display(res, display)
     return res
Exemplo n.º 18
0
 def link(self, link, title):
     return tags.A(
         attributes.Href(link),
         attributes.InlineStyle(color="#B200FD", text_decoration="underline"),
         tags.Text(title),
     )
Exemplo n.º 19
0
 def text(self, text, font_size="18px"):
     return tags.P(tags.Text(text), attributes.InlineStyle(font_size=font_size))