This change allows to add internationalized messages into CSS. The new
parameter 'lessMessages' contains the array of message keys that get
set as Less variables.
In Less the variables must enclosed in double quotes (") or single
quotes (') to prevent CSS injection.
Example usage:
Resources:
"class": "ResourceLoaderLessVarFileModule",
"lessMessages": [ "editsection" ],
Message 'editsection':
edit
Less file:
content: '[@{msg-editsection}]';
Generated CSS file:
content: '[edit]';
Also add a type case (object) to ensure that an empty object is
serialized as '{}' and not as '[]'.
Also include Less variables from parent.
Change-Id: I280b52c6745fe8e5755dc5d58c5621a64757d99d
* Subclass with context specific LESS variables
*/
class ResourceLoaderLessVarFileModule extends ResourceLoaderFileModule {
* Subclass with context specific LESS variables
*/
class ResourceLoaderLessVarFileModule extends ResourceLoaderFileModule {
- protected $lessVariables = [
- 'collapsible-collapse',
- 'collapsible-expand',
- ];
+ protected $lessVariables = [];
+
+ /**
+ * @inheritDoc
+ */
+ public function __construct(
+ $options = [],
+ $localBasePath = null,
+ $remoteBasePath = null
+ ) {
+ if ( isset( $options['lessMessages'] ) ) {
+ $this->lessVariables = $options['lessMessages'];
+ }
+ parent::__construct( $options, $localBasePath, $remoteBasePath );
+ }
/**
* Exclude a set of messages from a JSON string representation
/**
* Exclude a set of messages from a JSON string representation
* @param string $blob
* @param array $exclusions
* @return array $blob
* @param string $blob
* @param array $exclusions
* @return array $blob
foreach ( $exclusions as $key ) {
unset( $data[$key] );
}
foreach ( $exclusions as $key ) {
unset( $data[$key] );
}
* (ModifyVars) method so that the variable can be loaded and made available to stylesheets.
* Note this does not take care of CSS escaping. That will be taken care of as part
* of CSS Janus.
* (ModifyVars) method so that the variable can be loaded and made available to stylesheets.
* Note this does not take care of CSS escaping. That will be taken care of as part
* of CSS Janus.
* @param string $msg
* @return string wrapped LESS variable definition
*/
* @param string $msg
* @return string wrapped LESS variable definition
*/
- * @param \ResourceLoaderContext $context
+ * Get language-specific LESS variables for this module.
+ *
+ * @param ResourceLoaderContext $context
* @return array LESS variables
*/
* @return array LESS variables
*/
- protected function getLessVars( \ResourceLoaderContext $context ) {
+ protected function getLessVars( ResourceLoaderContext $context ) {
$blob = parent::getMessageBlob( $context );
$lessMessages = $this->excludeMessagesFromBlob( $blob, $this->messages );
$blob = parent::getMessageBlob( $context );
$lessMessages = $this->excludeMessagesFromBlob( $blob, $this->messages );
+ $vars = parent::getLessVars( $context );
foreach ( $lessMessages as $msgKey => $value ) {
$vars['msg-' . $msgKey] = self::wrapAndEscapeMessage( $value );
}
foreach ( $lessMessages as $msgKey => $value ) {
$vars['msg-' . $msgKey] = self::wrapAndEscapeMessage( $value );
}
'jquery.makeCollapsible.styles' => [
'targets' => [ 'desktop', 'mobile' ],
'class' => ResourceLoaderLessVarFileModule::class,
'jquery.makeCollapsible.styles' => [
'targets' => [ 'desktop', 'mobile' ],
'class' => ResourceLoaderLessVarFileModule::class,
+ 'lessMessages' => [
+ 'collapsible-collapse',
+ 'collapsible-expand',
+ ],
'styles' => [
'resources/src/jquery/jquery.makeCollapsible.styles.less',
],
'styles' => [
'resources/src/jquery/jquery.makeCollapsible.styles.less',
],