diff --git a/examples/form_cta.py b/examples/form_cta.py index 6827477..062bef4 100644 --- a/examples/form_cta.py +++ b/examples/form_cta.py @@ -1,5 +1,6 @@ from splashgen import launch -from splashgen.components import SplashSite, Form, TextInput, EmailInput, SelectInput +from splashgen.templates import SplashSite +from splashgen.components import Form, TextInput, EmailInput, SelectInput site = SplashSite(title="Form example") site.headline = "Form example" diff --git a/examples/splashgen_site.py b/examples/splashgen_site.py index c3fc78d..07b4ada 100644 --- a/examples/splashgen_site.py +++ b/examples/splashgen_site.py @@ -1,5 +1,6 @@ from splashgen import launch -from splashgen.components import SplashSite, CTAButton +from splashgen.templates import SplashSite +from splashgen.components import CTAButton site = SplashSite(title="Splashgen - Splash Pages Built In Python", diff --git a/examples/splashgen_site_2.py b/examples/splashgen_site_2.py new file mode 100644 index 0000000..238a8ae --- /dev/null +++ b/examples/splashgen_site_2.py @@ -0,0 +1,26 @@ +from splashgen import launch +from splashgen.components import CTAButton, CTAButtonSecondary, Link +from splashgen.templates import SplashSite2 + +site = SplashSite2(title="Splashgen 2 - Splash Pages Built In Python", + theme="dark") + +site.nav_bar_center_link = Link( + "https://github.com/true3dco/splashgen", "About Us" +) +site.nav_bar_right_link = Link( + "https://github.com/true3dco/splashgen", "Sign Up" +) + +site.headline = "Build your splash page 2 in python effortlessly" +site.subtext = """ +In less than 20 lines of python, create clean and beautiful splash pages with +Splashgen. Don't waste time with no-code tools when you already know how to +code. +""" +site.primary_call_to_action = CTAButton( + "https://github.com/true3dco/splashgen", "View on GitHub") +site.secondary_call_to_action = CTAButtonSecondary( + "https://github.com/true3dco/splashgen", "View on GitHub") + +launch(site) diff --git a/examples/zenweb.py b/examples/zenweb.py index 1302336..4717758 100644 --- a/examples/zenweb.py +++ b/examples/zenweb.py @@ -1,6 +1,6 @@ from os import path from splashgen import MetaTags, launch -from splashgen.components import SplashSite +from splashgen.templates import SplashSite from splashgen.integrations import MailchimpSignup site = SplashSite(title="ZenWeb – Python Internal Web Apps", diff --git a/setup.py b/setup.py index a13b338..9571b95 100644 --- a/setup.py +++ b/setup.py @@ -31,5 +31,5 @@ "splashgen=splashgen.cli:main", ] }, - package_data={'splashgen': ['templates/*.jinja', 'assets/*.png']}, + package_data={'splashgen': ['jinja_templates/*.jinja', 'assets/*.png']}, ) diff --git a/splashgen/__init__.py b/splashgen/__init__.py index bd909e5..3f098b8 100644 --- a/splashgen/__init__.py +++ b/splashgen/__init__.py @@ -6,8 +6,8 @@ from jinja2 import Environment, PackageLoader - -jinja = Environment(loader=PackageLoader("splashgen"), autoescape=False) +jinja = Environment(loader=PackageLoader( + "splashgen", "jinja_templates"), autoescape=False) _assigned_component = None diff --git a/splashgen/assets/video-default.mp4 b/splashgen/assets/video-default.mp4 new file mode 100644 index 0000000..e28468e Binary files /dev/null and b/splashgen/assets/video-default.mp4 differ diff --git a/splashgen/components/__init__.py b/splashgen/components/__init__.py index 7adbb3a..59f41c1 100644 --- a/splashgen/components/__init__.py +++ b/splashgen/components/__init__.py @@ -1,3 +1,4 @@ -from .SplashSite import SplashSite -from .CTAButton import CTAButton +from .cta_button import CTAButton +from .cta_button_secondary import CTAButtonSecondary from .form import Form, TextInput, EmailInput, SelectInput +from .link import Link diff --git a/splashgen/components/CTAButton.py b/splashgen/components/cta_button.py similarity index 100% rename from splashgen/components/CTAButton.py rename to splashgen/components/cta_button.py diff --git a/splashgen/components/cta_button_secondary.py b/splashgen/components/cta_button_secondary.py new file mode 100644 index 0000000..656abdc --- /dev/null +++ b/splashgen/components/cta_button_secondary.py @@ -0,0 +1,10 @@ +from splashgen import Component + + +class CTAButtonSecondary(Component): + def __init__(self, link: str, text: str) -> None: + self.link = link + self.text = text + + def render(self) -> str: + return f'{self.text}' diff --git a/splashgen/components/link.py b/splashgen/components/link.py new file mode 100644 index 0000000..82bbf1e --- /dev/null +++ b/splashgen/components/link.py @@ -0,0 +1,10 @@ +from splashgen import Component + + +class Link(Component): + def __init__(self, link: str, text: str) -> None: + self.link = link + self.text = text + + def render(self) -> str: + return f'{self.text}' diff --git a/splashgen/templates/form.html.jinja b/splashgen/jinja_templates/form.html.jinja similarity index 100% rename from splashgen/templates/form.html.jinja rename to splashgen/jinja_templates/form.html.jinja diff --git a/splashgen/templates/input.html.jinja b/splashgen/jinja_templates/input.html.jinja similarity index 100% rename from splashgen/templates/input.html.jinja rename to splashgen/jinja_templates/input.html.jinja diff --git a/splashgen/templates/mailchimp_signup.html.jinja b/splashgen/jinja_templates/mailchimp_signup.html.jinja similarity index 100% rename from splashgen/templates/mailchimp_signup.html.jinja rename to splashgen/jinja_templates/mailchimp_signup.html.jinja diff --git a/splashgen/templates/splash_site.html.jinja b/splashgen/jinja_templates/splash_site.html.jinja similarity index 100% rename from splashgen/templates/splash_site.html.jinja rename to splashgen/jinja_templates/splash_site.html.jinja diff --git a/splashgen/jinja_templates/splash_site_2.html.jinja b/splashgen/jinja_templates/splash_site_2.html.jinja new file mode 100644 index 0000000..1b25411 --- /dev/null +++ b/splashgen/jinja_templates/splash_site_2.html.jinja @@ -0,0 +1,146 @@ + + + + + + + {{ title }} + {% for favicon in favicons %} + + {% endfor %} + + {% if meta %} + + + + + + {% if meta.canonical_url %} + + + {% endif %} + + + + + + + {% if meta.image %} + + + {% endif %} {% endif %} + + + + {% if enable_splashgen_analytics %} + + + {% endif %} + + +
+ {# Nav bar #} +
+ {% if logo %} + + {% endif %} + {% if nav_bar_center_link %} + {{ nav_bar_center_link }} + {% endif %} + {% if nav_bar_right_link %} + {{ nav_bar_right_link }} + {% endif %} + +
+

+ {{ headline }} +

+
+

+ {{ subtext }} +

+
+ + {% if primary_call_to_action %} + {{ primary_call_to_action }} + {% endif %} + + {% if secondary_call_to_action %} + {{ secondary_call_to_action }} + {% endif %} + + {% if hero_video %} +
+
+ {% endif %} +
+ + diff --git a/splashgen/templates/__init__.py b/splashgen/templates/__init__.py new file mode 100644 index 0000000..6cee7f1 --- /dev/null +++ b/splashgen/templates/__init__.py @@ -0,0 +1,2 @@ +from .splash_site import SplashSite +from .splash_site_2 import SplashSite2 diff --git a/splashgen/components/SplashSite.py b/splashgen/templates/base.py similarity index 70% rename from splashgen/components/SplashSite.py rename to splashgen/templates/base.py index 2386cc3..181b674 100644 --- a/splashgen/components/SplashSite.py +++ b/splashgen/templates/base.py @@ -1,18 +1,17 @@ -from splashgen import Component, MetaTags from os import path +from typing import Dict + from PIL import Image +from splashgen import Component, MetaTags _ASSET_DIR = path.join(path.dirname(__file__), '../assets') # TODO: Render favicons, touch icon, splash icons, etc. # TODO: Support BG color? -class SplashSite(Component): - meta: MetaTags - headline: str - subtext: str - call_to_action: Component - hero_image: str +class Template(Component): + template = "" + enable_splashgen_analytics: bool """Set this to false to disable analytics. @@ -20,7 +19,7 @@ class SplashSite(Component): track any personally-identifiable information on users visiting your site. """ - def __init__(self, title: str = "Splash Site", logo: str = None, meta: MetaTags = None, theme: str = "light") -> str: + def __init__(self, title: str = "Website", logo: str = None, meta: MetaTags = None, theme: str = "light") -> None: super().__init__() self.title = title if not logo: @@ -31,26 +30,9 @@ def __init__(self, title: str = "Splash Site", logo: str = None, meta: MetaTags raise ValueError( "Invalid theme option. Please specify 'light' or 'dark'") self.theme = theme - self.headline = "Fill out your headline here by assigning to `headline`" - self.subtext = "Fill out subtext by assigning to `subtext`" - self.call_to_action = None - self.hero_image = None self.favicon_img = self.logo self.enable_splashgen_analytics = True - def render(self) -> str: - logo_url = self.write_asset_to_build(self.logo) - if self.hero_image: - hero_img_url = self.write_asset_to_build(self.hero_image) - else: - hero_img_url = None - favicons = self._gen_favicons() - return self.into_template("splash_site.html.jinja", extras={ - "logo": logo_url, - "favicons": favicons, - "hero_image": hero_img_url, - }) - def _gen_favicons(self): favicons = [] with Image.open(self.favicon_img) as img: @@ -66,3 +48,19 @@ def _gen_favicons(self): favicon_info["filename"])) favicons.append(favicon_info) return favicons + + def render(self) -> str: + if not self.template: + raise ValueError("A Jinja template path must must be supplied " + "to the template attribute.") + logo_url = self.write_asset_to_build(self.logo) + favicons = self._gen_favicons() + return self.into_template(self.template, extras={ + "logo": logo_url, + "favicons": favicons, + **self.prep_extras(), + }) + + def prep_extras(self) -> Dict: + """Override in subclasses to supply extra information to templates""" + return {} diff --git a/splashgen/templates/splash_site.py b/splashgen/templates/splash_site.py new file mode 100644 index 0000000..5011581 --- /dev/null +++ b/splashgen/templates/splash_site.py @@ -0,0 +1,29 @@ +from typing import Dict +from splashgen import Component +from .base import Template + + +class SplashSite(Template): + headline: str + subtext: str + call_to_action: Component + hero_image: str + + template = "splash_site.html.jinja" + + def __init__(self, **kwargs) -> str: + super().__init__(**kwargs) + + self.headline = "Fill out your headline here by assigning to `headline`" + self.subtext = "Fill out subtext by assigning to `subtext`" + self.call_to_action = None + self.hero_image = None + + def prep_extras(self) -> Dict: + if self.hero_image: + hero_img_url = self.write_asset_to_build(self.hero_image) + else: + hero_img_url = None + return { + "hero_image": hero_img_url, + } diff --git a/splashgen/templates/splash_site_2.py b/splashgen/templates/splash_site_2.py new file mode 100644 index 0000000..912c355 --- /dev/null +++ b/splashgen/templates/splash_site_2.py @@ -0,0 +1,36 @@ +from typing import Dict +from splashgen.components import CTAButton, CTAButtonSecondary, Link +from .base import Template + + +class SplashSite2(Template): + nav_bar_center_link: Link + nav_bar_right_link: Link + headline: str + subtext: str + primary_call_to_action: CTAButton + secondary_call_to_action: CTAButtonSecondary + hero_video: str + + template = "splash_site_2.html.jinja" + + def __init__(self, **kwargs) -> str: + super().__init__(**kwargs) + + self.headline = "Fill out your headline here by assigning to `headline`" + self.subtext = "Fill out subtext by assigning to `subtext`" + self.call_to_action = None + self.primary_call_to_action = None + self.secondary_call_to_action = None + self.hero_video = None + self.nav_bar_center_link = None + self.nav_bar_right_link = None + + def prep_extras(self) -> Dict: + if self.hero_video: + hero_video_url = self.write_asset_to_build(self.hero_video) + else: + hero_video_url = None + return { + "hero_video": hero_video_url, + }