Created
May 6, 2019 20:59
-
-
Save stephancom/68e1689ba0fd4740278f8177e5dbb115 to your computer and use it in GitHub Desktop.
Markdown fields concern
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
# __ __ _ _ ___ _ _ _ | |
# | \/ |__ _ _ _| |____| |_____ __ ___ _ | __(_)___| |__| |___ | |
# | |\/| / _` | '_| / / _` / _ \ 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