Skip to content

Instantly share code, notes, and snippets.

@hugopeixoto
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugopeixoto/b83bca5e247716e7f0da to your computer and use it in GitHub Desktop.
Save hugopeixoto/b83bca5e247716e7f0da to your computer and use it in GitHub Desktop.
class Listing
markdown :title, :description
end
class MarkdownAttribute
def self.load value
return nil if value.nil? # or something
MarkdownAttribute.new(value)
end
def self.dump obj
return nil if obj.nil? # or something
obj.markdown
end
def initialize value
@raw = value
end
def to_s
Redcarpet::Markdown.new(RemoveMarkdownRenderer).render(markdown)
end
def markdown
@raw.to_s
end
def html
Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(markdown).safe_html
end
end
module MarkdownHandler
extend ActiveSupport::Concern
module ClassMethods
def markdown( *attributes_with_markdown )
attributes_with_markdown.each do |attribute|
serialize attribute, MarkdownAttribute
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment