module ErbAsterisk::Yields
Public Instance Methods
apply_line_to(tag, line, args = {})
click to toggle source
Apply line to place where yield_here
:tag defined
# File lib/erb_asterisk/yields.rb, line 4 def apply_line_to(tag, line, args = {}) default_args!(args) apply_to_yields(tag, line, args[:priority]) log_debug("apply_line_to: :#{tag}, #{line}, #{args}", 2) "; Applied \"#{line}\" to :#{tag}" end
content_for(tag, args = {}) { || ... }
click to toggle source
Apply block to yield_here
# File lib/erb_asterisk/yields.rb, line 13 def content_for(tag, args = {}) default_args!(args) old_output = @erb_output @erb_output = '' apply_to_yields(tag, yield, args[:priority]) log_debug("content_for: :#{tag}, #{args}", 2) @erb_output = old_output end
yield_actual(tag)
click to toggle source
# File lib/erb_asterisk/yields.rb, line 30 def yield_actual(tag) "; Yield for :#{tag}\n" << output_yield(tag) end
yield_here(tag)
click to toggle source
Define place where put apply_line_to
# File lib/erb_asterisk/yields.rb, line 25 def yield_here(tag) @yield_here_occured = true "<%= yield_actual :#{tag} %>" end
Private Instance Methods
apply_to_yields(tag, content, priority)
click to toggle source
# File lib/erb_asterisk/yields.rb, line 36 def apply_to_yields(tag, content, priority) @yields[tag] = [] if @yields[tag].nil? @yields[tag] << { content: content, priority: priority } end
output_yield(tag)
click to toggle source
# File lib/erb_asterisk/yields.rb, line 41 def output_yield(tag) a = @yields[tag] log_debug("yield_here: :#{tag}, size=#{a.size}", 2) a = a.sort_by { |i| -i[:priority] } result = a.reduce('') do |s, i| s << "; priority: #{i[:priority]}\n" if i[:priority] != 0 s << "#{i[:content]}\n" end result end