Sha256: d74b48e6eee8309d33b297bbdef06bfeab9e0a93bd5325ff065b3a0d076358ba

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module ActsAsContentHighlightable
  module Model
    def acts_as_content_highlightable_on(column_names)
      column_names = [column_names].flatten
      if not column_names.all? {|column_name| self.column_names.include? column_name.to_s}
        raise ArgumentError, "acts_as_content_highlightable_on: One or more invalid attribute #{column_names}"
      end

      class_eval do
        has_many :content_highlights, :as => :highlightable
        before_save :prepare_for_content_highlights, :if => column_names.map{|column_name| "#{column_name}_changed?"}
      end

      class_eval %{
        def highlightable_columns
          return #{column_names.map(&:to_s)}
        end
        def prepare_for_content_highlights
          #{column_names}.each do |column_name|
            self[column_name.to_sym] = ActsAsContentHighlightable::HtmlNodeParser.new(self[column_name.to_sym]).assign_unique_node_identifiers("data-" + ActsAsContentHighlightable.unique_html_node_identifier_key).body_content
          end
        end
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_content_highlightable-0.2.1 lib/acts_as_content_highlightable/model.rb
acts_as_content_highlightable-0.2.0 lib/acts_as_content_highlightable/model.rb