Module: FsTemplate::TemplateFile::OldWay

Included in:
FsTemplate::TemplateFile
Defined in:
lib/fs_template/template_file.rb

Instance Method Summary collapse

Instance Method Details

#apply_body_to_short(base_body) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fs_template/template_file.rb', line 72

def apply_body_to_short(base_body)
  note_parts = note.to_s.split(":")
  if note == 'append'
    base_body + body
  elsif note_parts[0] == 'insert'
    raise "bad" unless note_parts[1] == 'line'
    base_lines = base_body.split("\n")
    i = note_parts[2].to_i - 1
    base_lines[0...i].join("\n") + body + base_lines[i..-1].join("\n")
  else
    raise "unknown note #{note}"
  end
end

#split_note_and_body_shortObject



62
63
64
65
66
67
68
69
70
# File 'lib/fs_template/template_file.rb', line 62

def split_note_and_body_short
  if full_body =~ /^FSTMODE:([a-z:0-9]+)\s/m
    note = $1
    rest = full_body.gsub(/^FSTMODE:#{note}/,"")
    {:note => note, :body => rest, :format => :short}
  else
    nil
  end
end