class Overapp::TemplateFile::Params

Attributes

full_body[RW]
path[RW]

Public Instance Methods

body() click to toggle source
# File lib/overapp/template_file/params.rb, line 6
def body; full_body; end
each(&b) click to toggle source
# File lib/overapp/template_file/params.rb, line 8
def each(&b)
  note_params.each(&b)
end
has_note?() click to toggle source
# File lib/overapp/template_file/params.rb, line 68
def has_note?
  note_params.any? { |x| x[:action].present? }
end
note_params_single(one) click to toggle source
# File lib/overapp/template_file/params.rb, line 36
def note_params_single(one)
  res = {}
  note = one[:note]
  res[:body] = one[:body]

  if note
    lines = note.split("\n").select { |x| x.present? }
    if (lines.size == 1) && !(lines.first =~ /[a-z]+:/)
      res[:action] = lines.first.strip
    else
      lines.each do |line|
        parts = line.split(":").select { |x| x.present? }
        if parts.size > 2
          parts = [parts[0],parts[1..-1].join(":")]
        end
        parts = parts.map { |x| x.strip }
        raise "bad #{path} #{parts.inspect}" unless parts.size == 2
        res[parts[0].to_sym] = parts[1]
      end
    end
  end
  res
end
split_note_and_body() click to toggle source
# File lib/overapp/template_file/params.rb, line 12
def split_note_and_body
  res = []
  remaining_body = full_body
  while remaining_body
    if remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)(<over(?:lay|app)>.+)/m
      note = $1
      rest = $2
      remaining_body = $3
      res << {:note => note, :body => rest}
    elsif remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)/m
      note = $1
      rest = $2
      remaining_body = nil
      res << {:note => note, :body => rest}
    else
      res << {:note => nil, :body => remaining_body}
      remaining_body = nil
    end
  end
  res
rescue => exp
  raise "split_note_and_body #{path} #{exp.message}"
end