Add book catalog example with global/local template system
Features:
- Global template configuration (sqlite_global_templates directive)
- Template path resolution relative to location
- Automatic template loading from directories
- Local templates override global templates
- Content handler installation via directive setter
Book Catalog Example:
- Complete working example with 10 technical books
- SQLite database with setup script
- 4 browseable pages (all, programming, databases, computer-science)
- Shared global templates (header, footer, book_card partial)
- Category-specific local templates with unique theming
- Responsive gradient UI design
- Working navigation and filtering
Configuration:
- sqlite_global_templates: HTTP main-level directive for shared templates
- sqlite_template: Location-level directive (sets content handler)
- Template resolution: {doc_root}{uri}/{template_name}
- All .hbs files in directories auto-loaded as partials
Technical improvements:
- Fixed content handler setup (not phase handler)
- Proper HttpModuleMainConf and HttpModuleLocationConf traits
- Template directory scanning and registration
- Error handling with debug logging
This commit is contained in:
58
conf/book_catalog.conf
Normal file
58
conf/book_catalog.conf
Normal file
@ -0,0 +1,58 @@
|
||||
# Book Catalog Configuration
|
||||
# Demonstrates the nginx-test SQLite module with multiple locations and template inheritance
|
||||
|
||||
load_module target/debug/libnginx_test.dylib;
|
||||
|
||||
worker_processes 1;
|
||||
events {}
|
||||
|
||||
error_log logs/error.log debug;
|
||||
|
||||
http {
|
||||
# Global templates for shared components (header, footer, book_card partial)
|
||||
sqlite_global_templates "server_root/global_templates";
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
root "server_root";
|
||||
|
||||
# Default redirect to all books
|
||||
location = / {
|
||||
return 301 /books/all;
|
||||
}
|
||||
|
||||
# All books
|
||||
location /books/all {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Programming books only
|
||||
location /books/programming {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = 'Programming' ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Database books only
|
||||
location /books/databases {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = 'Databases' ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Computer Science books only
|
||||
location /books/computer-science {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = 'Computer Science' ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,10 +9,14 @@ events {}
|
||||
error_log logs/error.log debug;
|
||||
|
||||
http {
|
||||
# Optional: Global templates directory for shared partials/layouts
|
||||
# sqlite_global_templates "server_root/global_templates";
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
location / {
|
||||
root "server_root";
|
||||
location /people {
|
||||
add_header "Content-Type" "text/html";
|
||||
sqlite_db "db.sqlite3";
|
||||
sqlite_query "SELECT id, name, address FROM person";
|
||||
|
||||
Reference in New Issue
Block a user