Python API
Module django_chili.bowl
- class django_chili.bowl.BowlNode(content_node, filename)
This class represents a custom template node for rendering a Bowl.
BowlNode is a subclass of template.Node.
- Attributes:
tag (str): Represents the tag name used in the template for this node.
- Methods:
- __init__(self, content_node: template.Node, filename: str):
Initializes a new BowlNode instance with the given content_node and filename. The content_node represents the content of the node in the template, and the filename
is a string representing the path to the file containing the contents of the bowl.
- render(self, context: template.Context) -> str:
Renders the BowlNode by reading the contents of the file specified by filename and creating a Sauce instance with the contents. The Sauce instance is then added to the
context as a variable named ‘sauce’. The content_node is then rendered in the provided context. Finally, the str representation of the Sauce instance is returned as HTML.
- render(context)
Render Method
This method is used to render the contents of a Sauce instance with the provided context.
- Parameters:
context – The context dictionary containing the values to be rendered.
- Returns:
The rendered HTML as a string.
- django_chili.bowl.bowl_tag(parser, token)
- Parameters:
parser – The Django template parser object.
token – The Django template token object.
- Returns:
A BowlNode object.
This method is a custom template tag for the Django templating engine. It takes two parameters, parser which is the template parser object, and token which is the template token * object. It performs a specific logic to parse the tag name and filename from the token contents, then parses the content nodes using the parser, deletes the first token, and returns * a BowlNode object with the parsed content node and stripped filename.
Module django_chili.chop
- class django_chili.chop.ChopNode(content_node, match, target='tag', attr=None)
Represents a custom template tag node that allows chopping and manipulating HTML tags.
- Args:
content_node (Node): The node containing the content to be rendered. match (str): The CSS selector used to find the tags to be manipulated. target (str, optional): The target of the manipulation. Default is “tag”. attr (str, optional): The attribute name to be modified. Required only if target is “attr”.
- Attributes:
tag (str): The name of the custom template tag.
- Methods:
render(context): Renders the custom template tag node.
- django_chili.chop.chop_tag(parser, token)
- Parameters:
parser – The parser object used for parsing the template.
token – The tag’s token string.
- Returns:
The parsed ChopNode object.
This method takes a parser object and a token string as input parameters and returns a parsed ChopNode object.
The method works by splitting the token string into the tag name and arguments. It then processes the arguments by splitting them further into positional arguments and named arguments *. Positional arguments are added to a list while named arguments are added to a dictionary.
After processing the arguments, the method calls the parser to parse the content node using the ‘endChopNode’ tag as the end point. It then deletes the first token and returns a Chop *Node object created from the parsed content node and the positional and named arguments.
Module django_chili.chunk
Module django_chili.sauce
- class django_chili.sauce.Sauce(html)
This class represents a customized version of the BeautifulSoup class for parsing HTML.
- Class:
Sauce inherits from
BeautifulSoupand adds additional functionalities for parsing HTML.
Usage:
To use this class, simply instantiate it with an HTML string:
sauce = Sauce(“<html><head><title>Example</title></head><body><h1>Hello, world!</h1></body></html>”)
Methods:
Sauceprovides the following methods:__init__(self, html)
Initializes a new instance of the Sauce class.
- Parameters:
html (str): The HTML string to parse.
_markup_is_url(cls, markup)
Checks whether the given markup resembles a URL.
- Parameters:
markup (str): The markup to check.
_markup_resembles_filename(cls, markup)
Checks whether the given markup resembles a filename.
- Parameters:
markup (str): The markup to check.
Note:
This class inherits the methods and attributes from the BeautifulSoup class, which can be found in the official BeautifulSoup documentation.