diff options
Diffstat (limited to 'app/lib/command_tag')
-rw-r--r-- | app/lib/command_tag/processor.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb index da6d49160..4f11c0c0d 100644 --- a/app/lib/command_tag/processor.rb +++ b/app/lib/command_tag/processor.rb @@ -16,7 +16,6 @@ class CommandTag::Processor include CommandTag::Commands STATEMENT_RE = /^\s*#!\s*([^\n]+ (?:start|begin|do)$.*?)\n\s*#!\s*(?:end|stop|done)\s*$|^\s*#!\s*(.*?)\s*$/im.freeze - STATEMENT_STRIP_RE = /^\s*#!\s*(?:[^\n]+ (?:start|begin|do)$.*?)\n\s*#!\s*(?:end|stop|done)\s*$\n?|^\s*#!\s*(?:.*?)\s*$\n?/im.freeze TEMPLATE_RE = /%%\s*(.*?)\s*%%/.freeze ESCAPE_MAP = { '\n' => "\n", @@ -42,10 +41,9 @@ class CommandTag::Processor reset_status_caches parse_statements - @text = @text.gsub(STATEMENT_STRIP_RE, '').split("\n") %w(at_start once_at_start).each { |suffix| execute_statements(suffix) } - @text = parse_templates(@text.join("\n")).rstrip + @text = parse_templates(@text).rstrip %w(before_save once_before_save).each { |suffix| execute_statements(suffix) } if @text.blank? || @text.gsub(Account::MENTION_RE, '').strip.blank? @@ -113,14 +111,16 @@ class CommandTag::Processor end def parse_statements - @text.scan(STATEMENT_RE).flatten.compact.each do |statement| + @text.gsub!(STATEMENT_RE) do + statement = Regexp.last_match[1..-1].flatten.compact next if statement.blank? - statement = statement.scan(/'([^']*)'|"([^"]*)"|(\S+)|\s+(?:start|begin|do)\s*$\n+(.*)/im).flatten.compact - statement[0] = statement[0].strip.tr(':.\- ', '_').gsub(/__+/, '_').downcase - statement[-1].rstrip! if statement.count > 1 + statement_array = statement.scan(/'([^']*)'|"([^"]*)"|(\S+)|\s+(?:start|begin|do)\s*$\n+(.*)/im).flatten.compact + statement_array[0] = statement_array[0].strip.tr(':.\- ', '_').gsub(/__+/, '_').downcase + next unless statement_array[0].match?(/\A\w+\z/) - add_statement_handlers_for(statement) if statement[0].present? + statement_array[-1].rstrip! if statement_array.count > 1 + add_statement_handlers_for(statement_array) end end @@ -138,7 +138,7 @@ class CommandTag::Processor end end - def add_statement_handlers_for(statement_array) + def add_statement_handlers_for(statement_array, _index) potential_handlers_for(statement_array[0]) do |handler, once| (@statements << [handler, statement_array[1..-1]]) if respond_to?(handler) && !(once && @run_once.include?(handler)) @run_once << handler if once |