Finished implementation of styles

This commit is contained in:
VetheonGames 2024-06-22 11:01:46 -06:00
parent f65d4f9132
commit 99b4b136c4
2 changed files with 3 additions and 18 deletions

1
.gitignore vendored
View File

@ -76,3 +76,4 @@ test_project/subdir1/file2.rb
test_project/subdir1/file3.rb
test_project/subdir2/file4.rb
test_project/subdir2/file5.rb
test_project/TODO.md

View File

@ -6,13 +6,10 @@ require 'find'
module TodoMarker
TODO_REGEX = /# !!TODO!!(?: style: (\w+))? "(.*?)"/
STYLE_REGEX = /`style: (\w+?)` (.*?)`/
STYLES = {
'title' => '## %s',
'title1' => '# %s',
'sublist' => ' - %s',
'super-text' => '<sup>%s</sup>',
'sub-text' => '<sub>%s</sub>'
'sublist' => ' - %s'
}.freeze
def self.generate_todo_md(directory)
@ -25,7 +22,6 @@ module TodoMarker
next unless line.match(TODO_REGEX)
style, message = line.match(TODO_REGEX).captures
message = parse_styles(message)
todos << {
style:,
message:,
@ -38,25 +34,13 @@ module TodoMarker
create_todo_file(directory, todos)
end
def self.parse_styles(message)
while message.match?(STYLE_REGEX)
message.gsub!(STYLE_REGEX) do
style, text = Regexp.last_match.captures
STYLES[style] % text
end
end
message
end
def self.create_todo_file(directory, todos)
File.open(File.join(directory, 'TODO.md'), 'w') do |file|
file.puts "# TODO List\n\n"
previous_style = nil
todos.each do |todo|
formatted_message = format_message(todo[:style], todo[:message])
file.puts formatted_message
file.puts " (#{todo[:file]}:#{todo[:line]})" if todo[:style] != 'sublist' && todo[:style].nil?
previous_style = todo[:style]
file.puts " (#{todo[:file]}:#{todo[:line]})" if todo[:style].nil?
end
end
end