module WrapIt::TextContainer

Provides functionality for text-contained components.

Text can be captured from `:text` or `:body` option, or as first unparsed String argument, or in block, provided to constructor.

If block given, text will be captured from it in priority, so String arguments and options will not parsed. You can cancel this manner by calling {ClassMethods#text_in_block text_in_block(false)} method.

This module adds `body` section before base `content` section.

@author Alexey Ovchinnikov <alexiss@cybernetlab.ru>

Public Class Methods

included(base) click to toggle source
# File lib/wrap_it/text_container.rb, line 18
def self.included(base)
  base.class_eval do
    extend ClassMethods

    default_tag 'p', false

    option(:body, if: %i(body text)) { |_, v| body << v }
    argument(:body, first_only: true, after_options: true,
             if: String,
             and: ->{ !block_provided? || !text_in_block? }) do |_, v|
      self.class.html_safe? && v = html_safe(v)
      body << v
    end

    section :body
    place :body, :before, :content

    after_capture do
      self[:body] = html_safe(@body) unless @body.nil? || @body.empty?
    end
  end
end

Public Instance Methods

body() click to toggle source

Retrieves body text

@return [String] text

# File lib/wrap_it/text_container.rb, line 45
def body
  @body ||= empty_html
end