Methods

Attributes

[R] source

Class Public methods

from_html(html)

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 17
      def from_html(html)
        new(ActionText::HtmlConversion.fragment_for_html(html.to_s.strip))
      end
🔎 See on GitHub

new(source)

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 24
    def initialize(source)
      @source = source
    end
🔎 See on GitHub

wrap(fragment_or_html)

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 6
      def wrap(fragment_or_html)
        case fragment_or_html
        when self
          fragment_or_html
        when Nokogiri::HTML::DocumentFragment
          new(fragment_or_html)
        else
          from_html(fragment_or_html)
        end
      end
🔎 See on GitHub

Instance Public methods

find_all(selector)

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 28
    def find_all(selector)
      source.css(selector)
    end
🔎 See on GitHub

replace(selector)

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 37
    def replace(selector)
      update do |source|
        source.css(selector).each do |node|
          node.replace(yield(node).to_s)
        end
      end
    end
🔎 See on GitHub

to_html()

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 49
    def to_html
      @html ||= HtmlConversion.node_to_html(source)
    end
🔎 See on GitHub

to_plain_text()

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 45
    def to_plain_text
      @plain_text ||= PlainTextConversion.node_to_plain_text(source)
    end
🔎 See on GitHub

to_s()

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 53
    def to_s
      to_html
    end
🔎 See on GitHub

update()

📝 Source code
# File actiontext/lib/action_text/fragment.rb, line 32
    def update
      yield source = self.source.clone
      self.class.new(source)
    end
🔎 See on GitHub