implemented step 17 by Gemini
- Rendering CSS assets
This commit is contained in:
@ -14,6 +14,45 @@ class Renderer
|
||||
private string $exportsPath;
|
||||
private string $templatesPath;
|
||||
|
||||
private array $palettes = [
|
||||
'blue-gray' => [
|
||||
'primary' => '#2563eb',
|
||||
'secondary' => '#64748b',
|
||||
'bg' => '#f8fafc',
|
||||
'text' => '#1e293b'
|
||||
],
|
||||
'nature-green' => [
|
||||
'primary' => '#059669',
|
||||
'secondary' => '#fbbf24',
|
||||
'bg' => '#fdfdfd',
|
||||
'text' => '#064e3b'
|
||||
],
|
||||
'elegant-gold' => [
|
||||
'primary' => '#d4af37',
|
||||
'secondary' => '#111827',
|
||||
'bg' => '#ffffff',
|
||||
'text' => '#111827'
|
||||
]
|
||||
];
|
||||
|
||||
private array $styles = [
|
||||
'minimal' => [
|
||||
'radius' => '0px',
|
||||
'shadow' => 'none',
|
||||
'padding' => '4rem 1rem'
|
||||
],
|
||||
'modern' => [
|
||||
'radius' => '0.5rem',
|
||||
'shadow' => '0 4px 6px -1px rgb(0 0 0 / 0.1)',
|
||||
'padding' => '6rem 1.5rem'
|
||||
],
|
||||
'premium' => [
|
||||
'radius' => '1.5rem',
|
||||
'shadow' => '0 10px 15px -3px rgb(0 0 0 / 0.1)',
|
||||
'padding' => '8rem 2rem'
|
||||
]
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->storage = new FileStorage();
|
||||
@ -43,7 +82,17 @@ class Renderer
|
||||
$siteCssSource = $this->templatesPath . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'site.css';
|
||||
copy($siteCssSource, $assetsDir . DIRECTORY_SEPARATOR . 'site.css');
|
||||
|
||||
// 3. Render Content Sections
|
||||
// 3. Prepare relative paths for assets
|
||||
if (!empty($projectData['wizard_data']['assets']['logo'])) {
|
||||
$projectData['wizard_data']['assets']['logo'] = $this->makePathRelative($projectData['wizard_data']['assets']['logo'], $projectId);
|
||||
}
|
||||
if (!empty($projectData['wizard_data']['assets']['gallery'])) {
|
||||
foreach ($projectData['wizard_data']['assets']['gallery'] as $key => $path) {
|
||||
$projectData['wizard_data']['assets']['gallery'][$key] = $this->makePathRelative($path, $projectId);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Render Content Sections
|
||||
$sectionsHtml = '';
|
||||
$selectedSections = $projectData['wizard_data']['modules']['sections'] ?? [];
|
||||
|
||||
@ -57,16 +106,42 @@ class Renderer
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Render HTML base template
|
||||
// 4. Prepare Visual Variables
|
||||
$visuals = $projectData['wizard_data']['visuals'] ?? [];
|
||||
$palette = $this->palettes[$visuals['palette'] ?? 'blue-gray'] ?? $this->palettes['blue-gray'];
|
||||
$style = $this->styles[$visuals['style'] ?? 'modern'] ?? $this->styles['modern'];
|
||||
|
||||
// 5. Render HTML base template
|
||||
$html = $this->renderTemplate('base', [
|
||||
'project' => $projectData,
|
||||
'content' => $sectionsHtml
|
||||
'content' => $sectionsHtml,
|
||||
'css_vars' => [
|
||||
'primary' => $palette['primary'],
|
||||
'secondary' => $palette['secondary'],
|
||||
'bg' => $palette['bg'],
|
||||
'text' => $palette['text'],
|
||||
'radius' => $style['radius'],
|
||||
'shadow' => $style['shadow'],
|
||||
'padding' => $style['padding']
|
||||
]
|
||||
]);
|
||||
|
||||
// 5. Save to exports
|
||||
// 6. Save to exports
|
||||
return file_put_contents($projectExportDir . DIRECTORY_SEPARATOR . 'index.html', $html) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an absolute or project-root relative path relative to the project's export directory.
|
||||
*/
|
||||
private function makePathRelative(string $path, string $projectId): string
|
||||
{
|
||||
$prefix = "exports/{$projectId}/";
|
||||
if (strpos($path, $prefix) === 0) {
|
||||
return substr($path, strlen($prefix));
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal helper to render a PHP template with variables.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user