summaryrefslogtreecommitdiffstats
path: root/chrome/common/jstemplate_builder.h
blob: 3eda5a67d3817df9fb0b24a95294bdc0e72dc96f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This provides some helper methods for building and rendering an
// internal html page.  The flow is as follows:
// - instantiate a builder given a webframe that we're going to render content
//   into
// - load the template html and load the jstemplate javascript into the frame
// - given a json data object, run the jstemplate javascript which fills in
//   template values

#ifndef CHROME_COMMON_JSTEMPLATE_BUILDER_H_
#define CHROME_COMMON_JSTEMPLATE_BUILDER_H_
#pragma once

#include <string>

class DictionaryValue;
namespace base {
class StringPiece;
}

namespace jstemplate_builder {

// A helper function that generates a string of HTML to be loaded.  The
// string includes the HTML and the javascript code necessary to generate the
// full page with support for JsTemplates.
std::string GetTemplateHtml(const base::StringPiece& html_template,
                            const DictionaryValue* json,
                            const base::StringPiece& template_id);

// A helper function that generates a string of HTML to be loaded.  The
// string includes the HTML and the javascript code necessary to generate the
// full page with support for i18n Templates.
std::string GetI18nTemplateHtml(const base::StringPiece& html_template,
                                const DictionaryValue* json);

// A helper function that generates a string of HTML to be loaded.  The
// string includes the HTML and the javascript code necessary to generate the
// full page with support for both i18n Templates and JsTemplates.
std::string GetTemplatesHtml(const base::StringPiece& html_template,
                             const DictionaryValue* json,
                             const base::StringPiece& template_id);

// The following functions build up the different parts that the above
// templates use.

// Appends a script tag with a variable name |templateData| that has the JSON
// assigned to it.
void AppendJsonHtml(const DictionaryValue* json, std::string* output);

// Appends the source for JsTemplates in a script tag.
void AppendJsTemplateSourceHtml(std::string* output);

// Appends the code that processes the JsTemplate with the JSON. You should
// call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this.
void AppendJsTemplateProcessHtml(const base::StringPiece& template_id,
                                 std::string* output);

// Appends the source for i18n Templates in a script tag.
void AppendI18nTemplateSourceHtml(std::string* output);

// Appends the code that processes the i18n Template with the JSON. You
// should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling
// this.
void AppendI18nTemplateProcessHtml(std::string* output);

}  // namespace jstemplate_builder
#endif  // CHROME_COMMON_JSTEMPLATE_BUILDER_H_