carbon/eel

Some nice Eel helper for Neos.io

Installs: 12 568

Dependents: 19

Suggesters: 0

Stars: 3

Watchers: 1

Forks: 0

Open Issues: 0

Type:neos-carbon

1.6.1 2019-08-19 15:33 UTC

README

Latest Stable Version Total Downloads License GitHub forks GitHub stars GitHub watchers

Carbon.Eel Package for Neos CMS

Version Flow Neos
0.* 3.* 2.*
> 1 4.* + 5.* 3.* + 4.*

BEM Helper

Generates BEM classes. The modifiers property can be a string (for one modifier), an array (e.g. ['one', 'two']) or an array with keys and values. If you have an array with keys and values (like a Fusion DataStructure) and a value is true the name of the key gets used for the modifier.

  • block (string, required) The name of the block
  • element (string) The name of the element, optional
  • modifiers (string|array) The name of the modifiers, optional

BEM.array(block, element, modifiers)

Shortcut to Carbon.Array.BEM(block, element, modifiers)

BEM.string(block, element, modifiers)

Shortcut to Carbon.String.BEM(block, element, modifiers)

BEM.modifier(class, modifiers)

Generates a string with BEM classes. The modifiers property can be a string (for one modifier), an array (e.g. ['one', 'two']) or an array with keys and values. If you have an array with keys and values (like a Fusion DataStructure) and the value is true the name of the key gets used for the modifier.

  • class (string, required) The name of the class
  • modifiers (string|array) The name of the modifiers, optional

Return The string

Array Helper

Carbon.Array.BEM(block, element, modifiers)

Generates an array with BEM classes. The modifiers property can be a string (for one modifier), an array (e.g. ['one', 'two']) or an array with keys and values. If you have an array with keys and values (like a Fusion DataStructure) and the value is true the name of the key gets used for the modifier.

  • block (string, required) The name of the block
  • element (string) The name of the element, optional
  • modifiers (string|array) The name of the modifiers, optional

Return The array

Carbon.Array.setKeyValue(array, key, value)

Can be used to add a value with a dynamic key

Example:

array = Neos.Fusion:RawArray
array.@process.addKeyValue = ${Carbon.Array.setKeyValue(value, 'key', 'value')}
  • array (array) The array which should be extended
  • key (string) The key for the entry
  • value (mixed) The value

Return The extended array

Carbon.Array.ksort(array)

Sort an array by key

Example:

array.@process.ksort = ${Carbon.Array.ksort(value)}
  • array (array) The array which should be sorted

Return The sorted array

Carbon.Array.filter(array)

Iterates over each value in the array and all entries of the array equal to false will be removed.

Example:

array.@process.filter = ${Carbon.Array.filter(value)}
  • array (array) The array to iterate over

Return The filtered array

Carbon.Array.values(array)

Return all the values of an array

Example:

array.@process.values = ${Carbon.Array.values(value)}
  • array (array) The array to convert

Return An indexed array of values.

Carbon.Array.join(array, separator)

Join the given array recursively using the given separator.

${Carbon.Array.join(array, ',')}
  • array (array) The array who should be processed
  • separator (string, optional) The separator between the values, defaults to ,

Return The converted array as a string

Carbon.Array.extractSubElements(array, preserveKeys)

This method extracts sub elements to the parent level.

An input array of type:

