Docs.
This commit is contained in:
		
							parent
							
								
									8486c22c32
								
							
						
					
					
						commit
						aecd9f844e
					
				
							
								
								
									
										10
									
								
								src/snek/templates/docs.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/snek/templates/docs.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | |||||||
|  | {% extends "base.html" %} | ||||||
|  | 
 | ||||||
|  | {% block main %} | ||||||
|  | <div class="dialog"> | ||||||
|  | 
 | ||||||
|  |     <fancy-button size="auto"  text="Back" url="/back"></fancy-button> | ||||||
|  | <html-frame url="/docs.md"></html-frame> | ||||||
|  | 
 | ||||||
|  | </div> | ||||||
|  | {% endblock %} | ||||||
							
								
								
									
										53
									
								
								src/snek/templates/docs.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/snek/templates/docs.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | |||||||
|  | # API Documentation | ||||||
|  | 
 | ||||||
|  | Currently only some details about the internal API are available. | ||||||
|  | 
 | ||||||
|  | ## How to create a user | ||||||
|  | ```python | ||||||
|  | # Save user to the table named 'user' | ||||||
|  | # Password gets sha256 encrypted with default a salt string | ||||||
|  | # of the snek.system.security module. | ||||||
|  | 
 | ||||||
|  | new_user_object = await app.service.user.register( | ||||||
|  |     username="retoor",  | ||||||
|  |     password="retoorded" | ||||||
|  | ) | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## Encrypt string | ||||||
|  | ```python | ||||||
|  | from snek.system import security | ||||||
|  | 
 | ||||||
|  | # Support for both utf and bytes. | ||||||
|  | var1 = security.encrypt("data") | ||||||
|  | var2 = security.encrypt(b"data") | ||||||
|  | 
 | ||||||
|  | # Is correct: | ||||||
|  | assert(var1 == var2) | ||||||
|  | ``` | ||||||
|  | 
 | ||||||
|  | ## How to create a basic HTML / Markdown view | ||||||
|  | ```python | ||||||
|  | from snek.system.view import BaseView  | ||||||
|  | 
 | ||||||
|  | class IndexView(BaseView): | ||||||
|  |      | ||||||
|  |     async def get(self): | ||||||
|  |         # The render function supports markdown. | ||||||
|  |         # It will render with syntax highlighting. | ||||||
|  |         # Just use the .md file extension in the file name. | ||||||
|  |         return await self.render("index.html") | ||||||
|  | ``` | ||||||
|  | ## How to create a FormView | ||||||
|  | ```python | ||||||
|  | from snek.system.view import BaseFormView | ||||||
|  | from snek.form.register import RegisterForm | ||||||
|  | 
 | ||||||
|  | class RegisterFormView(BaseFormView): | ||||||
|  |      | ||||||
|  |     form = RegisterForm | ||||||
|  | ``` | ||||||
|  | ## How to register a class view | ||||||
|  | ```python | ||||||
|  | app.routes.add_view("/your-page.html", YourViewClass) | ||||||
|  | ``` | ||||||
							
								
								
									
										15
									
								
								src/snek/view/docs.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/snek/view/docs.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | |||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | from snek.system.view import BaseView | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class DocsHTMLView(BaseView): | ||||||
|  | 
 | ||||||
|  |     async def get(self): | ||||||
|  |         return await self.render_template("docs.html") | ||||||
|  |      | ||||||
|  | class DocsMDView(BaseView): | ||||||
|  | 
 | ||||||
|  |     async def get(self): | ||||||
|  |         return await self.render_template("docs.md") | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user