| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 namespace base { |
| 19 class DictionaryValue; | 20 class DictionaryValue; |
| 20 namespace base { | |
| 21 class StringPiece; | 21 class StringPiece; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace jstemplate_builder { | 24 namespace jstemplate_builder { |
| 25 | 25 |
| 26 // A helper function that generates a string of HTML to be loaded. The | 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 | 27 // string includes the HTML and the javascript code necessary to generate the |
| 28 // full page with support for JsTemplates. | 28 // full page with support for JsTemplates. |
| 29 std::string GetTemplateHtml(const base::StringPiece& html_template, | 29 std::string GetTemplateHtml(const base::StringPiece& html_template, |
| 30 const DictionaryValue* json, | 30 const base::DictionaryValue* json, |
| 31 const base::StringPiece& template_id); | 31 const base::StringPiece& template_id); |
| 32 | 32 |
| 33 // A helper function that generates a string of HTML to be loaded. The | 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 | 34 // string includes the HTML and the javascript code necessary to generate the |
| 35 // full page with support for i18n Templates. | 35 // full page with support for i18n Templates. |
| 36 std::string GetI18nTemplateHtml(const base::StringPiece& html_template, | 36 std::string GetI18nTemplateHtml(const base::StringPiece& html_template, |
| 37 const DictionaryValue* json); | 37 const base::DictionaryValue* json); |
| 38 | 38 |
| 39 // A helper function that generates a string of HTML to be loaded. The | 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 | 40 // string includes the HTML and the javascript code necessary to generate the |
| 41 // full page with support for both i18n Templates and JsTemplates. | 41 // full page with support for both i18n Templates and JsTemplates. |
| 42 std::string GetTemplatesHtml(const base::StringPiece& html_template, | 42 std::string GetTemplatesHtml(const base::StringPiece& html_template, |
| 43 const DictionaryValue* json, | 43 const base::DictionaryValue* json, |
| 44 const base::StringPiece& template_id); | 44 const base::StringPiece& template_id); |
| 45 | 45 |
| 46 // The following functions build up the different parts that the above | 46 // The following functions build up the different parts that the above |
| 47 // templates use. | 47 // templates use. |
| 48 | 48 |
| 49 // Appends a script tag with a variable name |templateData| that has the JSON | 49 // Appends a script tag with a variable name |templateData| that has the JSON |
| 50 // assigned to it. | 50 // assigned to it. |
| 51 void AppendJsonHtml(const DictionaryValue* json, std::string* output); | 51 void AppendJsonHtml(const base::DictionaryValue* json, std::string* output); |
| 52 | 52 |
| 53 // Same as AppendJsonHtml(), execpt does not include the <script></script> | 53 // Same as AppendJsonHtml(), execpt does not include the <script></script> |
| 54 // tag wrappers. | 54 // tag wrappers. |
| 55 void AppendJsonJS(const DictionaryValue* json, std::string* output); | 55 void AppendJsonJS(const base::DictionaryValue* json, std::string* output); |
| 56 | 56 |
| 57 // Appends the source for JsTemplates in a script tag. | 57 // Appends the source for JsTemplates in a script tag. |
| 58 void AppendJsTemplateSourceHtml(std::string* output); | 58 void AppendJsTemplateSourceHtml(std::string* output); |
| 59 | 59 |
| 60 // Appends the code that processes the JsTemplate with the JSON. You should | 60 // Appends the code that processes the JsTemplate with the JSON. You should |
| 61 // call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this. | 61 // call AppendJsTemplateSourceHtml and AppendJsonHtml before calling this. |
| 62 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id, | 62 void AppendJsTemplateProcessHtml(const base::StringPiece& template_id, |
| 63 std::string* output); | 63 std::string* output); |
| 64 | 64 |
| 65 // Appends the source for i18n Templates in a script tag. | 65 // Appends the source for i18n Templates in a script tag. |
| 66 void AppendI18nTemplateSourceHtml(std::string* output); | 66 void AppendI18nTemplateSourceHtml(std::string* output); |
| 67 | 67 |
| 68 // Appends the code that processes the i18n Template with the JSON. You | 68 // Appends the code that processes the i18n Template with the JSON. You |
| 69 // should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling | 69 // should call AppendJsTemplateSourceHtml and AppendJsonHtml before calling |
| 70 // this. | 70 // this. |
| 71 void AppendI18nTemplateProcessHtml(std::string* output); | 71 void AppendI18nTemplateProcessHtml(std::string* output); |
| 72 | 72 |
| 73 } // namespace jstemplate_builder | 73 } // namespace jstemplate_builder |
| 74 #endif // CHROME_COMMON_JSTEMPLATE_BUILDER_H_ | 74 #endif // CHROME_COMMON_JSTEMPLATE_BUILDER_H_ |
| OLD | NEW |