Support search on markdown fields
This commit is contained in:
@@ -9,6 +9,14 @@ module ActionText
|
||||
markdown_#{name} || build_markdown_#{name}
|
||||
end
|
||||
|
||||
def #{name}_html
|
||||
#{name}.to_html
|
||||
end
|
||||
|
||||
def #{name}_plain_text
|
||||
#{name}.to_plain_text
|
||||
end
|
||||
|
||||
def #{name}?
|
||||
markdown_#{name}.present?
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require "redcarpet/render_strip"
|
||||
|
||||
module ActionText
|
||||
class Markdown < Record
|
||||
DEFAULT_RENDERER_OPTIONS = {
|
||||
@@ -14,14 +16,18 @@ module ActionText
|
||||
tables: true
|
||||
}
|
||||
|
||||
mattr_accessor :renderer, default: Redcarpet::Markdown.new(
|
||||
Redcarpet::Render::HTML.new(DEFAULT_RENDERER_OPTIONS), DEFAULT_MARKDOWN_EXTENSIONS)
|
||||
mattr_accessor :renderer, default: Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(DEFAULT_RENDERER_OPTIONS), DEFAULT_MARKDOWN_EXTENSIONS)
|
||||
mattr_accessor :plain_renderer, default: Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
|
||||
|
||||
belongs_to :record, polymorphic: true, touch: true
|
||||
|
||||
def to_html
|
||||
(renderer.try(:call) || renderer).render(content).html_safe
|
||||
end
|
||||
|
||||
def to_plain_text
|
||||
(plain_renderer.try(:call) || plain_renderer).render(content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
module RailsExt
|
||||
module ActiveSupportArrayConversions
|
||||
def to_choice_sentence
|
||||
to_sentence two_words_connector: " or ", last_word_connector: ", or "
|
||||
end
|
||||
module ChoiceSentenceArrayConversion
|
||||
def to_choice_sentence
|
||||
to_sentence two_words_connector: " or ", last_word_connector: ", or "
|
||||
end
|
||||
end
|
||||
|
||||
Array.include RailsExt::ActiveSupportArrayConversions
|
||||
Array.include ChoiceSentenceArrayConversion
|
||||
|
||||
Reference in New Issue
Block a user