[
 element1 => [
   0 => 'value1'
 ],
 element2 => [
   0 => 'value2'
   1 => 'value3'
 ],

will be converted to:

[
   0 => 'value1'
   1 => 'value2'
   2 => 'value3'
]
  • array (array) The array who should be processed
  • preserveKeys (boolean, optional) Option if the key should be preserved, defaults to false

Return The converted array

Carbon.Array.unique(array, filter)

Removes duplicate values from an array

Example:

array.@process.removeDuplicates = ${Carbon.Array.unique(value)}
  • array (array) The input array
  • filter (boolean, optional) Option if the array should be filtered, defaults to false

Return Returns the filtered array.

FileContent Helper

Carbon.FileContent.path(string)

Returns the file content of a path. Fails silent.

Examples:

Carbon.FileContent.path('resource://Foo.Bar/Private/Assets/Logo.svg')
Carbon.FileContent.path('Foo.Bar/Private/Assets/Logo.svg')
  • string (string) The path to the file

Return The content of the file

Carbon.FileContent.pathHash(string, length)

Returns the hash value from the file content of a path. Fails silent.

Examples:

Carbon.FileContent.pathHash('resource://Foo.Bar/Private/Assets/Logo.svg') == 1d62f5a5
Carbon.FileContent.pathHash('Foo.Bar/Private/Assets/Logo.svg', 20) == 1d62f5a55ad5e304d60d
  • string (string) The path to the file
  • length (integer, optional) The length of the hash value, defaults to 8. The maximal value is 40

Return The hash value from the content of the file

Carbon.FileContent.resource(resource)

Returns the file content of a persisted resource. Fails silent.

Example:

Carbon.FileContent.resource(q(node).property('file'))
  • resource (resource) The persisted resource to read

Return The content of the file

Carbon.FileContent.resourceHash(resource, length)

Returns the hash value from the file content of a persisted resource. Fails silent.

Example:

Carbon.FileContent.resourceHash(q(node).property('file')) == 1d62f5a5
Carbon.FileContent.resourceHash(q(node).property('file'), 20) == 1d62f5a55ad5e304d60d
  • resource (resource) The persisted resource to read
  • length (integer, optional) The length of the hash value, defaults to 8. The maximal value is 40

Return The hash value from the content of the file

String Helper

Carbon.String.BEM(block, element, modifiers)

Generates a string with BEM classes. The modifiers property can be a string (for one modifier), an array (e.g. ['one', 'two']) or an array with keys and values. If you have an array with keys and values (like a Fusion DataStructure) and the value is true the name of the key gets used for the modifier.

  • block (string, required) The name of the block
  • element (string) The name of the element, optional
  • modifiers (string|array) The name of the modifiers, optional

Return The string

Carbon.String.urlize(string)

Generates a slug of the given string

Examples:

Carbon.String.urlize('Hello World') == 'hello-world'
Carbon.String.urlize('Ä_ÖÜ äöü') == 'ae-oeue-aeoeue'
  • string (string) The string to convert

Return The converted string

Carbon.String.toPascalCase(string)

Convert strings to PascalCase

Examples:

Carbon.String.toPascalCase('hello-world') == 'HelloWorld'
Carbon.String.toPascalCase('hello world') == 'HelloWorld'
Carbon.String.toPascalCase('Hello World') == 'HelloWorld'
  • string (string) The string to convert

Return The converted string

Carbon.String.toCamelCase(string)

Convert strings to camelCase

Examples:

Carbon.String.toCamelCase('hello-world') == 'helloWorld'
Carbon.String.toCamelCase('hello world') == 'helloWorld'
Carbon.String.toCamelCase('Hello World') == 'helloWorld'
  • string (string) The string to convert

Return The converted string

Carbon.String.convertCamelCase(string, separator)

Convert CamelCaseStrings to hyphen-case-strings

Examples:

Carbon.String.convertCamelCase('HelloWorld') == 'hello-world'
Carbon.String.convertCamelCase('HelloWorld', '_') == 'hello_world'
Carbon.String.convertCamelCase('HelloWorld', '') == 'helloworld'
  • string (string) The string to convert
  • separator (string, optional) The separator between the words, defaults to -

Return The converted string

Carbon.String.convertToString(input, separator)

Helper to make sure to get a string back

Examples:

Carbon.String.convertToString(' helloworld  ') == 'helloworld'
Carbon.String.convertToString([' hello', ' world']) == 'hello world'
Carbon.String.convertToString(['hello', 'world'], '-') == 'hello-world'
  • input (string, array) A string or an array to convert
  • separator (string, optional) The separator between the words, defaults to whitespace

Return The converted string

Carbon.String.nl2br(string, separator)

Replace all newlines with an <br>

Examples:

Carbon.String.nl2br('hello\nworld') == 'hello<br>world'
Carbon.String.nl2br('hello\nworld', ' | ') == 'hello | world'
  • string (string) A string to convert
  • separator (string, optional) The separator between the words, defaults to <br>

Return The converted string

Carbon.String.removeNbsp(string)

Replace non-breaking spaces and double spaces with a normal space.

Examples:

Carbon.String.removeNbsp(' hello world') == 'hello world'
Carbon.String.removeNbsp('hello   world') == 'hello world'
  • string (string) A string to convert

Return The converted string

Installation

Carbon.Eel is available via packagist. Just run

composer require carbon/eel

To install the package under Neos 2.* / Flow 3.* you have to enter

composer require "carbon/eel:^0.5"