mix cinder.gen.filter (Cinder v0.5.0)

View Source

Generate and configure a custom Cinder filter based on built-in filters.

This task creates a new custom filter module that delegates to a built-in filter as a starting point, allowing you to customize specific behaviors while keeping the rest of the implementation. It automatically registers the filter in your application configuration.

Example

mix cinder.gen.filter MyApp.Filters.CustomText custom_text --template=text

Arguments

  • module - The module name for the filter (e.g., MyApp.Filters.CustomText)
  • type - The filter type identifier (e.g., custom_text)

Options

  • --template or -t - Base filter to copy from: text, select, multi_select, boolean, date_range, number_range
  • --no-tests - Skip generating test file
  • --no-config - Skip automatic configuration registration
  • --no-setup - Skip ensuring Cinder.setup() is called in application

Available Templates

  • text - Based on Cinder.Filters.Text (text input with operators)
  • select - Based on Cinder.Filters.Select (dropdown selection)
  • multi_select - Based on Cinder.Filters.MultiSelect (multiple selection)
  • boolean - Based on Cinder.Filters.Boolean (true/false/any selection)
  • date_range - Based on Cinder.Filters.DateRange (from/to date picker)
  • number_range - Based on Cinder.Filters.NumberRange (from/to number input)

What it does

  1. Creates a custom filter module that delegates to the chosen built-in filter
  2. Automatically updates the filter type to your custom type
  3. Generates comprehensive test file (unless --no-tests)
  4. Automatically adds the filter to your :cinder configuration
  5. Provides clear examples of how to customize the behavior

Customization

The generated filter starts by delegating all behavior to the base filter but with your custom type. You can then override any callback function to customize:

  • render/4 - Customize the HTML rendering
  • process/2 - Customize input processing and validation
  • validate/1 - Customize filter validation logic
  • build_query/3 - Customize query building
  • default_options/0 - Customize default options
  • empty?/1 - Customize empty value detection

The generated filter will be immediately ready to use in your tables.