Liking cljdoc? Tell your friends :D

clj-mjml.mjml

Clojure wrapper for ch.digitalfondue.mjml4j

Clojure wrapper for ch.digitalfondue.mjml4j
raw docstring

-mainclj

(-main & args)
source

classpath-resource-loaderclj

(classpath-resource-loader resource-path)

Loads a resource from the classpath.

Args: resource-path: String path to the resource (e.g., "templates/header.mjml")

Returns: String content of the resource

Throws: Exception if resource is not found

Loads a resource from the classpath.

Args:
  resource-path: String path to the resource (e.g., "templates/header.mjml")
  
Returns:
  String content of the resource
  
Throws:
  Exception if resource is not found
sourceraw docstring

cli-optionsclj

source

create-classpath-resolverclj

(create-classpath-resolver)

Creates an IncludeResolver that loads MJML includes from the classpath.

Useful for:

  • Loading templates packaged in JAR files
  • Using resources in src/resources directory
  • Referencing templates via classpath paths

Example: (def resolver (create-classpath-resolver)) (render template {:mj-include-resolver resolver})

MJML usage: <mj-include path="templates/header.mjml" />

Creates an IncludeResolver that loads MJML includes from the classpath.

Useful for:
- Loading templates packaged in JAR files
- Using resources in src/resources directory
- Referencing templates via classpath paths

Example:
  (def resolver (create-classpath-resolver))
  (render template {:mj-include-resolver resolver})
  
MJML usage:
  <mj-include path="templates/header.mjml" />
sourceraw docstring

create-custom-resolverclj

(create-custom-resolver loader-fn)

Creates a custom IncludeResolver using a provided loader function.

Args: loader-fn: Function that takes a resource path (String) and returns the MJML content (String)

Useful for:

  • Loading templates from databases
  • Fetching templates from remote URLs
  • Implementing custom caching strategies
  • Integration with existing template systems

Example: (def resolver (create-custom-resolver (fn [path] (db/fetch-template path)))) (render template {:mj-include-resolver resolver})

MJML usage: <mj-include path="email-templates/123" />

Creates a custom IncludeResolver using a provided loader function.

Args:
  loader-fn: Function that takes a resource path (String) and returns 
             the MJML content (String)

Useful for:
- Loading templates from databases
- Fetching templates from remote URLs
- Implementing custom caching strategies
- Integration with existing template systems

Example:
  (def resolver 
    (create-custom-resolver
      (fn [path]
        (db/fetch-template path))))
  (render template {:mj-include-resolver resolver})
  
MJML usage:
  <mj-include path="email-templates/123" />
sourceraw docstring

create-filesystem-resolverclj

(create-filesystem-resolver)
(create-filesystem-resolver base-path)

Creates an IncludeResolver that loads MJML includes from the filesystem.

Args: base-path: String or File representing the base directory for includes (defaults to current working directory if not provided)

Useful for:

  • Development workflows with local files
  • Loading templates from user directories
  • Dynamic template systems with file-based storage

Example: (def resolver (create-filesystem-resolver "/path/to/templates")) (render template {:mj-include-resolver resolver})

MJML usage: <mj-include path="partials/header.mjml" />

Creates an IncludeResolver that loads MJML includes from the filesystem.

Args:
  base-path: String or File representing the base directory for includes
             (defaults to current working directory if not provided)

Useful for:
- Development workflows with local files
- Loading templates from user directories
- Dynamic template systems with file-based storage

Example:
  (def resolver (create-filesystem-resolver "/path/to/templates"))
  (render template {:mj-include-resolver resolver})
  
MJML usage:
  <mj-include path="partials/header.mjml" />
sourceraw docstring

error-msgclj

(error-msg errors)
source

exitclj

(exit status msg)
source

make-configclj

(make-config {:keys [mj-include-resolver language text-direction]
              :or {language "en" text-direction :ltr}})

Internal function that creates an Mjml4j Configuration from an options map.

Most users should call render directly with an options map rather than calling this function.

Internal function that creates an Mjml4j Configuration from an options map.

Most users should call render directly with an options map rather than 
calling this function.
sourceraw docstring

renderclj

(render template)
(render template options)

Renders MJML to HTML.

Arity:

  • (render template): Render with default configuration (no includes).
  • (render template options): Render with specific configuration.

Options map: :mj-include-resolver - An IncludeResolver for handling mj-include tags. Use create-filesystem-resolver, create-classpath-resolver, or create-custom-resolver to create one. :language - Language code for the email (optional, defaults to "en"). Examples: "en", "fr", "es", "de" :text-direction - Text direction for the email (optional, defaults to :ltr). Use :ltr for left-to-right or :rtl for right-to-left languages.

Examples: Basic rendering: (render "<mjml>...</mjml>")

With filesystem includes: (render template {:mj-include-resolver (create-filesystem-resolver "/templates")})

With classpath includes: (render template {:mj-include-resolver (create-classpath-resolver)})

With custom loader: (render template {:mj-include-resolver (create-custom-resolver (fn [path] (fetch-from-db path)))})

With language and text direction (e.g., for Arabic emails): (render template {:mj-include-resolver resolver :language "ar" :text-direction :rtl})

Multiple options combined: (render template {:mj-include-resolver (create-classpath-resolver) :language "fr" :text-direction :ltr})

Renders MJML to HTML.

Arity:
- (render template): Render with default configuration (no includes).
- (render template options): Render with specific configuration.

Options map:
  :mj-include-resolver - An IncludeResolver for handling mj-include tags.
                         Use create-filesystem-resolver, create-classpath-resolver,
                         or create-custom-resolver to create one.
  :language            - Language code for the email (optional, defaults to "en").
                         Examples: "en", "fr", "es", "de"
  :text-direction      - Text direction for the email (optional, defaults to :ltr).
                         Use :ltr for left-to-right or :rtl for right-to-left languages.

Examples:
  Basic rendering:
    (render "<mjml>...</mjml>")
  
  With filesystem includes:
    (render template 
            {:mj-include-resolver (create-filesystem-resolver "/templates")})
  
  With classpath includes:
    (render template 
            {:mj-include-resolver (create-classpath-resolver)})
  
  With custom loader:
    (render template 
            {:mj-include-resolver 
             (create-custom-resolver 
               (fn [path] (fetch-from-db path)))})
  
  With language and text direction (e.g., for Arabic emails):
    (render template 
            {:mj-include-resolver resolver
             :language "ar"
             :text-direction :rtl})
  
  Multiple options combined:
    (render template
            {:mj-include-resolver (create-classpath-resolver)
             :language "fr"
             :text-direction :ltr})
sourceraw docstring

usageclj

(usage options-summary)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close