### Install brand_yml from PyPI Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-py/README.md Install the brand_yml package using pip from the Python Package Index. ```bash uv pip install brand_yml ``` -------------------------------- ### Install brand_yml from GitHub Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-py/README.md Install the brand_yml package directly from its GitHub repository using pip. ```bash uv pip install "git+https://github.com/posit-dev/brand-yml" ``` -------------------------------- ### Complete _brand.yml Example Source: https://github.com/posit-dev/brand-yml/blob/main/docs/articles/llm-brand-yml-prompt/brand-yml.prompt.txt This example demonstrates all allowed features of a _brand.yml file, including meta information, logo configurations, color palettes, and typography settings. All fields are optional and should only be included if they directly apply to the brand. ```yaml meta: # name: Acme # ALT: Single string for simple company name name: short: Acme # Short company name full: Acme Corporation International # Full, legal company name # link: https://acmecorp.com # ALT: single url for the company's home page link: home: https://www.acmecorp.com # Company's home apge bluesky: https://bsky.app/profile/acmecorp.bsky.social # Bluesky social media account link github: https://github.com/acmecorp # GitHub account link mastodon: https://mastodon.social/@acmecorp # Mastodon account link linkedin: https://www.linkedin.com/company/acmecorp # LinkedIn account link facebook: https://www.facebook.com/acmecorp # Facebook account link twitter: https://twitter.com/acmecorp # Twitter account link logo: images: # Mapping of image names to local files that should be stored next to the _brand.yml file. Users may need to download these files manually. header: logos/header-logo.png # Each entry maps a name to a local file header-white: logos/header-logo-white.png full: # ALT: Images can alternatively be a path with associated alt text for accessibility path: logos/full-logo.svg alt: Acme logo. small: logos/icon.png # A small image, ideally icon-sized. Can be a path to a file or the name of a file in `logo.images` medium: # A medium sized logo, ideally small enough for a sidebar logo # ALT: Logos is small, medium, and large may have `light` and `dark` variants light: header # light variant for use on light backgrounds dark: header-white # dark variant for use on dark backgrounds large: full # A large logo, e.g. for use in a hero or cover page. ALT: Can refer directly to images in `logo.images`. color: palette: # Dictionary of the brand's colors with readable names. # Must be a flat list of names and color values. # Names should be follow Sass variable conventions. Prefer hex color values. # Prefer or create aliases for Bootstrap primary colors: blue, indigo, purple, pink, red, orange, yellow, green, teal, cyan, white, black white: "#FFFFFF" black: "#151515" blue: "#447099" orange: "#EE6331" green: "#72994E" teal: "#419599" burgundy: "#9A4665" purple: burgundy # Aliases are allowed by referring to other colors in `color.palette` fire-red: "#FF0000" bright-yellow: "#FFFF00" # All theme colors can take direct color values, and all are optional. # Only include the colors that are obviously required. # Refer to color names from `color.palette` whenever possible. foreground: "#151515" # Main text color, should have high contrast with background background: "#FFFFFF" # Main background color, should have high contrast with foreground primary: "#447099" # Main accent color for links, buttons, etc. secondary: "#707073" # Used for lighter text or disabled states. Only include if necessary. tertiary: "#C2C2C4" # Even lighter color for hover states, accents, wells. Only include if necessary. success: "#72994E" # Color for positive or successful actions/information info: "#419599" # Color for neutral or informational actions/information warning: "#EE6331" # Color for warning or cautionary actions/information, danger: "#9A4665" # Color for errors, dangerous actions, negative information light: "#FFFFFF" # Bright color for high-contrast on dark elements dark: "#404041" # Dark color for high-contrast on light elements # ALT: All properties in `color` can refer by name to values in `color.palette`, including within `color.palette`. # foreground: black # background: white # primary: blue # success: green # info: teal # ALT: All properties in `color` can refer by name to other properties in `color`. typography: fonts: - family: Open Sans # Font family name source: file # Source of the font (file, google, bunny, or system) files: # REQUIRED list of font files for `source: file`, which must have at least one font file. Use placeholder names and comment out the source font section if proprietary fonts are used. (And include a Google Font alternative recommendation.) - path: fonts/open-sans/OpenSans-Variable.ttf # Each file corresponds to a weight and style, both default to "normal". weight: 400 # Optional: specify weight for this file style: normal # Optional: specify style for this file ``` -------------------------------- ### Install brand.yml from R-universe Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/README.md Install the brand.yml package from the posit-dev R-universe repository, specifying both the universe and CRAN as sources. ```r install.packages( 'brand.yml', repos = c('https://posit-dev.r-universe.dev', 'https://cloud.r-project.org') ) ``` -------------------------------- ### Install brand.yml Development Version from GitHub Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/README.md Install the development version of brand.yml directly from its GitHub repository using the pak package. ```r # install.packages("pak") pak::pak("posit-dev/brand-yml/pkg-r") ``` -------------------------------- ### Full Brand Logo Configuration Example Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md Demonstrates a complete and valid configuration for brand logos, showcasing various image sizes and variants. ```R brand$logo ``` -------------------------------- ### Install brand.yml from CRAN Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/README.md Use this command to install the latest stable release of the brand.yml package from CRAN. ```r install.packages("brand.yml") ``` -------------------------------- ### Read brand.yml file into R Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/README.md Use read_brand_yml() to load a brand.yml file into a structured R list. It can read from a specified path or automatically find a _brand.yml in the project. The example shows reading a specific example file and inspecting its color palette. ```r library(brand.yml) brand <- read_brand_yml( system.file("examples", "brand-posit.yml", package = "brand.yml") ) brand$color |> str() #> List of 12 #> $ palette :List of 7 #> ..$ blue : chr "#447099" #> ..$ orange : chr "#EE6331" #> ..$ gray : chr "#404041" #> ..$ white : chr "#FFFFFF" #> ..$ teal : chr "#419599" #> ..$ green : chr "#72994E" #> ..$ burgundy: chr "#9A4665" #> $ foreground: chr "#151515" #> $ background: chr "#FFFFFF" #> $ primary : chr "#447099" #> $ secondary : chr "#707073" #> $ tertiary : chr "#C2C2C4" #> $ success : chr "#72994E" #> $ info : chr "#419599" #> $ warning : chr "#EE6331" #> $ danger : chr "#9A4665" #> $ light : chr "#FFFFFF" #> $ dark : chr "#404041" ``` -------------------------------- ### Access Base Typography Model Dump Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-py/README.md Get a dictionary representation of the base typography settings, including family, weight, size, and line height. ```python brand.typography.base.model_dump() ``` -------------------------------- ### Validate Unexpected Typography Fields Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Detects and reports any fields within the 'typography' list that are not recognized. For example, 'bad' is an unexpected field. ```R as_brand_yml(list(typography = list(bad = "foo"))) ``` -------------------------------- ### Modify and Re-validate Schema Source: https://github.com/posit-dev/brand-yml/blob/main/schema/validate-json-schema.md Modifies the schema by filtering its definitions to include only those starting with 'Brand' and then re-validates it. This is useful for isolating specific parts of a larger schema for targeted validation. ```python schema["$defs"] = {k: v for k, v in schema["$defs"].items() if k.startswith("Brand")} # not required but useful for brand-yaml work # schema["type"] = "object" # schema["properties"] = {"brand": {"$ref": "#/$defs/Brand"}} schema["$ref"] = "#/$defs/Brand" validate_json_schema(schema) ``` -------------------------------- ### Print Default Brand Configuration Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/read_brand_yml.md This snippet shows how to print the default brand configuration loaded from a YAML file. Ensure the '_brand.yml' file is accessible in the working directory. ```R print(brand) ``` -------------------------------- ### Load Brand Guidelines from YAML String Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-py/README.md Load brand guidelines from a YAML string into a Brand object. Typically, this YAML content is read from a `_brand.yml` file. ```python from brand_yml import Brand brand = Brand.from_yaml_str( # Typically, this file is stored in `_brand.yml` # and read with `Brand.from_yaml()`. """ meta: name: Posit Software, PBC link: https://posit.co color: palette: pblue: "#447099" green: "#72994E" teal: "#419599" orange: "#EE6331" purple: "#9A4665" gray: "#707073" primary: blue secondary: gray success: green info: teal warning: orange danger: purple typography: base: family: Open Sans weight: 300 """ ) ``` -------------------------------- ### Format Light/Dark Logo to HTML with Attributes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Converts a light/dark logo resource into HTML with custom attributes, rendering separate `` tags for light and dark content. This allows for customized styling and dimensions for both logo variants. ```r cat(format(logo_light_dark, .format = "html", class = "custom-logo", width = 200)) ``` -------------------------------- ### Load JSON Schema from File Source: https://github.com/posit-dev/brand-yml/blob/main/schema/validate-json-schema.md Loads a JSON schema from a specified local path. Ensure the path to the schema file is correctly set for your environment. ```python import json from pathlib import Path import jsonschema from jsonschema import Draft202012Validator # NEEDS TO BE DONE LOCALLY, UPDATE PATH TO MATCH YOUR LOCAL SETUP # From Quarto revision 88819d5b9f092381d5d20a146ac3121dc2435acc (v1.6.37) quarto_local_path = Path("~/work/quarto-dev/quarto-cli") schema_path = quarto_local_path.expanduser().joinpath("src/resources/schema/json-schemas.json") if not schema_path.exists(): raise FileNotFoundError(f"Path {schema_path} does not exist") with open(schema_path, 'r') as schema_file: schema = json.load(schema_file) ``` -------------------------------- ### Handle logo.images as a string error Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md When `logo.images` is expected to be a list but is provided as a string, this error occurs. ```R as_brand_yml(list(logo = list(images = "foo.png"))) ``` -------------------------------- ### Handle logo.images.light as a number error Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md An error occurs if `logo.images.light` is a number when it should be a string or a list. ```R as_brand_yml(list(logo = list(images = list(light = 1234)))) ``` -------------------------------- ### Format Logo to HTML Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Converts a single logo resource into an HTML `` tag. Use this for standard HTML output. ```r cat(format(logo_resource, .format = "html")) ``` -------------------------------- ### Format Logo to HTML with Attributes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Converts a single logo resource into an HTML `` tag with custom attributes like class and width. Specify attributes to customize the rendered image. ```r cat(format(logo_resource, .format = "html", class = "custom-logo", width = 200)) ``` -------------------------------- ### Handle logo with unknown names error Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md Providing unknown names within the `logo` list, such as 'unknown', results in an error, specifying the allowed names. ```R as_brand_yml(list(logo = list(unknown = "foo.png"))) ``` -------------------------------- ### format() - Light/Dark Brand Logo Resource to HTML Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a `brand_logo_resource_light_dark` object as HTML by default. It renders two `` tags, one for light and one for dark content. ```R cat(format(logo_light_dark)) ``` -------------------------------- ### format() - Brand Logo Resource to Markdown Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a `brand_logo_resource` object as Markdown. The output is an image link with associated attributes. ```R cat(format(logo_resource, .format = "markdown")) ``` -------------------------------- ### format() - Light/Dark Brand Logo Resource to HTML with Attributes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a `brand_logo_resource_light_dark` object as HTML, applying custom attributes to both the light and dark content `` tags. ```R cat(format(logo_light_dark, class = "my-logo", width = 100, height = 50)) ``` -------------------------------- ### format() - Brand Logo Resource to HTML Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a `brand_logo_resource` object as HTML, which is the default behavior. The output includes an `` tag with base64 encoded image data. ```R cat(format(logo_resource)) ``` -------------------------------- ### format() - Brand Logo Resource to HTML with Attributes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a `brand_logo_resource` object as HTML, adding custom attributes like `class`, `width`, and `height` to the `` tag. ```R cat(format(logo_resource, class = "my-logo", width = 100, height = 50)) ``` -------------------------------- ### Initial Schema Validation Source: https://github.com/posit-dev/brand-yml/blob/main/schema/validate-json-schema.md Performs an initial validation of the loaded schema against the Draft2020-12 specification. This step helps identify any immediate structural issues with the schema itself. ```python validate_json_schema(schema) ``` -------------------------------- ### Format Logo to Markdown Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a light/dark logo resource into Markdown image tags. Use this for basic Markdown output. ```r cat(format(logo_light_dark, .format = "markdown")) ``` -------------------------------- ### Format Light/Dark Logo to HTML Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Converts a light/dark logo resource into HTML, rendering separate `` tags for light and dark content within a span. This is suitable for environments that support distinct light and dark modes. ```r cat(format(logo_light_dark, .format = "html")) ``` -------------------------------- ### Format Logo to Markdown with Attributes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a light/dark logo resource into Markdown image tags with additional custom attributes like class and width. Specify attributes to customize the rendered image. ```r cat(format(logo_light_dark, .format = "markdown", class = "my-logo", width = 100)) ``` -------------------------------- ### Format Logo to Markdown with Vector Classes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a light/dark logo resource into Markdown image tags, handling a vector of classes for more complex styling. This allows multiple classes to be applied to the logo. ```r cat(format(logo_light_dark, .format = "markdown", class = c("my-logo", "my-logo-other"))) ``` -------------------------------- ### brand_use_logo() - No Logos Available Errors Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Shows errors when no logos are available for the specified brand. This occurs when `brand_no_logos` is used. ```R brand_use_logo(brand_no_logos, name = "smallest", .required = TRUE) ``` ```R brand_use_logo(brand_no_logos, name = "largest", .required = "for header display") ``` -------------------------------- ### format() - Brand Logo Resource to Markdown with Attributes Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Formats a `brand_logo_resource` object as Markdown, including custom attributes such as `class` and `width`. ```R cat(format(logo_resource, .format = "markdown", class = "my-logo", width = 100)) ``` -------------------------------- ### Handle logo as a number error Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md When `logo` is provided as a number, an error is raised indicating it must be a string or a list. ```R as_brand_yml(list(logo = 1234)) ``` -------------------------------- ### brand_use_logo() - Required Logo Errors Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Demonstrates errors when a required logo is not found. Use `.required = TRUE` to enforce logo presence. ```R brand_use_logo(brand, name = "large", .required = TRUE) ``` ```R brand_use_logo(brand, name = "large", .required = "for header display") ``` ```R brand_use_logo(brand, name = "tiny") ``` -------------------------------- ### GTM Head Snippet Initialization Source: https://github.com/posit-dev/brand-yml/blob/main/docs/_partials/gtm-head.html This snippet initializes the Google Tag Manager data layer and loads the GTM container. It should be placed in the of your HTML document. ```javascript (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-KHBDBW7'); ``` -------------------------------- ### Handle logo with unexpected names error Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md If the `logo` list contains names other than 'path' or 'alt', an error is triggered. ```R as_brand_yml(list(logo = list(path = "foo", bad = "foo"))) ``` -------------------------------- ### Error Handling for Uninitialized Brand Object Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md This R code demonstrates an error condition when attempting to use `brand_sass_fonts()` with a brand object that has not been properly initialized with a file path. Ensure the `brand` object is loaded from disk or has a `path` field. ```r brand_sass_fonts(brand) # Condition # Error in `brand_path_dir()`: # ! `brand` must have been read from a file on disk or have a `path` field. ``` -------------------------------- ### brand_use_logo() - Variant Errors Without Fallback Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Illustrates errors when a specific logo variant is required but not available, and fallback is disallowed with `.allow_fallback = FALSE`. ```R brand_use_logo(brand, "small", variant = "light", .required = TRUE, .allow_fallback = FALSE) ``` ```R brand_use_logo(brand, "small", variant = "dark", .required = "for header display", .allow_fallback = FALSE) ``` ```R brand_use_logo(brand, "large", variant = "light", .required = "for light plot icons", .allow_fallback = FALSE) ``` -------------------------------- ### brand_use_logo() - Light/Dark Variant Requirement Errors Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Handles errors when requesting a 'light-dark' variant for a logo that only supports individual light or dark variants, without fallback. ```R brand_use_logo(brand, name = "small", variant = "light-dark", .required = TRUE, .allow_fallback = FALSE) ``` ```R brand_use_logo(brand, name = "small", variant = "light-dark", .required = "for theme support", .allow_fallback = FALSE) ``` -------------------------------- ### Access Brand Metadata Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-py/README.md Access the 'name' attribute from the 'meta' section of the loaded brand guidelines. ```python brand.meta.name ``` -------------------------------- ### Generate Brand Fonts SASS Layer Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Prints the SASS variables and CSS classes generated for brand fonts, including font-family definitions and corresponding CSS rules. ```R cat(format(brand_fonts_sass_layer)) ``` -------------------------------- ### Write Modified Schema to File Source: https://github.com/posit-dev/brand-yml/blob/main/schema/validate-json-schema.md Saves the modified JSON schema to a file named 'brand.schema.json' in the current directory. The schema is formatted with an indent of 2 spaces for readability. ```python import json from pathlib import Path with Path(".").joinpath("brand.schema.json").open("w") as f: f.write(json.dumps(schema, indent=2)) ``` -------------------------------- ### Handle invalid value for logo.small error Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_logo.md This error is raised when an invalid value is assigned to `logo.small`, as it expects a string or a list. ```R as_brand_yml(list(logo = list(small = 1234))) ``` -------------------------------- ### Validate Base Typography Weight Type (Decimal) Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that 'typography.base.weight' is a whole number. Providing a decimal number will result in an error. ```R as_brand_yml(list(typography = list(base = list(weight = 100.5)))) ``` -------------------------------- ### Validate Base Typography Background-Color Field Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Confirms that 'typography.base.background-color' is not used, as it's an disallowed field. Its use will result in an error. ```R as_brand_yml(list(typography = list(base = list(`background-color` = "red")))) ``` -------------------------------- ### check_enum() Fails with NULL when Allow Null is False Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/check.md Shows check_enum() failing when the input is NULL and 'allow_null' is set to FALSE. Set 'allow_null' to TRUE if NULL inputs are permissible. ```R test_check_enum(NULL, values = letters[1:5], allow_null = FALSE) ``` -------------------------------- ### Access Primary Brand Color Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-py/README.md Retrieve the primary brand color defined in the 'color' section of the brand guidelines. ```python brand.color.primary ``` -------------------------------- ### Validate Font Definition Completeness Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Confirms that each font entry in 'typography.fonts' includes both 'family' and 'source' fields. Missing either field results in an error. ```R as_brand_yml(list(typography = list(fonts = list(list(source = "bad"))))) ``` ```R as_brand_yml(list(typography = list(fonts = list(list(weight = 400))))) ``` -------------------------------- ### Validate Headings Color Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Verifies that 'typography.headings.color' is a string or NULL. Providing a number will result in a validation error. ```R as_brand_yml(list(typography = list(headings = list(color = 42)))) ``` -------------------------------- ### check_enum() Fails with Duplicates when Allow Duplicates is False Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/check.md Demonstrates check_enum() failing when the input contains duplicate values and 'allow_dups' is set to FALSE. Set 'allow_dups' to TRUE to permit duplicate entries. ```R test_check_enum(c("a", "a"), values = letters[1:5], allow_dups = FALSE) ``` -------------------------------- ### Validate Font Source Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that the 'typography.fonts' setting is a list. If it's a string, an error is raised. ```R as_brand_yml(list(typography = list(fonts = "foo"))) ``` -------------------------------- ### Validate Font Source Enum Values Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Checks if the provided font 'source' value is one of the allowed options ('system', 'file', 'google', 'bunny'). Using an invalid source triggers an error. ```R as_brand_yml(list(typography = list(fonts = list(list(family = "foo", source = "bad"))))) ``` -------------------------------- ### Render Logo in knitr Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_use_logo.md Renders a single brand logo resource within a knitr document. This method is used by knitr to display the logo directly in the output. ```r cat(result$out) ``` -------------------------------- ### Validate Base Typography Size Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Checks if 'typography.base.size' is a string or NULL. Providing a number will trigger a validation error. ```R as_brand_yml(list(typography = list(base = list(size = 42)))) ``` -------------------------------- ### Validate Base Typography Weight Enum Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Verifies that the 'typography.base.weight' value is one of the allowed enumerated strings. Using an invalid string like 'bad' will cause an error. ```R as_brand_yml(list(typography = list(base = list(weight = "bad")))) ``` -------------------------------- ### Validate Font Source Value Type (Boolean) Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that font sources are not boolean values. If a boolean is provided, an error is raised. ```R as_brand_yml(list(typography = list(fonts = list(source = TRUE)))) ``` -------------------------------- ### check_enum() Fails with Invalid Single Value Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/check.md Demonstrates how check_enum() fails when the input is a single value not present in the allowed 'values' list. Ensure the input matches one of the specified values. ```R test_check_enum("X", values = letters[1:5]) ``` -------------------------------- ### Validate Base Typography Family Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that 'typography.base.family' is a string or NULL. Providing a number will result in a validation error. ```R as_brand_yml(list(typography = list(base = list(family = 42)))) ``` -------------------------------- ### Validate Base Typography Color Field Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that 'typography.base.color' is not used, as it's not an allowed field. Using it will raise an error. ```R as_brand_yml(list(typography = list(base = list(color = "red")))) ``` -------------------------------- ### Validate Headings Style Enum Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that 'typography.headings.style' values are within the allowed set ('normal', 'italic'). Using an invalid value or duplicates will cause an error. ```R as_brand_yml(list(typography = list(headings = list(style = "bad")))) ``` ```R as_brand_yml(list(typography = list(headings = list(style = rep("normal", 2)))))) ``` -------------------------------- ### check_enum() Fails with Multiple Values Exceeding Max Length Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/check.md Illustrates check_enum() failing when the input vector has more elements than allowed by 'max_len'. Set 'max_len' to accommodate the expected number of items. ```R test_check_enum(c("a", "b", "c"), values = letters[1:5], max_len = 2) ``` -------------------------------- ### Validate Font Family Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Ensures that the 'family' field for each font is a string or NULL. Providing a number will cause an error. ```R as_brand_yml(list(typography = list(fonts = list(list(family = 42))))) ``` -------------------------------- ### Validate Base Typography Line-Height Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Checks if 'typography.base.line-height' is a string or a number. Using NA will trigger a validation error. ```R as_brand_yml(list(typography = list(base = list(`line-height` = NA)))) ``` -------------------------------- ### Check Schema Validity Source: https://github.com/posit-dev/brand-yml/blob/main/schema/validate-json-schema.md Validates if a given Python dictionary representing a JSON schema conforms to the Draft2020-12 metaschema. It prints a success message or details of the validation error. ```python def validate_json_schema(schema): try: Draft202012Validator.check_schema(schema) print("Schema is valid according to JSON Schema 2020-12 specification.") except jsonschema.exceptions.SchemaError as e: print(f"Schema is invalid: {e}") ``` -------------------------------- ### Validate Font Source Value Type Source: https://github.com/posit-dev/brand-yml/blob/main/pkg-r/tests/testthat/_snaps/brand_typography.md Checks if individual font sources within 'typography.fonts' are lists. If a source is a string, an error is raised. ```R as_brand_yml(list(typography = list(fonts = list(source = "bad")))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.