コード例 #1
0
class AntennaDataView(NavedYawrap):
    resources = [
        EmbedCss(CSS),
        EmbedJs(SVG_JS),
    ]

    def fill_sub_page(self, fr, sf, powers):
        with self.tag("h3"):
            self.text("Antenna Dump %s.%s" % (fr, sf))

        with self.tag("table", klass="ant_pow_val"):
            with self.tag("tr"):
                self.line("td", "Frame:")
                self.line("td", str(fr))
            with self.tag("tr"):
                self.line("td", "Sub-frame")
                self.line("td", str(sf))
            with self.tag("tr"):
                self.line("td", "lnCellId")
                self.line("td", "166")

            for i, power in enumerate(powers):
                with self.tag("tr"):
                    self.line("td", "Antenna %d mean power" % i)
                    style = "background-color:%s;" % int16_to_log_color(power)
                    self.line("td",
                              "%.2f dB (%s)" % (dB(power), power),
                              style=style)
コード例 #2
0
ファイル: test_navrap.py プロジェクト: kamichal/yarap
 class MyPage(NavedYawrap):
     resources = [EmbedCss("""
     body {
         margin: 16;
         font-family: Verdana, sans-serif;
     }""")
                  ]
コード例 #3
0
def test_defining_css_as_a_dict(mocked_save_file):
    class Root(NavedYawrap):
        resources = [
            EmbedCss({"body": {
                "background": "#DAD"
            }}),
            LinkCss({"#that": {
                "color": "#DAD"
            }}, file_name="common_style.css"),
        ]

    root_doc = Root("one.html")
    root_doc.add(EmbedCss("div {padding: 0px;}"))

    sub_doc = root_doc.sub("two.html")
    sub_doc.add(EmbedCss("#id {margin: 10px 12px;}"))
    sub_doc.add(LinkCss("a {width: 90%;}", file_name="sub.css"))

    root_soup = BeautifulSoup(root_doc._render_page(), "html.parser")
    sub_soup = BeautifulSoup(sub_doc._render_page(), "html.parser")

    expected_root_styles = [
        "body { background: #DAD; }".split(), "div {padding: 0px;}".split()
    ]
    expected_sub_styles = [
        "body { background: #DAD; }".split(),
        "#id {margin: 10px 12px;}".split()
    ]

    root_styles = [
        style.text.split() for style in root_soup.html.head.find_all("style")
    ]
    assert all([style in root_styles for style in expected_root_styles])

    sub_styles = [
        style.text.split() for style in sub_soup.html.head.find_all("style")
    ]
    assert all([style in sub_styles for style in expected_sub_styles])

    root_links = [
        link["href"] for link in root_soup.html.head.find_all("link")
    ]
    assert root_links == ['resources/common_style.css']

    sub_links = [link["href"] for link in sub_soup.html.head.find_all("link")]
    assert sub_links == ['resources/common_style.css', 'resources/sub.css']
コード例 #4
0
 class MyRap(Yawrap):
     resources = [
         EmbedCss("head { background: #DAD; }"),
         EmbedJs('console.log("alles klar in the head")'),
         EmbedCss.from_url("http://www.css.in/da.house.css"),
         EmbedJs.from_url('http://www.js.in/the.head.js'),
         EmbedCss.from_file("/path/to/style_to_embed.css"),
         EmbedJs.from_file("/path/to/script_to_embed.js"),
     ]
コード例 #5
0
 class Root(NavedYawrap):
     resources = [
         EmbedCss({"body": {
             "background": "#DAD"
         }}),
         LinkCss({"#that": {
             "color": "#DAD"
         }}, file_name="common_style.css"),
     ]
コード例 #6
0
ファイル: test_yarap.py プロジェクト: kamichal/yarap
    class MyRap(Yawrap):
        resources = [EmbedCss({'.content': {'color': '#daf'}})]

        def __init__(self, target_file):
            title = 'MyWrap'
            Yawrap.__init__(self, target_file, title)

            with self.tag('p'):
                self.text("that's my wrap")
コード例 #7
0
def test_class_defined_css(yawrap_class_with_naved):
    class JarapWCss(yawrap_class_with_naved):
        resources = [EmbedCss(CssStyle1)]

    jarap = JarapWCss('')
    jarap.add(EmbedCss(CssStyle2))
    render = jarap._render_page()
    soup = BeautifulSoup(render, "html.parser")
    assert [c.text for c in soup.html.head.children
            if c.name == "style"] == [CssStyle1, CssStyle2]
コード例 #8
0
ファイル: test_usage_01.py プロジェクト: kamichal/yarap
class MyPageTemplate(Yawrap):
    resources = [
        ExternalJs("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"),
        EmbedCss("""\
        body {
            padding: 12px;
            font-family: helvetica, sans-serif;
            font-size: 14px;
        }
        .box {
            display: inline-block;
            height: 80px;
            margin: 8px;
            padding: 8px;
            width: 80px;
        }"""),
        EmbedJs("""\
        $("button").click(function(){
            $("#red-box").fadeToggle();
            $("#green-box").fadeToggle("slow");
            $("#blue-box").fadeToggle(3000);
        });""", placement=BODY_END),
    ]

    def _create_box(self, name, color):
        style = "background-color:{};".format(color)
        with self.tag('div', id=name, klass="box", style=style):
            self.text(name)

    def fill_with_content(self):
        with self.tag("h2"):
            self.text("Demonstrate a simple JavaScript.")

        with self.tag('p'):
            self.text("fadeToggle() operating with different speed parameters.")

        with self.tag('button'):
            self.text("Click to fade in/out boxes")

        with self.tag("div"):
            self._create_box('red-box', "red")
            self._create_box('green-box', "#0f0")
            self._create_box('blue-box', "#0a1cf0")
