Module: Shamu::Entities::HtmlSanitation::AttributeMethod

Included in:
Shamu::Entities::HtmlSanitation
Defined in:
lib/shamu/entities/html_sanitation.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, on: , default: , build: , &block) ⇒ self #attribute(name, build, on: , default: , &block) ⇒ self

Define a new attribute for the class.

Parameters:

  • name (Symbol)

    of the attribute.

  • as (Symbol)

    an alias of the attribute.

  • on (Symbol)

    another method on the class to delegate the attribute to.

  • default (Object, #call)

    value if not set.

  • build (Class, #call)

    method used to build a nested object on assignment of a hash with nested keys.

  • serialize (Boolean)

    true if the attribute should be included in #to_attributes. Default true.

  • html (Symbol, #call)

    sanitation options. Acceptable values are

    • :none strip all HTML. The default.
    • :simple simple formatting suitable for most places. See Attributes::HtmlSanitation#simple_html_sanitize for details.
    • :body basic formatting for 'body' text. See Attributes::HtmlSanitation#body_html_sanitize for details.
    • :allow permit any HTML tag.
    • Any other symbol is assumed to be a method on the entity that will be called to filter the html.
    • #call anything that responds to #call that takes a single argument of the raw string and returns the sanitized HTML.

Yield Returns:

  • the value of the attribute. The result is memoized so the block is only invoked once.

Returns:

  • (self)


15
16
17
18
19
# File 'lib/shamu/entities/html_sanitation.rb', line 15

def attribute( name, *args, **options, &block )
  options[:html] ||= :none

  super name, *args, **options, &block
end