Module: HasHtmlPipeline
- Defined in:
- lib/has_html_pipeline.rb,
lib/has_html_pipeline/version.rb
Overview
Usage:
HasHtmlPipeline.register_html_pipeline(:markdown, [HTML::Pipeline::MarkdownFilter])
class User
extend HasHtmlPipeline
attr_accessor :about
has_html_pipeline :about, :markdown
end
u = User.new
u.about = '# Markdown #'
u.about_html # => '<h1>Markdown</h1>'
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .configure {|_self| ... } ⇒ Object
-
.included(klass) ⇒ Object
for ‘include HasHtmlPipeline`.
- .register_html_pipeline(name, filters, context = {}) ⇒ Object (also: register)
- .registered_html_pipelines ⇒ Object
Instance Method Summary collapse
Class Method Details
.configure {|_self| ... } ⇒ Object
36 37 38 |
# File 'lib/has_html_pipeline.rb', line 36 def configure yield self end |
.included(klass) ⇒ Object
for ‘include HasHtmlPipeline`
22 23 24 |
# File 'lib/has_html_pipeline.rb', line 22 def included(klass) klass.extend(self) end |
.register_html_pipeline(name, filters, context = {}) ⇒ Object Also known as: register
30 31 32 |
# File 'lib/has_html_pipeline.rb', line 30 def register_html_pipeline(name, filters, context = {}) registered_html_pipelines[name.to_sym] = HTML::Pipeline.new(filters, context) end |
.registered_html_pipelines ⇒ Object
26 27 28 |
# File 'lib/has_html_pipeline.rb', line 26 def registered_html_pipelines @registered_html_pipelines ||= {} end |
Instance Method Details
#has_html_pipeline(field, pipeline_name) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/has_html_pipeline.rb', line 41 def has_html_pipeline(field, pipeline_name) define_method "#{field}_html" do pipeline = ::HasHtmlPipeline.registered_html_pipelines[pipeline_name.to_sym] pipeline.call(send(field))[:output].to_s end end |