Coverage for pesummary/core/webpage/base.py: 91.7%

36 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:42 +0000

1# Licensed under an MIT style license -- see LICENSE.md 

2 

3import numpy as np 

4 

5__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"] 

6 

7 

8class Base(object): 

9 """Meta class containing helper functions for generating webpages 

10 """ 

11 def close(self): 

12 """Close the opened html file. 

13 """ 

14 self.html_file.close() 

15 

16 def _check_content(self, content): 

17 """Make sure that the content has new line in string 

18 

19 Parameters 

20 ---------- 

21 content: str 

22 string that you want to check 

23 """ 

24 if len(content) and content[-1] != "\n": 

25 content += "\n" 

26 return content 

27 

28 def add_content(self, content, indent=0): 

29 """Add content to the html page 

30 

31 Parameters 

32 ---------- 

33 content: str/list, optional 

34 either a single string or a list of string that you want to add to 

35 your html page 

36 indent: int, optional 

37 the indent of the line 

38 """ 

39 if type(content) == list: 

40 for i in np.arange(len(content)): 

41 content[i] == self._check_content(content[i]) 

42 self.html_file.write(" " * indent + content) 

43 else: 

44 content = self._check_content(content) 

45 self.html_file.write(" " * indent + content) 

46 

47 def make_div(self, indent=0, _class=None, _style=None, _id=None): 

48 """Make a div of your choice 

49 

50 indent: int, optional 

51 the indent of the line 

52 _class: str, optional 

53 the class name of your div 

54 _style: str, optional 

55 the style of your div 

56 _id: str, optional 

57 the id of your div 

58 """ 

59 string = "<div" 

60 if _class: 

61 string += " class='%s'" % (_class) 

62 if _style: 

63 string += " style='%s'" % (_style) 

64 if _id is not None: 

65 string += " id='%s'" % (_id) 

66 string += ">\n" 

67 self.add_content(string, indent=indent) 

68 

69 def end_div(self, indent=0): 

70 """End a div of your choice 

71 

72 Parameters 

73 ---------- 

74 indent: int, optional 

75 the indent of the new line 

76 """ 

77 self.add_content("</div>", indent) 

78 

79 def make_container(self, style=None, indent=0, display=None, container_id=None): 

80 """Make a container for your webpage 

81 

82 Parameters 

83 ---------- 

84 indent: int, optional 

85 the indent of the new line 

86 """ 

87 if not style: 

88 style = "margin-top:3em; margin-bottom:5em; background-color:#FFFFFF; " + \ 

89 "box-shadow: 0 0 5px grey; max-width: 1400px" 

90 if display is not None: 

91 style += "; display:{}".format(display) 

92 self.make_div(indent, _class="container", _style=style, _id=container_id) 

93 

94 def end_container(self, indent=0): 

95 """End a container 

96 

97 Parameters 

98 ---------- 

99 indent: int, optional 

100 the indent of the new line 

101 """ 

102 self.end_div(indent)