markdown_class_attributes.rb 923 B

1234567891011121314151617181920212223242526272829303132
  1. module MarkdownClassAttributes
  2. extend ActiveSupport::Concern
  3. module ClassMethods
  4. def markdown_class_attributes(*attributes)
  5. attributes.each do |attribute|
  6. class_eval <<-RUBY
  7. def html_#{attribute}
  8. Kramdown::Document.new(#{attribute}, :auto_ids => false).to_html.html_safe
  9. end
  10. def #{attribute}
  11. if self.class.#{attribute}.is_a?(Proc)
  12. Utils.unindent(self.instance_eval(&self.class.#{attribute}) || "No #{attribute} has been set.")
  13. else
  14. Utils.unindent(self.class.#{attribute} || "No #{attribute} has been set.")
  15. end
  16. end
  17. def self.#{attribute}(value = nil, &block)
  18. if block
  19. @#{attribute} = block
  20. elsif value
  21. @#{attribute} = value
  22. end
  23. @#{attribute}
  24. end
  25. RUBY
  26. end
  27. end
  28. end
  29. end