Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / chrome / common / jstemplate_builder.h
blobc867e7300cebcba055f367fbb68c17f1b69fd6d5
1 // Copyright (c) 2012 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.
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
13 #ifndef CHROME_COMMON_JSTEMPLATE_BUILDER_H_
14 #define CHROME_COMMON_JSTEMPLATE_BUILDER_H_
16 #include <string>
18 #include "base/string_piece.h"
20 namespace base {
21 class DictionaryValue;
24 namespace jstemplate_builder {
26 // While an object of this class is in scope, the template builder will output
27 // version 2 html. Version 2 uses load_time_data.js and i18n_template2.js, and
28 // should soon become the default.
29 class UseVersion2 {
30 public:
31 UseVersion2();
32 ~UseVersion2();
34 private:
35 DISALLOW_COPY_AND_ASSIGN(UseVersion2);
38 // A helper function that generates a string of HTML to be loaded. The
39 // string includes the HTML and the javascript code necessary to generate the
40 // full page with support for JsTemplates.
41 std::string GetTemplateHtml(const base::StringPiece& html_template,
42 const base::DictionaryValue* json,
43 const base::StringPiece& template_id);
45 // A helper function that generates a string of HTML to be loaded. The
46 // string includes the HTML and the javascript code necessary to generate the
47 // full page with support for i18n Templates.
48 std::string GetI18nTemplateHtml(const base::StringPiece& html_template,
49 const base::DictionaryValue* json);
51 // A helper function that generates a string of HTML to be loaded. The
52 // string includes the HTML and the javascript code necessary to generate the
53 // full page with support for both i18n Templates and JsTemplates.
54 std::string GetTemplatesHtml(const base::StringPiece& html_template,
55 const base::DictionaryValue* json,
56 const base::StringPiece& template_id);
58 // The following functions build up the different parts that the above
59 // templates use.
61 // Appends a script tag with a variable name |templateData| that has the JSON
62 // assigned to it.
63 void AppendJsonHtml(const base::DictionaryValue* json, std::string* output);
65 // Same as AppendJsonHtml(), except does not include the <script></script>
66 // tag wrappers.
67 void AppendJsonJS(const base::DictionaryValue* json, std::string* output);
69 // Appends the source for JsTemplates in a script tag.
70 void AppendJsTemplateSourceHtml(std::string* output);
72 // Appends the code that processes the JsTemplate with the JSON. You should
73 // call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this.
74 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id,
75 std::string* output);
77 // Appends the source for i18n Templates in a script tag.
78 void AppendI18nTemplateSourceHtml(std::string* output);
80 // Appends the code that processes the i18n Template with the JSON. You
81 // should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling
82 // this.
83 void AppendI18nTemplateProcessHtml(std::string* output);
85 } // namespace jstemplate_builder
86 #endif // CHROME_COMMON_JSTEMPLATE_BUILDER_H_