Brightspot CMS Developer Guide

How the view generator creates view classes


When you build a theme, the view generator executes the following steps:

  1. Open the file styleguide/_config.json and look up the value for javaPackage. This value is the first component of the package name for the generated view files. Assign this value to <package>.
  2. Loop through each JSON file in the directory /styleguide/. For each file—
    1. Check for the existence of a _template key. If not found, continue to the next JSON file.
    2. Copy the file’s path, and duplicate the path under the directory target/generated-sources/styleguide/.
    3. In the JSON file, look up the value for _template, and extract the base name (file name without the hbs extension). Assign this value to <base>.
    4. Create a new class file View.java in the path from step b.
    5. Declare the class’s package as package <package>.<currentpath>, where  reflects the path from /styleguide/ to the current file.Each key inside the JSON file not starting with an underscore is assumed to be a displayed field. For each such key—
      1. Create a constructor inside the file View.java.
      2. Create a getter inside the file View.java. (At runtime, the getters populate the corresponding field in the template.)


Suppose you want to create a view for articles. Your theme files may look as follows:

_config.json

Data file specifying package name

{
    "javaPackage" : "brightspotnews"
}


Article.hbs

Template

<div class="Article">
    <div class="Article-headline">
        {{headline}}
    </div>
    <div class="Article-body">
        {{body}}
    </div>
    <div class="Article-image">
        <img src="{{image}}" alt="Alternate Text" />
    </div>
</div>


Article.json

Data file specifying associated template and source for method names

{
  "_template": "path/to/Article.hbs",
  "headline": "{{words(4)}}",
  "body": "{{paragraphs(2, 5, 15)}}",
  "image": "{{image(200, 200)}}"
}

Resulting file structure

The following diagram shows your directory structure after building the Brightspot project; the gray shading indicates those directories and files Brightspot created based on the data files.

Resulting file structure.svg Resulting file structure.svg

Resulting interface ArticleView.java

This file is a Java interface automatically generated by Brightspot’s view generator.

package brightspotnews.content.article; 

/* Imports */

/* Various annotations */

public interface ArticleView { 

    CharSequence getHeadline(); 

    CharSequence getBody();

    CharSequence getImage();

}
  • Interface’s package name.
    • The first component of the package name is the value for javaPackage as show in the snippet "Data file specifying package name."
    • The remaining components reflect the directory structure to Article.json under /styleguide/.
  • Declares the interface’s name. The name is based on the name of the discovered data file Article.json.
  • Declares a method getHeadline. The view generator derives this method’s name from the key headline as appearing in the snippet "Data file specifying associated template and source for method names." The other method names are derived similarly.

See also:

Previous Topic
Generating data files from published content
Next Topic
Generating Java view interfaces from data files
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News