A method and device for generating code for describing a page
Define the text of page components and build component trees through JSON format, and generate component code using stack data structures, solving the problem of insufficient flexibility and scalability of existing tools when dealing with highly coupled components, and achieving more efficient page code generation.
Patent Information
- Application Number
- CN202010827850.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-17
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2040-08-17
AI Technical Summary
When existing tools generate HTML5-based pages, they have low personalization, poor flexibility and scalability when processing components with high coupling, and they cannot implement component nesting, resulting in increased code complexity and workload of development pages.
Define component nodes by defining text describing page components using JSON format, and build a component tree of the page, storing each node using the stack data structure, and generating corresponding component codes by obtaining node operations stored in the stack data structure.
The flexibility and scalability of generating page components is improved. Through the loop operation of nodes in the stack data structure, component codes corresponding to the node hierarchy structure are spliced to form, which improves the efficiency of generating page codes.
Smart Images

Figure CN113760271B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for generating codes for describing pages. Background Art
[0002] At present, HTML5-based applications are widely used. When generating HTML5-based pages, some tools can be used to complete the task. Existing tools usually generate tool libraries for HTML5 pages by dragging and dropping. The implementation principle of such tools usually defines different JSON-based structures for user interface components and business components, and then generates a structure set by dragging or clicking, and generates the corresponding component code or page file by traversing the structure set.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Existing tools generally deal with components with a high degree of coupling, such as carousels, banners, product pools, etc. These general components are generated according to a fixed hierarchy, so they have a low degree of personalization, poor flexibility and scalability, and cannot realize the function of nested component construction; thereby increasing the complexity and workload of page development code. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and device for generating code for describing a page, which can use JSON format to define text definition component nodes that describe page components and build a component tree of the page; use a stack data structure to store each node, and generate corresponding component code by obtaining node operations stored in the stack data structure. By using JSON format to define text definition component nodes that describe page components, the flexibility and extensibility of generating page components are improved; by looping operations on nodes in the stack data structure, component codes corresponding to the node hierarchy structure are spliced to improve the efficiency of generating page code.
[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for generating code for describing a page is provided, characterized in that it includes: obtaining text that describes a page component using a first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent the component; the node has node information; storing a root node among the one or more nodes in a blank stack to form a node stack; when the number of nodes contained in the node stack is not less than 1, taking the first node at the top of the node stack as the current node; generating a component code according to the node information of the current node, and adding the component code to the end of the target code; when the number of child nodes of the current node is not less than 1, deleting the current node from the node stack and storing the child nodes in the node stack; when the number of child nodes of the current node is less than 1, deleting the current node from the node stack; when the number of nodes contained in the node stack is less than 1, completing the generation of the target code for describing the page.
[0007] Optionally, the method for generating a code for describing a page is characterized in that:
[0008] The first format is a JSON structure.
[0009] Optionally, the method for generating a code for describing a page is characterized in that:
[0010] A component tree is constructed according to the text, wherein the nodes of the component tree correspond one-to-one to the nodes in the text.
[0011] Optionally, the method for generating a code for describing a page is characterized in that:
[0012] The node information also includes component attribute information and component type. The component code is generated according to the attribute information and the component type.
[0013] Optionally, the method for generating a code for describing a page is characterized in that:
[0014] Storing the child nodes in the node stack includes: storing the child nodes in the node stack in reverse order according to the acquired order of the child nodes.
[0015] Optionally, the method for generating a code for describing a page is characterized in that:
[0016] According to the hierarchical relationship of the current node in the component tree, a paragraph structure of the component code corresponding to the current node in the target code is determined, wherein the paragraph structure has a first tag and a last tag.
[0017] Optionally, the method for generating a code for describing a page is characterized in that:
[0018] When the number of child nodes included in the current node is greater than 1, the end tag of the paragraph structure corresponding to the current node is determined according to the last child node obtained.
[0019] Optionally, the method for generating a code for describing a page is characterized in that:
[0020] When a page contains multiple component trees, the target component code is generated based on each component tree respectively; and a user page is generated according to the multiple target component codes.
[0021] To achieve the above object, according to a second aspect of an embodiment of the present invention, there is provided a device for generating code for describing a page, characterized in that it comprises: a node generation module, a code generation module and a page generation module, wherein:
[0022] The node generation module is used to obtain text describing a page component in a first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent the component; the node has node information; and a root node of the one or more nodes is stored in a blank stack to form a node stack;
[0023] The code generation module is used to, when the number of nodes contained in the node stack is not less than 1, use the first node at the top of the node stack as the current node; generate component code according to the node information of the current node, and add the component code to the end of the target code; when the number of child nodes of the current node is not less than 1, delete the current node from the node stack and store the child nodes in the node stack; when the number of child nodes of the current node is less than 1, delete the current node from the node stack;
[0024] The page generation module is used to complete the generation of the target code for describing the page when the number of nodes included in the node stack is less than 1.
[0025] Optionally, the device for generating a code for describing a page is characterized in that.
[0026] The first format is a JSON structure.
[0027] Optionally, the device for generating a code for describing a page is characterized in that:
[0028] A component tree is constructed according to the text, wherein the nodes of the component tree correspond one-to-one to the nodes in the text.
[0029] Optionally, the device for generating a code for describing a page is characterized in that:
[0030] The node information also includes component attribute information and component type. The component code is generated according to the attribute information and the component type.
[0031] Optionally, the device for generating a code for describing a page is characterized in that:
[0032] Storing the child nodes in the node stack includes: storing the child nodes in the node stack in reverse order according to the acquired order of the child nodes.
[0033] Optionally, the device for generating a code for describing a page is characterized in that:
[0034] According to the hierarchical relationship of the current node in the component tree, a paragraph structure of the component code corresponding to the current node in the target code is determined, wherein the paragraph structure has a first tag and a last tag.
[0035] Optionally, the device for generating a code for describing a page is characterized in that:
[0036] When the number of child nodes included in the current node is greater than 1, the end tag of the paragraph structure corresponding to the current node is determined according to the last child node obtained.
[0037] Optionally, the device for generating a code for describing a page is characterized in that:
[0038] When a page contains multiple component trees, the target component code is generated based on each component tree respectively; and a user page is generated according to the multiple target component codes.
[0039] To achieve the above-mentioned purpose, according to the third aspect of an embodiment of the present invention, there is provided an electronic device for generating a code for describing a page, characterized in that it comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in the above-mentioned method for generating a code for describing a page.
[0040] To achieve the above-mentioned purpose, according to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, characterized in that when the program is executed by a processor, any method described in the above-mentioned method of generating a code for describing a page is implemented.
[0041] One embodiment of the above invention has the following advantages or beneficial effects: it is possible to define component nodes using texts that describe page components in JSON format and construct a component tree for the page; it uses a stack data structure to store each node, and generates corresponding component code by obtaining node operations stored in the stack data structure. By using JSON format to define component nodes that describe page components, the flexibility and scalability of generating page components are improved; by looping the nodes in the stack data structure, component codes corresponding to the node hierarchy structure are spliced together, and the efficiency of generating page code is improved.
[0042] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0044] Figure 1 It is a flowchart of a method for generating a user page provided by an embodiment of the present invention;
[0045] Figure 2 It is a schematic diagram of a flow chart of generating a code for describing a page provided by an embodiment of the present invention;
[0046] Figure 3 is a schematic diagram of a component tree node provided by an embodiment of the present invention;
[0047] Figure 4 It is a schematic diagram of a process of generating target component code based on a node stack provided by an embodiment of the present invention;
[0048] Figure 5 It is a schematic diagram of the structure of a device for generating a code for describing a page provided by an embodiment of the present invention;
[0049] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0050] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0051] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0052] like Figure 1 As shown, an embodiment of the present invention provides a method for generating a code for describing a page, and the method may include the following steps:
[0053] Step S101: Obtain text that describes page components using a first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent components; the nodes have node information; and a root node among the one or more nodes is stored in a blank stack to form a node stack.
[0054] Specifically, according to the components included in the designed user page, a text describing each component is obtained, and the format of the text is based on the JSON structure; wherein JSON (JavaScript Object Notation) is a lightweight data exchange format, which uses a text format that is completely independent of the programming language to store and represent data, and its concise and clear hierarchical structure makes JSON an ideal data exchange language. Further, the text based on the JSON structure defines multiple nodes with a hierarchical structure, each node corresponds to a component, and each component forms a component tree, that is, according to the text, a component tree is constructed, and the nodes of the component tree correspond one-to-one to the nodes in the text.
[0055] It is understandable that a user page may contain one component tree or multiple component trees; wherein the nodes contained in the component tree contain at least node information, and the node information may include node identification; the node information also includes component attribute information and component type. A component code indicating the function of the component is generated based on the attribute information and the component type. For example: the following shows an example of a node and the node information contained therein, wherein uuid is the node identification, which is used to indicate the uniqueness of the node in the component tree; type is the component type, which is the type of each component used to compose the user page, such as: button, text, view, image, root, etc.; props is the attribute information of the component, and the attribute information is used to describe the characteristics of the component, such as: the display position of the component in the page, the behavior information of the component, the appearance information of the component, etc.; children is the child node information of the node. The number of child nodes can be one or more; it is understandable that a component tree contains a root node and one or more child nodes; preferably, the structure of the node information of each node can be the same, for example, as shown in the example below, the root node and the child node both contain the node identifier, component type, component attributes, and child node information; the text format describing the node and the node information is a JSON structure.
[0056]
[0057] Further, the root node of the one or more nodes is stored in a blank stack to form a node stack; specifically, a stack is a data structure that stores data according to the last-in-first-out principle, the first data entered is pushed to the bottom of the stack, and the last data is at the top of the stack (i.e., the top of the stack), and when data needs to be read, data is obtained from the top of the stack; first, the root node of the component tree is stored in a blank stack, wherein the blank stack indicates a stack that does not contain data, that is, the root node of the component tree is the first data stored in the blank stack, and further, a node stack is formed. It can be understood that the root node is first stored in the blank stack as the starting point for storing and processing each node contained in the component tree.
[0058] Step S102: When the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node; a component code is generated according to the node information of the current node, and the component code is added to the end of the target code; when the number of child nodes of the current node is not less than 1, the current node is deleted from the node stack, and the child nodes are stored in the node stack; when the number of child nodes of the current node is less than 1, the current node is deleted from the node stack.
[0059] Specifically, the number of nodes contained in the node stack is obtained. According to the description of step S101, the number of nodes contained in the node stack is 1 (including the root node), that is, the number of nodes is not less than 1, then the first node at the top of the node stack is obtained as the current node. The operation of obtaining the current node is the operation behavior on the stack data structure, that is, when data needs to be read, data is obtained from the top of the stack, for example, the stack.pop() method can be used.
[0060] After obtaining the current node, obtain the information of the current node. The description of the node information is consistent with step S101 and will not be repeated here. Further, generate component code according to the node information of the current node. The language used by the component code is a domain-specific language, or Hypertext Markup Language (HTML) or JSX (JavaScript XML), etc. Preferably, JSX is used as the language for generating component code, for example, the component code is generated using the generatorJSX() method. Further, each component code is sequentially spliced to generate a target component code for indicating a component tree, that is, and the component code is added to the end of the target component code. Preferably, one target component code corresponds to one component tree, and when generating the component code of the component tree, the target component code is empty. The format and storage method of the target component code of the present invention are not limited.
[0061] Further, the node information of the current node is obtained, and the number of child nodes in the node information is determined. When the number of child nodes is greater than or equal to 1 (that is, when the number of child nodes contained in the node information of the current node is not less than 1), the current node is deleted from the node stack (that is, the node at the top of the stack is deleted, that is, the stack pop operation); and the child nodes of the current node are stored in the node stack (that is, the stack push operation); it can be understood that according to the first-in-last-out storage characteristic of the stack, when the child nodes are stored in the node stack, the child nodes can be pushed into the node stack. Node sorting, when storing, the child nodes are stored in the node stack in reverse order. For example, node A contains two child nodes B1 (node identifier: uuid: 1) and B2 (node identifier: uuid: 2). As can be seen from the above description, B2 is stored in the node stack first, and then B1. The order of obtaining node information is to obtain B1 first, and then obtain B2. That is, the child nodes are stored in the node stack, including: sorting the node identifiers of the obtained child nodes, and storing the child nodes in the node stack in reverse order. When the number of child nodes contained in the node information of the current node is less than 1, that is, when the current node does not contain child nodes, the current node is deleted from the node stack.
[0062] The description of generating the target component code by using the node stack loop operation is consistent with step S201 to step S209, and will not be repeated here. The example of generating the target component code by using the node stack loop operation is consistent with step S401 to step S405, and will not be repeated here.
[0063] Step S103: When the number of nodes included in the node stack is less than 1, the generation of the target code for describing the page is completed.
[0064] Specifically, according to the description of step S101-step S102, the target component code is generated by using the node stack loop operation. When it is determined that there is no node data in the node stack (that is, when the number of nodes contained in the node stack is less than 1), the loop operation ends, and the generation of the target code for describing the page is completed. Further, the target component code of the page is obtained, and the target component code can be directly merged into the code of the front-end development project for use, or the target component code can be merged into a template to form a file and then put into the project code; the user page and component-related services are generated in combination with the project code.
[0065] Furthermore, a user page may include multiple component trees, and a target component code may be formed based on each component tree to generate the user page, that is, the target component code is generated based on each component tree; and the user page is generated based on the multiple target component codes.
[0066] like Figure 2 As shown, an embodiment of the present invention provides a method for generating a code for describing a page, and the method may include the following steps:
[0067] Step S201: constructing a component tree of a user page. Specifically, the description of obtaining a description component text to construct a component tree is consistent with step S101, and will not be repeated here.
[0068] Step S202: Store the root node of the component tree in the node stack. Specifically, the description of storing in the node stack is consistent with step S101, and will not be repeated here.
[0069] The description of step S201-step S202 is: obtain text that describes the page component using the first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent the component; the node has node information; and the root node of the one or more nodes is stored in a blank stack to form a node stack.
[0070] Step S203: Determine whether the number of nodes included in the node stack is greater than 0 (ie, not less than 1). Specifically, if the number of nodes is greater than 0, execute step S204; otherwise, execute step S209.
[0071] Step S204: Get the first node at the top of the node stack as the current node, and get the node information of the node. Specifically, the description of getting the current node and the node information is the same as step S102, and will not be repeated here.
[0072] Step S205: Generate a component code according to the node information, and add the component code to the end of the target component code. Specifically, the description of obtaining the component code and the target component code is consistent with step S102, and will not be repeated here.
[0073] The description of step S203-step S205 is: when the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node; the component code is generated according to the node information of the current node, and the component code is added to the end of the target code.
[0074] Step S206: Determine whether the number of child nodes of the current node is greater than 0 (ie, not less than 1). Specifically, if the number of child nodes is greater than 0, execute step S207, otherwise execute step S208.
[0075] Step S207: Delete the current node from the node stack, and store the child node in the node stack. Further, continue to execute step S204.
[0076] Step S208: When the number of child nodes of the current node is 0, the current node is deleted from the node stack.
[0077] Specifically, step S203 is continued to be executed, that is, it is determined again whether the number of nodes included in the node stack is greater than 0. When the number of nodes is greater than 0, the node information at the top of the node stack is obtained; thus forming a loop operation.
[0078] The description of step S206-step S208 is: when the number of child nodes of the current node is not less than 1, delete the current node from the node stack and store the child nodes in the node stack; when the number of child nodes of the current node is less than 1, delete the current node from the node stack.
[0079] Step S209: Complete the generation of the target code for describing the page.
[0080] Specifically, the description of obtaining the target component code is consistent with step S103, and is not repeated here. That is, when the number of nodes included in the node stack is less than 1, the generation of the target code for describing the page is completed.
[0081] like Figure 4 As shown, the embodiment of the present invention provides an example of a method for generating a code for describing a page, combined with Figure 3 The example includes the following steps:
[0082] like Figure 3 As shown, it is assumed that a component tree contained in a user page includes a root node A, A includes two child nodes B1 and B2; B1 includes two child nodes C1 and C2; B2 does not include any child nodes.
[0083] Step S401: Store the component tree root node A in a blank stack to form a node stack. When the number of nodes contained in the node stack is not less than 1, use the first node at the top of the node stack as the current node (i.e., node A); generate a component code (i.e., target component code A) based on the node information of the current node (A), and add the component code to the end of the target component code.
[0084] Further, according to the hierarchical relationship of the current node in the component tree, the paragraph structure of the component code corresponding to the current node in the target code is determined, and the paragraph structure has a first tag and a last tag. Specifically, taking the format of the target component code as JSX as an example, for example, based on the JSON structure, the node is described as a paragraph structure, then when generating the target component code, the first tag and the last tag of the paragraph structure are obtained, for example, the node information is defined in the JSON format, the first tag and the last tag can be marked with the symbol "{}", and when the target component code is generated, the corresponding first tag is generated (for example: indicating ); end tag (for example: indicating ), that is, according to the hierarchical relationship of the current node in the component tree, determine the paragraph structure of the component code corresponding to the current node in the target code, and the paragraph structure has a first tag and a last tag. It can be understood that when the current node contains child nodes, the last tag of the current node needs to be determined after the last tag of the contained child nodes is generated, that is, when the number of child nodes contained in the current node is greater than 1, the last tag of the current node is determined according to the last child node obtained.
[0085] Step S402: Obtain the number of child nodes contained in the node information of the first node A at the top of the node stack (the number of child nodes is 2, and the child nodes are B1 and B2 respectively), then delete A from the node stack, and store the child nodes B1 and B2 in the node stack in reverse order; that is, when the number of child nodes contained in the node information of the current node is not less than 1, delete the current node from the node stack, and store the child nodes in the node stack, first storing B2 and then storing B1, such as Figure 4As shown; sort the nodes of the acquired child nodes (assuming the sorting is B1, B2), and store the child nodes in the node stack in reverse order. That is, storing the child nodes in the node stack includes: according to the order of the acquired child nodes, storing the child nodes in the node stack in reverse order.
[0086] Furthermore, when it is determined that the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node (i.e., B1); based on the node information of the current node (B1), a component code (i.e., target component code B1) is generated, and the component code is added to the end of the target component code, that is, the target component code B1 is spliced (added) to the end of the target component code A.
[0087] Step S403: Obtain the number of child nodes contained in the node information of the first node B1 at the top of the node stack (the number of child nodes is 2, and the child nodes are C1 and C2 respectively), then delete B1 from the node stack, and store the child nodes C1 and C2 in the node stack in reverse order; that is, when the number of child nodes contained in the node information of the current node is not less than 1, delete the current node from the node stack, and store the child nodes in the node stack, first storing C2 and then storing C1, such as Figure 4 As shown; that is, storing the child nodes in the node stack includes: storing the child nodes in the node stack in reverse order according to the order of the child nodes obtained.
[0088] Furthermore, when it is determined that the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node (i.e., C1); based on the node information of the current node (C1), a component code (i.e., target component code C1) is generated, and the component code is added to the end of the target component code, that is, the target component code C1 is spliced (added) to the end of the target component code B1.
[0089] Step S404: Obtain the number of child nodes of the first node C1 at the top of the node stack (the number of child nodes is 0), and then delete C1 from the node stack. That is, when the number of child nodes included in the node information of the current node is less than 1, delete the current node from the node stack.
[0090] Furthermore, when it is determined that the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node (i.e., C2); a component code (i.e., target component code C2) is generated according to the node information of the current node (C2), and the component code is added to the end of the target component code, that is, the target component code C2 is spliced (added) to the end of the target component code C1.
[0091] Step S405: Obtain the number of child nodes contained in the node information of the first node C2 at the top of the node stack (the number of child nodes is 0), and then delete C2 from the node stack. That is, when the number of child nodes contained in the node information of the current node is less than 1, delete the current node from the node stack.
[0092] Further, when it is determined that the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node (i.e., B2); a component code (i.e., target component code B2) is generated according to the node information of the current node (i.e., B2), and the component code is added to the end of the target component code, that is, the target component code B2 is spliced (added) to the end of the target component code C1. It can be understood that if the child node B2 contains child nodes, the child nodes are continuously obtained and stored in the node stack in this step, and a loop operation is performed.
[0093] Furthermore, after determining that B2 does not contain the number of child nodes and deleting B2 from the node stack, the traversal loop operation of each node of the component tree has been completed, and the target component code is composed of target component code A, target component code B1, target component code C1, target component code C2, and target component code B2, that is, when the number of nodes contained in the node stack is less than 1, the generation of the target code used to describe the page is completed.
[0094] like Figure 5 As shown, an embodiment of the present invention provides a device 500 for generating a code for describing a page, comprising: a node generation module 501, a code generation module 502 and a page generation module 503; wherein,
[0095] The node generation module 501 is used to obtain text describing a page component in a first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent the component; the node has node information; and a root node of the one or more nodes is stored in a blank stack to form a node stack;
[0096] The code generation module 502 is used to, when the number of nodes contained in the node stack is not less than 1, use the first node at the top of the node stack as the current node; generate component code according to the node information of the current node, and add the component code to the end of the target code; when the number of child nodes of the current node is not less than 1, delete the current node from the node stack and store the child nodes in the node stack; when the number of child nodes of the current node is less than 1, delete the current node from the node stack;
[0097] The page generation module 503 is used to complete the generation of the target code for describing the page when the number of nodes included in the node stack is less than 1.
[0098] Optionally, the generating node module 501 includes the first format being a JSON structure.
[0099] Optionally, the node generation module 501 is further used to construct a component tree according to the text, and the nodes of the component tree correspond one-to-one to the nodes in the text.
[0100] Optionally, the code generation module 502 includes the node information and the component attribute information and component type, and generates the component code according to the attribute information and the component type.
[0101] Optionally, the code generation module 502 is further configured to store the child nodes in the node stack in reverse order according to the acquired order of the child nodes.
[0102] Optionally, the code generation module 502 is further used to determine a paragraph structure of the component code corresponding to the current node in the target code according to the hierarchical relationship of the current node in the component tree, wherein the paragraph structure has a first tag and a last tag.
[0103] Optionally, the code generation module 502 is further configured to determine the end tag of the paragraph structure corresponding to the current node according to the last acquired child node when the number of child nodes contained in the current node is greater than 1.
[0104] Optionally, the page generation module 503 is further used to generate the target component code based on each component tree respectively when the page contains multiple component trees; and generate a user page according to the multiple target component codes.
[0105] An embodiment of the present invention also provides an electronic device for generating code for describing a page, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in any of the above embodiments.
[0106] An embodiment of the present invention further provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the method provided in any of the above embodiments is implemented.
[0107] Figure 6 An exemplary system architecture 600 is shown to which the method for generating a code for describing a page or the apparatus for generating a code for describing a page according to an embodiment of the present invention can be applied.
[0108] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0109] Users can use terminal devices 601, 602, 603 to interact with server 605 through network 604 to receive or send messages, etc. Various client applications can be installed on terminal devices 601, 602, 603, such as web browser applications, search applications, instant messaging tools, and email clients.
[0110] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0111] The server 605 may be a server that provides various services, such as a background management server that provides support for generating component codes for the component tree constructed by the user using the terminal devices 601, 602, and 603. The background management server may analyze and process the node information of the received component tree, and feed back the corresponding information of the target component code to the terminal device.
[0112] It should be noted that the method for generating a code for describing a page provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the device for generating a code for describing a page is generally disposed in the server 605 .
[0113] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0114] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0115] like Figure 7As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0116] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0117] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0118] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0119] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0120] The modules and / or units involved in the embodiments of the present invention may be implemented in software or hardware. The modules and / or units described may also be arranged in a processor, for example, they may be described as: a processor includes a node generation module, a code generation module, and a page generation module. The names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the page generation module may also be described as "a module that completes the generation of the target code for describing the page according to the component node information".
[0121] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently and not assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: obtaining text describing a page component using a first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent the component; the node has node information; storing the root node of the one or more nodes in a blank stack to form a node stack; when the number of nodes contained in the node stack is not less than 1, taking the first node at the top of the node stack as the current node; generating a component code according to the node information of the current node, and adding the component code to the end of the target code; when the number of child nodes of the current node is not less than 1, deleting the current node from the node stack and storing the child node in the node stack; when the number of child nodes of the current node is less than 1, deleting the current node from the node stack; when the number of nodes contained in the node stack is less than 1, completing the generation of the target code for describing the page.
[0122] According to the technical solution of the embodiment of the present invention, it is possible to define component nodes using texts that describe page components in JSON format and construct a component tree for the page; use a stack data structure to store each node, and generate corresponding component code by obtaining node operations stored in the stack data structure. By using JSON format to define component nodes that describe page components, the flexibility and extensibility of generating page components are improved; by looping the nodes in the stack data structure, component codes corresponding to the node hierarchy structure are spliced to improve the efficiency of generating page code.
[0123] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for generating a code for describing a page, characterized in that: include: Obtaining text that describes a page component in a first format, wherein the text defines one or more nodes for representing components in a hierarchical structure; The node has node information; a root node among the one or more nodes is stored in a blank stack to form a node stack; When the number of nodes contained in the node stack is not less than 1, the first node at the top of the node stack is used as the current node; a component code is generated according to the node information of the current node, and the component code is added to the end of the target code; When the number of child nodes of the current node is not less than 1, deleting the current node from the node stack, and storing the child nodes of the current node in the node stack; When the number of child nodes of the current node is less than 1, the current node is deleted from the node stack; wherein the storing the child nodes of the current node in the node stack comprises: storing the child nodes in the node stack in reverse order according to the order of the child nodes obtained; When the number of nodes included in the node stack is less than 1, the generation of the target code for describing the page is completed.
2. The method according to claim 1, characterized in that The first format is a JSON structure.
3. The method according to claim 1, characterized in that A component tree is constructed according to the text, wherein the nodes of the component tree correspond one-to-one to the nodes in the text.
4. The method according to claim 1, characterized in that The node information also includes component attribute information and component type. The component code is generated according to the attribute information and the component type.
5. The method according to claim 2, characterized in that: According to the hierarchical relationship of the current node in the component tree, a paragraph structure of the component code corresponding to the current node in the target code is determined, wherein the paragraph structure has a first tag and a last tag.
6. The method according to claim 5, characterized in that When the number of child nodes included in the current node is greater than 1, the end tag of the paragraph structure corresponding to the current node is determined according to the last child node obtained.
7. The method according to any one of claims 1 to 6, characterized in that: When a page contains multiple component trees, the target component code is generated based on each component tree respectively; and a user page is generated according to the multiple target component codes.
8. A device for generating a code for describing a page, characterized in that: include: Generate node module, generate code module and generate page module; among them, The node generation module is used to obtain text describing a page component in a first format, wherein the text defines one or more nodes having a hierarchical structure and used to represent the component; the node has node information; and a root node of the one or more nodes is stored in a blank stack to form a node stack; The code generation module is used to take the first node at the top of the node stack as the current node when the number of nodes contained in the node stack is not less than 1; generate component code according to the node information of the current node, and add the component code to the end of the target code; when the number of child nodes of the current node is not less than 1, delete the current node from the node stack, and store the child nodes of the current node in the node stack; when the number of child nodes of the current node is less than 1, delete the current node from the node stack; and store the child nodes of the current node in the node stack, including: according to the order of the child nodes obtained, store the child nodes in the node stack in sequence based on reverse order; the page generation module is used to complete the generation of the target code for describing the page when the number of nodes contained in the node stack is less than 1.
9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
XML-based contract template generation method, device, equipment and medium
CN109446499A