コード例 #9
0
ファイル: test_navrap.py プロジェクト: kamichal/yarap
def add_tooltip(target_doc, popup_width=280, type_='span', *args, **kwargs):
    target_doc.add(EmbedCss({
        ".tooltip": {
            "position": "relative",
            "display": "inline-block",
        },
        ".tooltip .tooltip_popup": {
            'padding': '16px',
            'background-color': "#121",
            'border-radius': '6px',
            'color': '#fff',
            "top": "100%",
            "left": "50%",
            "width": "{}px".format(popup_width),
            "margin-left": "-{}px".format(popup_width / 2),
            'visibility': 'hidden',
            'position': 'absolute',
            'z-index': '1'
        },
        ".tooltip:hover .tooltip_popup": {
            'visibility': 'visible'
        },
        ".tooltip .tooltip_popup::after": {
            "content": "' '",
            "position": "absolute",
            "bottom": "100%",
            "left": "50%",
            "margin-left": "-5px",
            "border-width": "5px",
            "border-style": "solid",
            "border-color": "transparent transparent black transparent"
        }
    }))

    popup_doc = Doc()

    with target_doc.tag(type_, klass="tooltip", *args, **kwargs):
        yield popup_doc
        with target_doc.tag('span', klass=".{}_popup".format("tooltip")[1:]):
            target_doc.asis(popup_doc.getvalue())
コード例 #10
0
ファイル: test_yarap.py プロジェクト: kamichal/yarap
    class MyJsPage(Yawrap):
        resources = [
            ExternalJs(
                "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
            ),
            EmbedCss("""
          .box {
            width:80px;
            height: 80px;
          }"""),
            EmbedJs("""\
          $(document).ready(function(){
              $("button").click(function(){
                  $("#div1").fadeToggle();
                  $("#div2").fadeToggle("slow");
                  $("#div3").fadeToggle(3000);
              });
          });""")
        ]

        def __init__(self, out_file):
            title = 'jQuery W3 example, js defined as class attribute.'
            Yawrap.__init__(self, out_file, title)
            with self.tag('p'):
                self.text(
                    "Demonstrate fadeToggle() with different speed parameters."
                )

            with self.tag('button'):
                self.text("Click to fade in/out boxes")

            self.create_box2('div1', "background-color:red;")
            self.create_box2('div2', "background-color:green;")
            self.create_box2('div3', "background-color:blue;")

        def create_box2(self, name, add_style):
            with self.tag('div', id=name, klass="box", style=add_style):
                pass
            self.stag('br')
コード例 #11
0
ファイル: test_navrap.py プロジェクト: kamichal/yarap
def other_styles_listing_plugin(host_doc, out_dir, current_test_out_dir):
    style = """\
    .main_container {
        background: #FFD;
        margin: 12px 26px;
        padding: 0px;
        -moz-box-shadow: 2px 2px 5px 2px #AAA;
        -webkit-box-shadow: 2px 2px 5px 2px #AAA;
        font-family: Verdana, sans-serif;
    }
    .main_container h4 {
        margin: 9px;
    }
    .container {
        padding: 2px 18px;
    }
    a.div_link {
        text-decoration: none;
    }
    .blue {
        background: #6699ff;
    }
    .leftbar {
        border-left: solid 7px #6699ff;
    }
    .info_card {
        color: #000;
        margin: 3px 10px;
        display: inline-block;
        padding: 4px 26px;
        -moz-box-shadow: 0 0 7px 0 #999 inset;
        -webkit-box-shadow: 0 0 7px 0 #999 inset;
    }
    .info_card:hover {
        background: #9CF
    }
    """

    plugin_info = """\
This div is placed here using kind of plugin. It's a stand-alone python function,
that can be called with Yawrap handle and any other arguments you desire. Of course you write it yourself.""", """\
It can add content, add CSS rules or insert a JS to that site. There is no need to define them
in a page (i.e. Yawrap class) that uses it. However of course those will appear in the final page - merged
with its native rules.""", """\
It is supposed to look almost the same way in each pages of different styles unless plugin's CSS selectors
collide with host page selectors.""", """\
Advantage of using such stuff is ability to joining CSS and HTML of a plugin in one place of source.
It's easy to maintain. It's reusable by separation from page class definition. It can be used totally dynamic.
"""

    host_doc.add(EmbedCss(style))
    with host_doc.tag('div', klass='main_container'):
        with host_doc.tag('div', klass='container blue'):
            with host_doc.tag('h4'):
                host_doc.text("Other versions")

        with host_doc.tag('div', klass='container leftbar'):
            for info in plugin_info:
                with host_doc.tag('p'):
                    host_doc.text(info)

            with host_doc.tag('h4'):
                host_doc.text("Check also other styles:")
            for other_class, info, other_dir in NAV_TEST_PARAMS:
                other_index = os.path.join(out_dir, other_dir, 'index.html')
                rel_link = os.path.relpath(other_index, current_test_out_dir)

                with host_doc.local_link(other_index, klass='div_link'):
                    with add_tooltip(host_doc, 340) as popup:
                        popup.text(rel_link)
                        with popup.tag('p'):
                            popup.text(info)
                        with host_doc.tag('div', klass="info_card"):
                            host_doc.text(other_class.__name__ + ' ')
コード例 #12
0
 class JarapWCss(yawrap_class_with_naved):
     resources = [EmbedCss(CssStyle1)]