Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
FileView Class Reference

#include <FileView.h>

+ Inheritance diagram for FileView:
+ Collaboration diagram for FileView:

Public Member Functions

 FileView (const std::string &path, const std::string &contentType="text/html")
 
std::string render (const std::map< std::string, std::string > &context={}) const override
 Render the view body.
 
std::string getContentType () const override
 Return the MIME content type for this view.
 
- Public Member Functions inherited from FrameworkView
virtual ~FrameworkView ()=default
 
virtual void applyHeaders (HttpResponse &response) const
 Optional hook to set response headers (e.g., Content-Disposition).
 
virtual std::string render (const nlohmann::json &context) const
 Optional JSON context hook (used by JsonView or convenience).
 

Private Attributes

std::string filePath
 
std::string mimeType
 

Detailed Description

Definition at line 12 of file FileView.h.

Constructor & Destructor Documentation

◆ FileView()

FileView::FileView ( const std::string &  path,
const std::string &  contentType = "text/html" 
)
inlineexplicit

Definition at line 14 of file FileView.h.

15 : filePath(path), mimeType(contentType) {}
std::string filePath
Definition FileView.h:33
std::string mimeType
Definition FileView.h:34

Member Function Documentation

◆ getContentType()

std::string FileView::getContentType ( ) const
inlineoverridevirtual

Implements FrameworkView.

Definition at line 28 of file FileView.h.

28 {
29 return mimeType;
30 }

References mimeType.

◆ render()

std::string FileView::render ( const std::map< std::string, std::string > &  context = {}) const
inlineoverridevirtual

Optional context (used by templates).

Implements FrameworkView.

Definition at line 17 of file FileView.h.

17 {}) const override {
19 if (!sm) return "<h1>Storage unavailable</h1>";
20
21 std::string result;
22 if (!sm->readFileString(filePath, 0, UINT32_MAX, result)) {
23 return "<h1>File not found: " + filePath + "</h1>";
24 }
25 return result;
26 }
static constexpr std::uintptr_t getTypeKey()
Definition AppContext.h:91

Member Data Documentation

◆ filePath

std::string FileView::filePath
private

Definition at line 33 of file FileView.h.

◆ mimeType

std::string FileView::mimeType
private

Definition at line 34 of file FileView.h.

Referenced by getContentType().


The documentation for this class was generated from the following file: