Index: trunk/extensions/Spark/Spark.hooks.php |
— | — | @@ -36,6 +36,13 @@ |
37 | 37 | * @param PPFrame $frame |
38 | 38 | */ |
39 | 39 | public static function onSparkRender( $input, array $args, Parser $parser, PPFrame $frame ) { |
| 40 | + static $loadedJs = false; |
| 41 | + |
| 42 | + if ( !$loadedJs ) { |
| 43 | + $parser->getOutput()->addModules( 'ext.spark' ); |
| 44 | + $loadedJs = true; |
| 45 | + } |
| 46 | + |
40 | 47 | $tag = new SparkTag( $args, $input ); |
41 | 48 | return $tag->render(); |
42 | 49 | } |
Index: trunk/extensions/Spark/Spark.class.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Static class for hooks handled by the Spark extension. |
| 5 | + * Class to render spark tags. |
6 | 6 | * |
7 | 7 | * @since 0.1 |
8 | 8 | * |
9 | | - * @file Spark.hooks.php |
| 9 | + * @file Spark.class.php |
10 | 10 | * @ingroup Spark |
11 | 11 | * |
12 | 12 | * @licence GNU GPL v3+ |
— | — | @@ -13,12 +13,63 @@ |
14 | 14 | */ |
15 | 15 | final class SparkTag { |
16 | 16 | |
17 | | - public function __construct( array $args, $input ) { |
18 | | - // TODO |
| 17 | + /** |
| 18 | + * List of spark parameters. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * |
| 22 | + * @var array |
| 23 | + */ |
| 24 | + protected $parameters; |
| 25 | + |
| 26 | + /** |
| 27 | + * Constructor. |
| 28 | + * |
| 29 | + * @since 0.1 |
| 30 | + * |
| 31 | + * @var string or null |
| 32 | + */ |
| 33 | + protected $contents; |
| 34 | + |
| 35 | + public function __construct( array $args, $contents ) { |
| 36 | + $this->parameters = $this->getSparkParameters( $args ); |
| 37 | + $this->contents = $contents; |
19 | 38 | } |
20 | 39 | |
| 40 | + /** |
| 41 | + * Renrder the spark div. |
| 42 | + * |
| 43 | + * @since 0.1 |
| 44 | + * |
| 45 | + * @return string |
| 46 | + */ |
21 | 47 | public function render() { |
22 | | - return ''; // TODO |
| 48 | + return Html::element( |
| 49 | + 'div', |
| 50 | + array_merge( array( 'class' => 'spark' ), $this->parameters ), |
| 51 | + $this->contents |
| 52 | + ); |
23 | 53 | } |
24 | 54 | |
| 55 | + /** |
| 56 | + * Get the spark parameters from a list of key value pairs. |
| 57 | + * |
| 58 | + * @since 0.1 |
| 59 | + * |
| 60 | + * @param array $args |
| 61 | + * |
| 62 | + * @return array |
| 63 | + */ |
| 64 | + protected function getSparkParameters( array $args ) { |
| 65 | + $parameters = array(); |
| 66 | + |
| 67 | + foreach ( $args as $name => $value ) { |
| 68 | + if ( strpos( $name, 'data-spark-' ) === 0 ) { |
| 69 | + $parameters[$name] = $value; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + return $parameters; |
| 74 | + } |
| 75 | + |
25 | 76 | } |
\ No newline at end of file |