Class: Amrita2::Filters::Join

Inherits:
Base show all
Defined in:
lib/amrita2/template.rb

Instance Attribute Summary

Attributes inherited from Base

#next_

Instance Method Summary collapse

Methods inherited from Base

filter_method, inherited, #parse_filter_a, #|

Constructor Details

#initialize(sep) ⇒ Join

Returns a new instance of Join.



2506
2507
2508
2509
2510
2511
2512
# File 'lib/amrita2/template.rb', line 2506

def initialize(sep)
  @sep = case sep
         when :br ; "<br />"
         when :nbsp ; "&#160;"
         else ; sep
         end
end

Instance Method Details

#filter_element(de, e) ⇒ Object



2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
# File 'lib/amrita2/template.rb', line 2514

def filter_element(de, e)
  a = e.children.dup
  a.each do |n|
    case n
    when Hpricot::CData, Hpricot::Elem
      e.insert_after(Hpricot::Text.new(@sep), n) unless n == a.last
    when Hpricot::Text
      e.insert_after(Hpricot::Text.new(@sep), n) unless n == a.last
      n.content.strip!
      n.content.gsub!(/\s*\n\s*/, @sep)
    end
  end
  e
end