Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: ui/base/webui/jstemplate_builder.h

Issue 599653003: Remove old template html boilerplate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bydefault
Patch Set: fix android Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/browser/web_ui_data_source.h ('k') | ui/base/webui/jstemplate_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This provides some helper methods for building and rendering an 5 // This provides some helper methods for building and rendering an
6 // internal html page. The flow is as follows: 6 // internal html page. The flow is as follows:
7 // - instantiate a builder given a webframe that we're going to render content 7 // - instantiate a builder given a webframe that we're going to render content
8 // into 8 // into
9 // - load the template html and load the jstemplate javascript into the frame 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 10 // - given a json data object, run the jstemplate javascript which fills in
11 // template values 11 // template values
12 12
13 #ifndef UI_BASE_WEBUI_JSTEMPLATE_BUILDER_H_ 13 #ifndef UI_BASE_WEBUI_JSTEMPLATE_BUILDER_H_
14 #define UI_BASE_WEBUI_JSTEMPLATE_BUILDER_H_ 14 #define UI_BASE_WEBUI_JSTEMPLATE_BUILDER_H_
15 15
16 #include <string> 16 #include <string>
17 17
18 #include "base/strings/string_piece.h" 18 #include "base/strings/string_piece.h"
19 #include "ui/base/ui_base_export.h" 19 #include "ui/base/ui_base_export.h"
20 20
21 namespace base { 21 namespace base {
22 class DictionaryValue; 22 class DictionaryValue;
23 } 23 }
24 24
25 namespace webui { 25 namespace webui {
26 26
27 // While an object of this class is in scope, the template builder will output
28 // version 2 html. Version 2 uses load_time_data.js and i18n_template2.js, and
29 // should soon become the default.
30 class UI_BASE_EXPORT UseVersion2 {
31 public:
32 UseVersion2();
33 ~UseVersion2();
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(UseVersion2);
37 };
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 JsTemplates.
42 UI_BASE_EXPORT std::string GetTemplateHtml(
43 const base::StringPiece& html_template,
44 const base::DictionaryValue* json,
45 const base::StringPiece& template_id);
46
47 // A helper function that generates a string of HTML to be loaded. The 27 // A helper function that generates a string of HTML to be loaded. The
48 // string includes the HTML and the javascript code necessary to generate the 28 // string includes the HTML and the javascript code necessary to generate the
49 // full page with support for i18n Templates. 29 // full page with support for i18n Templates.
50 UI_BASE_EXPORT std::string GetI18nTemplateHtml( 30 UI_BASE_EXPORT std::string GetI18nTemplateHtml(
51 const base::StringPiece& html_template, 31 const base::StringPiece& html_template,
52 const base::DictionaryValue* json); 32 const base::DictionaryValue* json);
53 33
54 // A helper function that generates a string of HTML to be loaded. The 34 // A helper function that generates a string of HTML to be loaded. The
55 // string includes the HTML and the javascript code necessary to generate the 35 // string includes the HTML and the javascript code necessary to generate the
56 // full page with support for both i18n Templates and JsTemplates. 36 // full page with support for both i18n Templates and JsTemplates.
57 UI_BASE_EXPORT std::string GetTemplatesHtml( 37 UI_BASE_EXPORT std::string GetTemplatesHtml(
58 const base::StringPiece& html_template, 38 const base::StringPiece& html_template,
59 const base::DictionaryValue* json, 39 const base::DictionaryValue* json,
60 const base::StringPiece& template_id); 40 const base::StringPiece& template_id);
61 41
62 // The following functions build up the different parts that the above 42 // Assigns the given json data into |loadTimeData|, without a <script> tag.
63 // templates use.
64
65 // Appends a script tag with a variable name |templateData| that has the JSON
66 // assigned to it.
67 UI_BASE_EXPORT void AppendJsonHtml(const base::DictionaryValue* json,
68 std::string* output);
69
70 // Same as AppendJsonHtml(), except does not include the <script></script>
71 // tag wrappers.
72 UI_BASE_EXPORT void AppendJsonJS(const base::DictionaryValue* json, 43 UI_BASE_EXPORT void AppendJsonJS(const base::DictionaryValue* json,
73 std::string* output); 44 std::string* output);
74 45
75 // Appends the source for JsTemplates in a script tag.
76 UI_BASE_EXPORT void AppendJsTemplateSourceHtml(std::string* output);
77
78 // Appends the code that processes the JsTemplate with the JSON. You should
79 // call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this.
80 UI_BASE_EXPORT void AppendJsTemplateProcessHtml(
81 const base::StringPiece& template_id,
82 std::string* output);
83
84 // Appends the source for i18n Templates in a script tag.
85 UI_BASE_EXPORT void AppendI18nTemplateSourceHtml(std::string* output);
86
87 // Appends the code that processes the i18n Template with the JSON. You
88 // should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling
89 // this.
90 UI_BASE_EXPORT void AppendI18nTemplateProcessHtml(std::string* output);
91
92 } // namespace webui 46 } // namespace webui
93 47
94 #endif // UI_BASE_WEBUI_JSTEMPLATE_BUILDER_H_ 48 #endif // UI_BASE_WEBUI_JSTEMPLATE_BUILDER_H_
OLDNEW
« no previous file with comments | « content/public/browser/web_ui_data_source.h ('k') | ui/base/webui/jstemplate_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698