Middleman::Cells

Gem Version

Cells support for Middleman.

Usage

Create cells under source/cells.

source/cells/greet_cell.rb:

class GreetCell < Cell::ViewModel
  property :name

  def show
    render
  end
end

source/cells/greet/show.erb:

<p>Hello, <%= name %>!</p>

Use it in your views.

source/index.html.erb

---
name: Ninome-chan
---

<%= cell(:greet, current_page.data).() %>

Cool. :smirk:

For more details of Cells, see Cells' README.

Installation

Add the following line to your Gemfile.

gem 'middleman-cells'

In addition, you need to install template engine(s) which you want to use in cells. Available engines are listed here.

If you want to use cells-erb, for example, add the following line to Gemfile.

gem 'cells-erb'

Then, run bundle install.

Configuration

require 'cells-erb' # Require template engine(s) you installed.

activate :cells

Or, if you prefer:

activate :cells do
  require 'cells-erb'
end

Configuration Options

cells_dir (default: "cells")

# Change directory where to place cells to `source/view_models`.
activate :cells, cells_dir: 'view_models'

autoload (default: true)

# Disable to autoload cells.
activate :cells, autoload: false

# ...and you need to require your cells manually.
require 'source/cells/foobar_cell'

Contributing

Please report bugs via Issues. Also Pull Requests are welcome. :grinning:

Issue や Pull Request は日本語でもOKです :jp:

License

MIT