Class EmailLayout

java.lang.Object
io.meeds.portal.mail.util.EmailLayout

public final class EmailLayout extends Object
The one look of the emails of the platform: a header band in the brand color that carries the company name and the title, then a single column of text that follows the direction of the language (left to right, or right to left for Arabic, Hebrew, Persian...) with the action as a button. It is made of tables and inline styles, the only markup every mail client renders alike, and every text it is given is escaped.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    actionLink(EmailBrand brand, String label, String href, boolean primary)
    A button for an email that is laid out by its own template, such as a notification: a flat button with rounded corners.
    static String
    actionLink(String label, String href, boolean primary)
    The same button with the brand of the site
    static String
    The margin of a row of buttons that sits in the text column of an email with an avatar: it pulls the row back to the start of the content column, where the buttons of every other email are, on the left for a left to right language and on the right for a right to left one.
    static String
    The closing row of an email laid out by its own template: the space under the last block, as the account emails have, with no frame and no link (the button of the email and the plain address under it are the ways to the site)
    static String
    The dark styles of the notification emails, to put once before the header row: the colors of those templates are inline, the rules match them.
    static String
    dir(String lang)
     
    static String
    end(String lang)
     
    static String
    entityLink(String label, String url)
    The name of an entity (event, calendar, person, space) inside a sentence: escaped, bold and in the link color, a link when the address is a safe http or https one, plain bold text otherwise.
    static String
    Same as linkStyled(String) for the links that name a person, a space or any entity (built in Java, so without style): bold, in the link color, not underlined
    static String
    facts(String... labelsAndValues)
    A box of labelled values (where, when, who) in an email laid out by its own template: the quote look with a fixed label column.
    static String
    factsIn(String lang, String... labelsAndValues)
    Same as facts(String...), with the bar on the side where the text of lang starts
    static String
    The fonts of the text of an email that keeps its own template: the font of the platform branding first, then the fonts that every mail client has
    static String
     
    static String
    gap(String lang, String size)
     
    static String
    greeting(String hello, String name)
     
    static String
    headerRow(EmailBrand brand, String title)
    The header of an email as a table row, for the emails that are laid out by their own template (the notifications) and only share the look of the header: the company name and the title in the brand color
    static String
    headerRow(EmailBrand brand, String title, String lang)
    The same header for a reader whose language is written from right to left, when lang says so
    static boolean
    isRtl(String lang)
    Tells whether a language is written from right to left, as Arabic, Hebrew, Persian or Urdu are.
    static String
    leadIn(String sentence)
     
    static String
    The color of the links in the text of an email that keeps its own template, so that they follow the primary color of the site
    static String
     
    static String
    Gives the links of a label (the footer sentence that holds the link to the notification settings) the link style of the emails, as their only style attribute: the label may already carry one, and a tag with two of them is not valid
    static String
     
    static String
    Opens the block that quotes what somebody wrote (a message, a comment, a description) in an email laid out by its own template: a bar in the brand color and a light background, the same as the key value of the other emails.
    static String
    quoteStart(boolean spaceAfter)
    Same as quoteStart(); spaceAfter false leaves out the space under the box, for a quote that is the last block of its cell and is followed by a button, which brings its own space
    static String
    quoteStart(boolean spaceAfter, String lang)
    The general form: space under the box or not, bar on the start side of the language
    static String
    Same as quoteStart(), the bar on the side where the text of the language starts
    static String
    render(EmailModel model, EmailBrand brand)
     
    static String
    start(String lang)
     
    static String
    viewAction(String description, String label, String href)
    The action markup alone, for an email whose main link is in its text (a link in a quote) and has no button

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • greeting

      public static String greeting(String hello, String name)
      Returns:
      the greeting followed by the name of the reader, or by nothing but the comma when the name is not known
    • leadIn

      public static String leadIn(String sentence)
      Returns:
      the sentence that introduces a link, ended by a colon unless its translation already ends with a punctuation mark
    • isRtl

      public static boolean isRtl(String lang)
      Tells whether a language is written from right to left, as Arabic, Hebrew, Persian or Urdu are. The platform's own locale configuration only declares Arabic as such, so the direction of an email is taken from the language itself.
      Parameters:
      lang - a BCP 47 language tag or a Java locale name, such as ar, he-IL, fa_IR or ku-Arab
      Returns:
      true when the language, or its script, is written from right to left
    • render

      public static String render(EmailModel model, EmailBrand brand)
      Parameters:
      model - what the email says
      brand - how it is dressed
      Returns:
      the complete html document
      Throws:
      IllegalArgumentException - when the link of the button is not an http, https or mailto address
    • darkStyle

      public static String darkStyle()
      The dark styles of the notification emails, to put once before the header row: the colors of those templates are inline, the rules match them.
      Returns:
      a <style> element
    • headerRow

      public static String headerRow(EmailBrand brand, String title)
      The header of an email as a table row, for the emails that are laid out by their own template (the notifications) and only share the look of the header: the company name and the title in the brand color
      Parameters:
      brand - how the email is dressed
      title - the headline, in plain text
      Returns:
      a <tr> to include in a table
    • headerRow

      public static String headerRow(EmailBrand brand, String title, String lang)
      The same header for a reader whose language is written from right to left, when lang says so
    • quoteStart

      public static String quoteStart()
      Opens the block that quotes what somebody wrote (a message, a comment, a description) in an email laid out by its own template: a bar in the brand color and a light background, the same as the key value of the other emails. The text follows, then quoteEnd().
      Returns:
      the opening of a table that holds the quote
    • quoteStart

      public static String quoteStart(String lang)
      Same as quoteStart(), the bar on the side where the text of the language starts
    • quoteStart

      public static String quoteStart(boolean spaceAfter)
      Same as quoteStart(); spaceAfter false leaves out the space under the box, for a quote that is the last block of its cell and is followed by a button, which brings its own space
    • quoteStart

      public static String quoteStart(boolean spaceAfter, String lang)
      The general form: space under the box or not, bar on the start side of the language
    • quoteEnd

      public static String quoteEnd()
      Returns:
      the end of the block opened by quoteStart()
    • entityLink

      public static String entityLink(String label, String url)
      The name of an entity (event, calendar, person, space) inside a sentence: escaped, bold and in the link color, a link when the address is a safe http or https one, plain bold text otherwise.
      Parameters:
      label - the name, plain text
      url - the address it points to, or null
      Returns:
      the html of the name
    • facts

      public static String facts(String... labelsAndValues)
      A box of labelled values (where, when, who) in an email laid out by its own template: the quote look with a fixed label column. A pair whose value is blank is left out.
      Parameters:
      labelsAndValues - label, value, label, value...: the label is plain text, the value is html that the caller has already escaped
      Returns:
      the html of the box, or an empty text when no value is left
    • factsIn

      public static String factsIn(String lang, String... labelsAndValues)
      Same as facts(String...), with the bar on the side where the text of lang starts
    • buttonRowMargin

      public static String buttonRowMargin(String lang, String pull)
      The margin of a row of buttons that sits in the text column of an email with an avatar: it pulls the row back to the start of the content column, where the buttons of every other email are, on the left for a left to right language and on the right for a right to left one.
      Parameters:
      lang - the language of the email
      pull - the width of the avatar column, such as 64px
      Returns:
      the value of a margin declaration
    • linkStyled

      public static String linkStyled(String html)
      Gives the links of a label (the footer sentence that holds the link to the notification settings) the link style of the emails, as their only style attribute: the label may already carry one, and a tag with two of them is not valid
      Parameters:
      html - a label that holds <a> tags, or null
      Returns:
      the label whose links are underlined in the link color
    • entityStyled

      public static String entityStyled(String html)
      Same as linkStyled(String) for the links that name a person, a space or any entity (built in Java, so without style): bold, in the link color, not underlined
      Parameters:
      html - a label or a message that holds <a> tags, or null
      Returns:
      the same text whose links are styled as the names of the emails
    • closingRow

      public static String closingRow()
      The closing row of an email laid out by its own template: the space under the last block, as the account emails have, with no frame and no link (the button of the email and the plain address under it are the ways to the site)
      Returns:
      a <tr> to include in a table
    • actionLink

      public static String actionLink(EmailBrand brand, String label, String href, boolean primary)
      A button for an email that is laid out by its own template, such as a notification: a flat button with rounded corners. Buttons that follow each other sit on one line, as wide as their label and never wider than the screen, and wrap onto the next line when the screen is too narrow, so that they read the same on a computer and on a phone without a media query. The primary one is filled with the brand color; the secondary ones are quiet, outlined in the primary color, so that buttons side by side do not compete.
      Parameters:
      brand - how the email is dressed
      label - the text of the button, in plain text
      href - an http or https address; for any other address only the label is written
      primary - true for the main action of the email
      Returns:
      the html of the button
    • linkColor

      public static String linkColor()
      The color of the links in the text of an email that keeps its own template, so that they follow the primary color of the site
    • fontStack

      public static String fontStack()
      The fonts of the text of an email that keeps its own template: the font of the platform branding first, then the fonts that every mail client has
    • fontStack

      public static String fontStack(EmailBrand brand)
    • linkColor

      public static String linkColor(EmailBrand brand)
    • viewAction

      public static String viewAction(String description, String label, String href)
      The action markup alone, for an email whose main link is in its text (a link in a quote) and has no button
      Parameters:
      description - what the email is about, in plain text
      label - the name of the action, in plain text
      href - the address, which only counts when it is https
      Returns:
      the markup, or nothing for any other address
    • actionLink

      public static String actionLink(String label, String href, boolean primary)
      The same button with the brand of the site
    • dir

      public static String dir(String lang)
      Returns:
      rtl or ltr, for the dir attribute of a template that has to follow the direction of the reader's language
    • start

      public static String start(String lang)
      Returns:
      the side where text starts: left, or right in a right to left language
    • end

      public static String end(String lang)
      Returns:
      the side where text ends
    • gap

      public static String gap(String lang, String size)
      Parameters:
      size - such as 15px
      Returns:
      a padding that leaves a gap after the content, on the side where it ends: the gap between an avatar and the text beside it