Skip to content

Instantly share code, notes, and snippets.

@iande
Created March 19, 2011 05:41
Show Gist options
  • Select an option

  • Save iande/877253 to your computer and use it in GitHub Desktop.

Select an option

Save iande/877253 to your computer and use it in GitHub Desktop.
class Page < Ohm::Model
attribute :name
attribute :html
list :blocks, BlockContent
index :name
def validate
assert_present :name
end
def parse_block_content
self.blocks.clear
doc = Nokogiri::HTML(self.html)
doc.css('body *').each do |child|
self.blocks << BlockContent.create(:element => child.name,
:id_name => child['id'], :class_name => child['class'],
:content => child.content)
end
end
end
class BlockContent < Ohm::Model
attribute :element
attribute :id_name
attribute :class_name
attribute :content
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment