Class: MongoidMarkdownExtension::Markdown
- Inherits:
-
String
- Object
- String
- MongoidMarkdownExtension::Markdown
- Defined in:
- lib/mongoid_markdown_extension/markdown.rb
Class Attribute Summary collapse
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .demongoize(value) ⇒ Object
- .evolve(value) ⇒ Object
- .mongoize(value) ⇒ Object
- .reset ⇒ Object
Instance Method Summary collapse
- #gsub(*args) ⇒ Object
-
#initialize(str) ⇒ Markdown
constructor
A new instance of Markdown.
- #split(*args) ⇒ Object
- #to_html ⇒ Object
- #to_inline_html(line_breaks: false) ⇒ Object
- #to_stripped_s ⇒ Object
Constructor Details
#initialize(str) ⇒ Markdown
Returns a new instance of Markdown.
40 41 42 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 40 def initialize(str) super(str.to_s) end |
Class Attribute Details
.configuration ⇒ Object
9 10 11 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 9 def configuration @configuration ||= Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
17 18 19 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 17 def configure yield(configuration) end |
.demongoize(value) ⇒ Object
21 22 23 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 21 def demongoize(value) Markdown.new(value) end |
.evolve(value) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 32 def evolve(value) case value when Markdown then value.mongoize else value end end |
.mongoize(value) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 25 def mongoize(value) case value when Markdown then value.mongoize else value end end |
.reset ⇒ Object
13 14 15 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 13 def reset @configuration = Configuration.new end |
Instance Method Details
#gsub(*args) ⇒ Object
48 49 50 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 48 def gsub(*args) self.class.new(super(*args)) end |
#split(*args) ⇒ Object
44 45 46 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 44 def split(*args) super(*args).map { |str| self.class.new(str) } end |
#to_html ⇒ Object
52 53 54 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 52 def to_html markdown_renderer.render(to_s).html_safe end |
#to_inline_html(line_breaks: false) ⇒ Object
56 57 58 59 60 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 56 def to_inline_html(line_breaks: false) rendered = markdown_inline_renderer.render(to_s).gsub(/(<br\s?\/?>)+?\z/, '') rendered.gsub!(/(<br\s?\/?>)+?\Z/, '') if !line_breaks rendered.html_safe end |
#to_stripped_s ⇒ Object
62 63 64 |
# File 'lib/mongoid_markdown_extension/markdown.rb', line 62 def to_stripped_s markdown_stripdown_renderer.render(to_s).try(:strip) end |