Skip to content

Commit a58a56a

Browse files
refactoring
1 parent f3be57c commit a58a56a

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

whyml-converters/whyml_converters/html_converter.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,30 @@ def _generate_internal_styles(self, styles: Dict[str, Any]) -> str:
267267
if isinstance(value, dict):
268268
css_rule = self._generate_css_rule(key, value)
269269
css_parts.append(css_rule)
270-
elif isinstance(value, str) and '{' in value and '}' in value:
271-
# Direct CSS string - substitute variables
272-
css_with_vars = self._substitute_css_variables(value, styles)
273-
css_parts.append(css_with_vars)
270+
elif isinstance(value, str):
271+
css_text = value.strip()
272+
if '{' in css_text and '}' in css_text:
273+
# Full CSS block - substitute variables
274+
css_with_vars = self._substitute_css_variables(css_text, styles)
275+
css_parts.append(css_with_vars)
276+
elif ':' in css_text:
277+
# Treat as declaration list; build rule for selector
278+
# Prefix '.' for bare class-like selectors
279+
selector = key
280+
if not selector.startswith(('.', '#')):
281+
selector = f'.{selector}'
282+
# Parse declarations into dict
283+
properties = {}
284+
for decl in css_text.split(';'):
285+
decl = decl.strip()
286+
if not decl:
287+
continue
288+
if ':' in decl:
289+
prop, val = decl.split(':', 1)
290+
properties[prop.strip()] = val.strip()
291+
if properties:
292+
css_rule = self._generate_css_rule(selector, properties)
293+
css_parts.append(css_rule)
274294

275295
if css_parts:
276296
css_content = '\n'.join(css_parts)

whyml-converters/whyml_converters/php_converter.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@ def convert(self, manifest: Dict[str, Any], **kwargs):
4747
from .conversion_result import ConversionResult
4848
import asyncio
4949

50-
# Run async conversion
50+
# Determine default class name from metadata title
51+
metadata = manifest.get('metadata', {})
52+
title = metadata.get('title', 'Component')
53+
class_name_base = ''.join(ch for ch in title.title() if ch.isalnum()) or 'Component'
54+
# Ensure suffix 'Component'
55+
class_name = class_name_base if class_name_base.endswith('Component') else f"{class_name_base}Component"
56+
57+
# Run async conversion with class_name passed through
5158
try:
5259
loop = asyncio.get_event_loop()
5360
except RuntimeError:
5461
loop = asyncio.new_event_loop()
5562
asyncio.set_event_loop(loop)
5663

57-
php_content = loop.run_until_complete(self.convert_manifest(manifest, **kwargs))
58-
return ConversionResult(content=php_content, format="php")
64+
php_content = loop.run_until_complete(self.convert_manifest(manifest, class_name=class_name, **kwargs))
65+
filename = f"{class_name}.php"
66+
return ConversionResult(content=php_content, format="php", filename=filename)
5967

6068
async def convert_manifest(self,
6169
manifest: Dict[str, Any],
@@ -574,6 +582,21 @@ def _generate_php_utility_methods(self, **options) -> str:
574582
self._decrease_indent()
575583
utility_methods.append(f'{self._indent()}}}')
576584

585+
utility_methods.append("")
586+
587+
# Data setter to demonstrate typed array parameter
588+
utility_methods.append(f'{self._indent()}/**')
589+
utility_methods.append(f'{self._indent()} * Set component data')
590+
utility_methods.append(f'{self._indent()} * @param array $data Data array')
591+
utility_methods.append(f'{self._indent()} * @return void')
592+
utility_methods.append(f'{self._indent()} */')
593+
utility_methods.append(f'{self._indent()}protected function setData(array $data): void')
594+
utility_methods.append(f'{self._indent()}{{')
595+
self._increase_indent()
596+
utility_methods.append(f'{self._indent()}// In a full implementation, this would store $data for rendering')
597+
self._decrease_indent()
598+
utility_methods.append(f'{self._indent()}}}')
599+
577600
return '\n'.join(utility_methods)
578601

579602
def _generate_php_helper_functions(self, **options) -> str:

0 commit comments

Comments
 (0)