Sha256: 499be60fe88d7fc2fa40f9a2fdc466f7c4b85f948fe7631416772232c25e9075

Contents?: true

Size: 1.27 KB

Versions: 19

Compression:

Stored size: 1.27 KB

Contents

# Inline Decorators

In most use cases it is recommended to use [View Decorators](view-decorators.html) to render custom data to provide reusable and composable view fragments without polluting component definitions with custom logic.

However, if you need a simple one-off data transformation when using a [Table](../components/tables.html), you can specify a `Proc` within the table `fields` definition by using the secondary form of passing an `Array` of `[Symbol, Hash]` instead of just a `Symbol` for any given field.

The `Proc` will receive the current record (i.e. the object for the current row of a `collection` with a [Collection Table](../components/tables/collection-table.html) or the `item` with an [Item Table](components/tables/item-table.html)).

```rspec:html
collection = [
  User.new(name: 'John Smith', email: 'john@example.com'),
  User.new(name: 'Sally Anderson', email: 'sally@example.org')
]
subject do
  active_element.component.table collection: collection,
                                 fields: [
                                   :email,
                                   [:name, { mapper: ->(record) { record.name.upcase } }]
                                 ]
end

it { is_expected.to include 'JOHN SMITH' }
it { is_expected.to include 'SALLY ANDERSON' }
```

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
active_element-0.0.31 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.30 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.29 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.28 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.27 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.26 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.24 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.23 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.22 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.21 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.19 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.18 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.17 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.16 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.15 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.14 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.13 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.12 rspec-documentation/pages/040-Decorators/Inline Decorators.md
active_element-0.0.11 rspec-documentation/pages/040-Decorators/Inline Decorators.md