Sha256: cfa676c9436c59c484fabd8ae99a1dc7f57ecd554778cea611c7bf7302dd341e
Contents?: true
Size: 863 Bytes
Versions: 3
Compression:
Stored size: 863 Bytes
Contents
module Tablifier class Base include Singleton extend ERB::Util def erb @erb ||= ERB.new File.open(File.join(Gem::Specification.find_by_name('tablifier').gem_dir, 'lib', 'tablifier', 'template.html.erb')).read end def self.tablify obj raise ArgumentError, "tablify is only implemented for Hash and ActiveRecord objects, not: '#{obj.class_name}'" unless obj.is_a?(Hash) || obj.is_a?(ActiveRecord::Base) @class_name = obj.class.name @h = if obj.is_a?(ActiveRecord::Base) @obj_id = obj.id @to_s = obj.to_s obj.attributes else @obj_id = nil @to_s = nil obj.map{|k,v| [k.to_s,v]}.to_h end instance.erb.result(binding).html_safe end end end ActionView::Helpers::DebugHelper.module_eval do def tablify obj Tablifier::Base.tablify obj end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tablifier-1.1.2 | lib/tablifier/tablifier.rb |
tablifier-1.1.1 | lib/tablifier/tablifier.rb |
tablifier-1.1.0 | lib/tablifier/tablifier.rb |