Skip to content

Instantly share code, notes, and snippets.

@stephancom
Created May 6, 2019 20:59
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 stephancom/68e1689ba0fd4740278f8177e5dbb115 to your computer and use it in GitHub Desktop.
Save stephancom/68e1689ba0fd4740278f8177e5dbb115 to your computer and use it in GitHub Desktop.
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