diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-07-27 11:34:45 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:45:16 -0500 |
commit | 708fda8f29cf35dfd1d53078b1204fdb79bbc5e3 (patch) | |
tree | 1ce0d54de6548b61b5cef4deebe74cac5c65ae78 /app | |
parent | fd69bc85ec5d7af0033471d9079d9ed3fba4d93e (diff) |
[Command Tags] Add commands for appending, prepending, and replacing body text
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/command_tag/commands/text_tools.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/lib/command_tag/commands/text_tools.rb b/app/lib/command_tag/commands/text_tools.rb index 441706265..19f4b4f57 100644 --- a/app/lib/command_tag/commands/text_tools.rb +++ b/app/lib/command_tag/commands/text_tools.rb @@ -14,4 +14,30 @@ module CommandTag::Commands::TextTools ["----------\n#{value}\n----------"] end end + + def handle_prepend_before_save(args) + args.each { |arg| @text = "#{arg}\n#{text}" } + end + + def handle_append_before_save(args) + args.each { |arg| @text << "\n#{arg}" } + end + + def handle_replace_before_save(args) + @text.gsub!(args[0], args[1] || '') + end + + alias handle_sub_before_save handle_replace_before_save + + def handle_regex_replace_before_save(args) + flags = normalize(args[2]) + re_opts = (flags.include?('i') ? Regexp::IGNORECASE : 0) + re_opts |= (flags.include?('x') ? Regexp::EXTENDED : 0) + re_opts |= (flags.include?('m') ? Regexp::MULTILINE : 0) + + @text.gsub!(Regexp.new(args[0], re_opts), args[1] || '') + end + + alias handle_resub_before_save handle_replace_before_save + alias handle_regex_sub_before_save handle_replace_before_save end |