Class | Yapra::Plugin::Filter::ApplyTemplate |
In: |
lib-plugins/yapra/plugin/filter/apply_template.rb
|
Parent: | Yapra::Plugin::Base |
apply template and set to attribute.
example:
- module: Filter::ApplyTemplate config: content_encoded: '<div><%= title %></div>'
# File lib-plugins/yapra/plugin/filter/apply_template.rb, line 15 15: def run(data) 16: regexp = nil 17: if config['regexp'] 18: regexp = Regexp.new(config['regexp']) 19: else 20: regexp = /^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/ 21: end 22: 23: data.map! do |item| 24: url = item 25: if item.respond_to?('link') 26: url = item.link 27: end 28: 29: if regexp =~ url 30: unless(item.instance_of?(RSS::RDF::Item)) 31: new_item = RSS::RDF::Item.new 32: new_item.title = item.title rescue item.to_s 33: new_item.date = item.date rescue Time.now 34: new_item.description = item.description rescue item.to_s 35: new_item.link = item.link rescue '#' 36: item = new_item 37: end 38: 39: if plugin_config 40: plugin_config.each do |k, template| 41: value = apply_template template, binding 42: set_attribute_to item, k, value 43: end 44: end 45: end 46: item 47: end 48: 49: data 50: end