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

Side by Side Diff: chrome/common/jstemplate_builder.h

Issue 10141005: switch ntp to jstemplate v2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rip out broken customlogo code Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 CHROME_COMMON_JSTEMPLATE_BUILDER_H_ 13 #ifndef CHROME_COMMON_JSTEMPLATE_BUILDER_H_
14 #define CHROME_COMMON_JSTEMPLATE_BUILDER_H_ 14 #define CHROME_COMMON_JSTEMPLATE_BUILDER_H_
15 #pragma once 15 #pragma once
16 16
17 #include <string> 17 #include <string>
18 18
19 #include "base/string_piece.h" 19 #include "base/string_piece.h"
20 20
21 namespace base { 21 namespace base {
22 class DictionaryValue; 22 class DictionaryValue;
23 } 23 }
24 24
25 namespace jstemplate_builder { 25 namespace jstemplate_builder {
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 UseVersion2 {
31 public:
32 UseVersion2();
33 ~UseVersion2();
34
35 private:
36 bool previous_value_;
37
38 DISALLOW_COPY_AND_ASSIGN(UseVersion2);
39 };
40
27 // A helper function that generates a string of HTML to be loaded. The 41 // A helper function that generates a string of HTML to be loaded. The
28 // string includes the HTML and the javascript code necessary to generate the 42 // string includes the HTML and the javascript code necessary to generate the
29 // full page with support for JsTemplates. 43 // full page with support for JsTemplates.
30 std::string GetTemplateHtml(const base::StringPiece& html_template, 44 std::string GetTemplateHtml(const base::StringPiece& html_template,
31 const base::DictionaryValue* json, 45 const base::DictionaryValue* json,
32 const base::StringPiece& template_id); 46 const base::StringPiece& template_id);
33 47
34 // A helper function that generates a string of HTML to be loaded. The 48 // A helper function that generates a string of HTML to be loaded. The
35 // string includes the HTML and the javascript code necessary to generate the 49 // string includes the HTML and the javascript code necessary to generate the
36 // full page with support for i18n Templates. 50 // full page with support for i18n Templates.
(...skipping 10 matching lines...) Expand all
47 // The following functions build up the different parts that the above 61 // The following functions build up the different parts that the above
48 // templates use. 62 // templates use.
49 63
50 // Appends a script tag with a variable name |templateData| that has the JSON 64 // Appends a script tag with a variable name |templateData| that has the JSON
51 // assigned to it. 65 // assigned to it.
52 void AppendJsonHtml(const base::DictionaryValue* json, std::string* output); 66 void AppendJsonHtml(const base::DictionaryValue* json, std::string* output);
53 67
54 // Same as AppendJsonHtml(), except does not include the <script></script> 68 // Same as AppendJsonHtml(), except does not include the <script></script>
55 // tag wrappers. 69 // tag wrappers.
56 void AppendJsonJS(const base::DictionaryValue* json, std::string* output); 70 void AppendJsonJS(const base::DictionaryValue* json, std::string* output);
57 // Same as above, but uses a slightly different format which should some day
58 // become the default.
59 void AppendJsonJS2(const base::DictionaryValue* json, std::string* output);
60 71
61 // Appends the source for JsTemplates in a script tag. 72 // Appends the source for JsTemplates in a script tag.
62 void AppendJsTemplateSourceHtml(std::string* output); 73 void AppendJsTemplateSourceHtml(std::string* output);
63 74
64 // Appends the code that processes the JsTemplate with the JSON. You should 75 // Appends the code that processes the JsTemplate with the JSON. You should
65 // call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this. 76 // call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this.
66 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id, 77 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id,
67 std::string* output); 78 std::string* output);
68 79
69 // Appends the source for i18n Templates in a script tag. 80 // Appends the source for i18n Templates in a script tag.
70 void AppendI18nTemplateSourceHtml(std::string* output); 81 void AppendI18nTemplateSourceHtml(std::string* output);
71 82
72 // Appends the code that processes the i18n Template with the JSON. You 83 // Appends the code that processes the i18n Template with the JSON. You
73 // should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling 84 // should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling
74 // this. 85 // this.
75 void AppendI18nTemplateProcessHtml(std::string* output); 86 void AppendI18nTemplateProcessHtml(std::string* output);
76 87
77 } // namespace jstemplate_builder 88 } // namespace jstemplate_builder
78 #endif // CHROME_COMMON_JSTEMPLATE_BUILDER_H_ 89 #endif // CHROME_COMMON_JSTEMPLATE_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698