Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Markdown fields concern
# __ __ _ _ ___ _ _ _
# | \/ |__ _ _ _| |____| |_____ __ ___ _ | __(_)___| |__| |___
# | |\/| / _` | '_| / / _` / _ \ V V / ' \| _|| / -_) / _` (_-<
# |_| |_\__,_|_| |_\_\__,_\___/\_/\_/|_||_|_| |_\___|_\__,_/__/
#
# "Immature poets imitate; mature poets steal" - T. S. Eliot
# "When there's anything to steal, I steal" - Pable Picasso
# "Good artists copy; great artists steal" - Steve Jobs
#
module MarkdownFields
extend ActiveSupport::Concern
included do
def self.markdown_fields(*attrs)
attrs.each do |attr|
define_method "#{attr}_to_html".to_sym do
parse_markdown send(attr)
end
end
end
end
protected
def parse_markdown(text)
return nil unless text
Kramdown::Document.new(text).to_html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.