jstemplate_builder.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This provides some helper methods for building and rendering an
6// internal html page.  The flow is as follows:
7// - instantiate a builder given a webframe that we're going to render content
8//   into
9// - load the template html and load the jstemplate javascript into the frame
10// - given a json data object, run the jstemplate javascript which fills in
11//   template values
12
13#ifndef CHROME_COMMON_JSTEMPLATE_BUILDER_H_
14#define CHROME_COMMON_JSTEMPLATE_BUILDER_H_
15#pragma once
16
17#include <string>
18
19class DictionaryValue;
20namespace base {
21class StringPiece;
22}
23
24namespace jstemplate_builder {
25
26// A helper function that generates a string of HTML to be loaded.  The
27// string includes the HTML and the javascript code necessary to generate the
28// full page with support for JsTemplates.
29std::string GetTemplateHtml(const base::StringPiece& html_template,
30                            const DictionaryValue* json,
31                            const base::StringPiece& template_id);
32
33// A helper function that generates a string of HTML to be loaded.  The
34// string includes the HTML and the javascript code necessary to generate the
35// full page with support for i18n Templates.
36std::string GetI18nTemplateHtml(const base::StringPiece& html_template,
37                                const DictionaryValue* json);
38
39// A helper function that generates a string of HTML to be loaded.  The
40// string includes the HTML and the javascript code necessary to generate the
41// full page with support for both i18n Templates and JsTemplates.
42std::string GetTemplatesHtml(const base::StringPiece& html_template,
43                             const DictionaryValue* json,
44                             const base::StringPiece& template_id);
45
46// The following functions build up the different parts that the above
47// templates use.
48
49// Appends a script tag with a variable name |templateData| that has the JSON
50// assigned to it.
51void AppendJsonHtml(const DictionaryValue* json, std::string* output);
52
53// Appends the source for JsTemplates in a script tag.
54void AppendJsTemplateSourceHtml(std::string* output);
55
56// Appends the code that processes the JsTemplate with the JSON. You should
57// call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this.
58void AppendJsTemplateProcessHtml(const base::StringPiece& template_id,
59                                 std::string* output);
60
61// Appends the source for i18n Templates in a script tag.
62void AppendI18nTemplateSourceHtml(std::string* output);
63
64// Appends the code that processes the i18n Template with the JSON. You
65// should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling
66// this.
67void AppendI18nTemplateProcessHtml(std::string* output);
68
69}  // namespace jstemplate_builder
70#endif  // CHROME_COMMON_JSTEMPLATE_BUILDER_H_
71