Sha256: 275cd709f5d38e5200ed33a05f818eaa7fa2d00f2cfb30d5507ae8711ce2043d

Contents?: true

Size: 803 Bytes

Versions: 2

Compression:

Stored size: 803 Bytes

Contents

require 'active_support/core_ext/kernel/concern'

module HtmlFormat
  concern :ActiveRecord do
    class_methods do
      def to_html(**options)
        HtmlFormat.generate(all.collect(&:attributes), options)
      end
    end

    def to_html(**options)
      HtmlFormat.generate(attributes, options)
    end
  end
end

Kernel.class_eval do
  private

  def html_format(object = nil, options = {}, &block)
    if block
      options = object || {}
      object = yield
    end
    if object.respond_to?(:to_html)
      object.to_html(options)
    else
      HtmlFormat.generate(object, options)
    end
  end
end

[Array, Symbol, String, Hash, Numeric, TrueClass, FalseClass, NilClass].each do |e|
  e.class_eval do
    def to_html(**options)
      HtmlFormat.generate(self, options)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
html_format-0.0.9 lib/html_format/core_ext.rb
html_format-0.0.8 lib/html_format/core_ext.rb