Sha256: effbe5ac95bf11e6a1c1d43db565c09848e899aa2b8dd9a60199e5112f7ed223

Contents?: true

Size: 1008 Bytes

Versions: 12

Compression:

Stored size: 1008 Bytes

Contents

module ActiveRecord::ToHtml
  def to_html(options = {}, &block)
    options = { 
      :skip_instruct => true, 
    }.update(options)
    
    to_xml(options, &block).gsub( /<[^>]+>/ ) do |m|
      if m.starts_with?("</")
        "</div>"
      else
        m =~ /^<(\S+)\s*([^>]*)>$/
        klass, args = $1, $2 
        "<div class='#{klass}'#{args.blank? ? "" : " #{args}"}>"
      end
    end
  end
end

class ActiveRecord::Base
  include ActiveRecord::ToHtml
end

module ActiveRecord::ToHtml::Etest
  class Data < ActiveRecord::Base
  end

  def setup
    Data.lite_table do
      string :name
      string :age
    end

    Data.create! :name => "name", :age => 2

    assert_equal(1, Data.count)
  end
  
  def teardown
    Data.destroy_all
  end
  
  def test_to_html
    html = <<-HTML
<div class='active-record-to-html-etest-data'>
  <div class='age'>2</div>
  <div class='id' type="integer">25</div>
  <div class='name'>name</div>
</div>
HTML

    assert_equal html, Data.first.to_html
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vex-0.6.2 lib/vex/active_record/to_html.rb
vex-0.4.4 lib/vex/active_record/to_html.rb
vex-0.4.2 lib/vex/active_record/to_html.rb
vex-0.3.3 lib/vex/active_record/to_html.rb
vex-0.2.9 lib/vex/active_record/to_html.rb
vex-0.2.8 lib/vex/active_record/to_html.rb
vex-0.2.7 lib/vex/active_record/to_html.rb
vex-0.2.6 lib/vex/active_record/to_html.rb
vex-0.2.5 lib/vex/active_record/to_html.rb
vex-0.2.2 lib/vex/active_record/to_html.rb
vex-0.2.1 lib/vex/active_record/to_html.rb
vex-0.2 lib/vex/active_record/to_html.rb