Module: Flutterby::Filters
Class Method Summary collapse
- .add(fmts, &blk) ⇒ Object
- .apply!(input, filters, view:, &blk) ⇒ Object
- .tilt(format, body, options = {}) ⇒ Object
Instance Method Summary collapse
- #add(fmts, &blk) ⇒ Object
- #apply!(input, filters, view:, &blk) ⇒ Object
- #tilt(format, body, options = {}) ⇒ Object
Class Method Details
.add(fmts, &blk) ⇒ Object
29 30 31 32 33 |
# File 'lib/flutterby/filters.rb', line 29 def add(fmts, &blk) Array(fmts).each do |fmt| define_singleton_method("process_#{fmt}!", &blk) end end |
.apply!(input, filters, view:, &blk) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flutterby/filters.rb', line 13 def apply!(input, filters, view:, &blk) # Apply all filters filters.inject(input) do |body, filter| meth = "process_#{filter}!" if Filters.respond_to?(meth) Filters.send(meth, body, view: view, &blk) elsif template = tilt(filter, body) template.render(view, view.locals, &blk).html_safe else Flutterby.logger.warn "Unsupported filter '#{filter}'" body end end end |
.tilt(format, body, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/flutterby/filters.rb', line 35 def tilt(format, body, = {}) = { "erb" => { engine_class: Erubis::Auto::EscapedEruby } } = .fetch(format, {}).merge() t = Tilt[format] and t.new() { body } end |
Instance Method Details
#add(fmts, &blk) ⇒ Object
29 30 31 32 33 |
# File 'lib/flutterby/filters.rb', line 29 def add(fmts, &blk) Array(fmts).each do |fmt| define_singleton_method("process_#{fmt}!", &blk) end end |
#apply!(input, filters, view:, &blk) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flutterby/filters.rb', line 13 def apply!(input, filters, view:, &blk) # Apply all filters filters.inject(input) do |body, filter| meth = "process_#{filter}!" if Filters.respond_to?(meth) Filters.send(meth, body, view: view, &blk) elsif template = tilt(filter, body) template.render(view, view.locals, &blk).html_safe else Flutterby.logger.warn "Unsupported filter '#{filter}'" body end end end |
#tilt(format, body, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/flutterby/filters.rb', line 35 def tilt(format, body, = {}) = { "erb" => { engine_class: Erubis::Auto::EscapedEruby } } = .fetch(format, {}).merge() t = Tilt[format] and t.new() { body } end |