Last active
August 29, 2015 14:15
-
-
Save hugopeixoto/b83bca5e247716e7f0da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Listing | |
markdown :title, :description | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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