コード例 #1
0
class Heading:
    person: str
    name: Annotated[str, Context(), Attr('name')]
    greeting: Annotated[str, Get(Settings), Attr('greeting')]

    def __call__(self):
        return html('''<h1>{self.greeting} {self.person}, {self.name}</h1>''')
コード例 #2
0
class Document:
    """ A block in content, holding most of the info on this resource """

    body: Annotated[
        Markup,
        Get(PageContext, attr='body'),
    ]
    nosidebar: Annotated[
        bool,
        Get(HTMLConfig),
        Attr('nosidebar'),
    ]
    inner: VDOM = field(init=False)

    def __post_init__(self):
        # Alabaster wraps the main content in <div class="bodywrapper">
        # if nosidebar is true. Thus, get the main content first, then
        # insert in the two flavors of response.
        main_content = html('''\n
        <{Relbar1}/>
          <div class="body" role="main">
            {self.body}
          </div>          
        <{Relbar2}/>        
                ''')
        self.inner = main_content if self.nosidebar else html('<div class="bodywrapper">{main_content}</div>')

    def __call__(self) -> VDOM:
        return html('''\n
<div class="documentwrapper">
  {self.inner}
</div>        
            ''')
コード例 #3
0
def test_pipeline_two_attr_attr(french_container):
    @dataclass
    class Customer:
        name: str = 'Some Customer'

    @dataclass
    class Config:
        customer: Customer = Customer()

    pipeline = (Attr('customer'), Attr('name'))
    result = process_pipeline(
        french_container,
        pipeline,
        start=Config(),
    )
    assert result == 'Some Customer'
コード例 #4
0
def test_get_then_attr(french_container):
    get = Get(View)
    start = View
    result1 = get(start, french_container)
    attr = Attr('name')
    result = attr(result1, french_container)
    assert 'French View' == result
コード例 #5
0
class Relbar1:
    """ Relation bar usually at the top. """

    show_relbar_top: Annotated[bool,
                               Get(ThemeConfig),
                               Attr('show_relbar_top'), ]
    show_relbars: Annotated[bool, Get(ThemeConfig), Attr('show_relbar_top'), ]
    resolved_show_relbars: bool = field(init=False)

    def __post_init__(self):
        self.resolved_show_relbars = self.show_relbar_top or self.show_relbars

    def __call__(self) -> VDOM:
        return html('''\n
<div class="related top"><{RellinkMarkup} /> </div>        
        ''') if self.resolved_show_relbars else []
コード例 #6
0
 def target(
     customer_name: Annotated[
         str,
         Context(),
         Attr('name'),
     ],
 ):
     return customer_name
コード例 #7
0
 def target(
     view_name: Annotated[
         str,
         Get(Foo),
         Attr('name'),
     ] = 'View Name'
 ):
     return view_name
コード例 #8
0
 def target(
     view_name: Annotated[
         str,
         Get(View),
         Attr('name'),
     ],
 ):
     return view_name
コード例 #9
0
class CanonicalLink:
    baseurl: Annotated[Optional[str], Get(HTMLConfig), Attr('baseurl')]
    canonical_href: Optional[str] = field(init=False)
    file_suffix: Annotated[str, Get(HTMLConfig), Attr('file_suffix'), ]
    pagename: Annotated[str, Get(PageContext, attr='pagename'), ]

    def __post_init__(self):
        if self.baseurl:
            self.canonical_href = join(self.baseurl,
                                       self.pagename + self.file_suffix)
        else:
            self.canonical_href = None

    def __call__(self) -> Optional[VDOM]:
        if self.canonical_href:
            return html('<link rel="canonical" href={self.canonical_href}/>')
        return None
コード例 #10
0
def test_pipeline_two(french_container):
    pipeline = (Get(View), Attr('name'))
    result = process_pipeline(
        french_container,
        pipeline,
        start=View,
    )
    assert result == 'French View'
コード例 #11
0
class View:
    site_name: Annotated[
        str,
        Get(BaseSettings),
        Attr('site_name'),
    ]

    @property
    def name(self):
        site_name = self.site_name
        return f'View - {site_name}'
コード例 #12
0
class Footer:
    """ A block in the body below the content block. """

    copyright: Annotated[Optional[str], Get(SphinxConfig), Attr('copyright'), ]
    has_source: Annotated[bool, Get(HTMLConfig), Attr('has_source'), ]
    pathto: Annotated[Callable[[str], str], Get(PageContext, attr='pathto'), ]
    show_powered_by: Annotated[bool,
                               Get(ThemeConfig),
                               Attr('show_powered_by'), ]
    show_copyright: Annotated[bool, Get(HTMLConfig), Attr('show_copyright'), ]
    show_sourcelink: Annotated[bool,
                               Get(HTMLConfig),
                               Attr('show_sourcelink'), ]
    sourcename: Annotated[str, Get(PageContext, attr='sourcename'), ]
    resolved_copyright: str = field(init=False)
    resolved_powered_by: VDOM = field(init=False)
    resolved_page_source: VDOM = field(init=False)

    def __post_init__(self):
        self.resolved_copyright = f'&copy; {self.copyright}.' if self.copyright else ''
        self.resolved_powered_by = html('''\n
{'|' if self.copyright else ''}
Powered by <a href="http://sphinx-doc.org/">Sphinx</a>
        ''') if self.show_powered_by else html('')
        if self.show_sourcelink and self.has_source and self.sourcename:
            ps = self.pathto(f'_sources/{self.sourcename}')
            self.resolved_page_source = html('''\n
{'|' if self.show_copyright or self.show_powered_by else ''}
<a href={ps} rel="nofollow">Page source</a>
            ''')
        else:
            self.resolved_page_source = html('')

    def __call__(self) -> VDOM:
        return html('''\n
<div class="footer">
    {self.resolved_copyright}
    {self.resolved_powered_by}
    {self.resolved_page_source}
</div>
        ''')
コード例 #13
0
class FaviconSet:
    favicons: Annotated[Favicons, Get(ThemeConfig), Attr('favicons')]
    pathto: Annotated[Callable[[str, int], str],
                      Get(PageContext, attr='pathto'), ]
    shortcut_href: Optional[str] = field(init=False)
    png_href: Optional[str] = field(init=False)

    def __post_init__(self):
        favicons = self.favicons
        self.shortcut_href = self.pathto(join('static', favicons.shortcut),
                                         1) if favicons.shortcut else None
        self.png_href = self.pathto(join('static', favicons.png),
                                    1) if favicons.png else None

    def __call__(self) -> VDOM:
        shortcut = html(
            '<link rel="shortcut icon" type="image/x-icon" href={self.shortcut_href} />'
        ) if self.shortcut_href else None
        png = html(
            '<link rel="shortcut icon" type="image/x-icon" href={self.png_href} />'
        ) if self.png_href else None
        precomposed = html(
            '<link rel="apple-touch-icon-precomposed" type="image/x-icon" href={self.png_href} />'
        ) if self.png_href else None
        if self.favicons.sizes:
            sizes = []
            for size in self.favicons.sizes:
                size_href = self.pathto(join('static', size.filename), 1)
                size_size = size.size
                sizes.append(
                    html(
                        '<link rel="apple-touch-icon-precomposed" sizes={size_size} href={size_href} />'
                    ))
        else:
            sizes = None
        return html('''\n
{shortcut}
{png}
{precomposed}
{sizes}
        ''')
コード例 #14
0
class BaseLayout:
    language: Annotated[
        str,
        Get(SphinxConfig),
        Attr('language'),
    ]
    extrahead: Optional[VDOM] = None
    doctype: Markup = Markup('<!DOCTYPE html>\n')
    html_props: Dict[str, str] = field(init=False)

    def __post_init__(self):
        self.html_props = dict(lang=self.language) if self.language else dict()

    def __call__(self) -> VDOM:
        return html('''\n
{self.doctype}
<html ...{self.html_props}>
    <{Head} extrahead={self.extrahead} />
    <{Body} />
</html>
        ''')
コード例 #15
0
class Punctuation:
    character: Annotated[str, Get(PunctuationCharacter), Attr('symbol'), ]

    def __call__(self):
        return html('<span>{self.character}</span>')
コード例 #16
0
ファイル: greeting.py プロジェクト: pauleveritt/viewdom_wired
class Greeting:
    name: Annotated[str, Context(), Attr('name')]

    def __call__(self):
        return html('<h1>Hello {self.name}</h1>')
コード例 #17
0
class FrenchView:
    customer_name: Annotated[str, Context(), Attr('name'), ]

    @property
    def name(self):
        return f'Bonjour {self.customer_name}'
コード例 #18
0
class ThirdHeading:
    """ Double injection but with a plain factory, not injectable """

    greeting: Annotated[str, Get(Settings), Attr('greeting')]
    config: Config  # Annotated[Config, Get(Config)]
コード例 #19
0
class Favicon:
    href: Annotated[str, Get(HTMLConfig), Attr('favicon'), StaticPathTo(), ]

    def __call__(self) -> VDOM:
        return html('<link rel="shortcut icon" href={self.href} />')
コード例 #20
0
    class Target:
        customer_name: Annotated[str, Context(), Attr('name'), ]

        def __call__(self):
            return self.customer_name
コード例 #21
0
class SecondHeading:
    person: str
    name: Annotated[str, Context(), Attr('name')]
    greeting: Annotated[str, Get(Settings), Attr('greeting')]
コード例 #22
0
 class Target:
     customer_name: Annotated[str, Get(View), Attr('caps_name'), ]
コード例 #23
0
    class Target:
        view_name: Annotated[str, Get(Foo), Attr('name'), ] = 'View Name'

        def __call__(self):
            return self.view_name
コード例 #24
0
    class Target:
        customer_name: Annotated[str, Get(View), Attr('name'), ]

        def __call__(self):
            return self.customer_name
コード例 #25
0
class FrenchGreeting:
    name: Annotated[str, Context(), Attr('name')]

    def __call__(self):
        return html('<h1>Bonjour {self.name}</h1>')
コード例 #26
0
class DummyView(View):
    context_title: Annotated[DummyContext, Context(), Attr('title')]
    resource_title: Annotated[DummyContext, Get(Resource, attr='title')]

    def __call__(self) -> VDOM:
        return html('<div>Hello {self.context_title} from {self.resource_title}</div>')
コード例 #27
0
def test_attr(regular_container):
    attr = Attr('name')
    previous = FrenchCustomer()
    result = attr(previous, regular_container)
    assert 'French Customer' == result
コード例 #28
0
 class Heading:
     title: Annotated[
         str,
         Context(),
         Attr('name'),
     ]
コード例 #29
0
class View:
    customer_name: Annotated[str, Context(), Attr('name'), ]

    @property
    def name(self):
        return f'Hello {self.customer_name}'
コード例 #30
0
class ContextView:
    name: Annotated[str, Context(), Attr('name')]

    def __call__(self) -> str:
        return html('<div>Hello Customer</div>')