Adding in additional formatting options
This commit is contained in:
parent
7697f49799
commit
b47350d96d
|
@ -5,7 +5,15 @@ require 'todo_marker/version'
|
|||
require 'find'
|
||||
|
||||
module TodoMarker
|
||||
TODO_REGEX = /# !!TODO!! "(.*?)"/
|
||||
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>'
|
||||
}.freeze
|
||||
|
||||
def self.generate_todo_md(directory)
|
||||
todos = []
|
||||
|
@ -16,8 +24,11 @@ module TodoMarker
|
|||
File.readlines(path).each_with_index do |line, index|
|
||||
next unless line.match(TODO_REGEX)
|
||||
|
||||
style, message = line.match(TODO_REGEX).captures
|
||||
message = parse_styles(message)
|
||||
todos << {
|
||||
message: line.match(TODO_REGEX)[1],
|
||||
style:,
|
||||
message:,
|
||||
file: path,
|
||||
line: index + 1
|
||||
}
|
||||
|
@ -27,12 +38,38 @@ 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|
|
||||
file.puts "- #{todo[:message]} (#{todo[:file]}:#{todo[:line]})"
|
||||
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]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.format_message(style, message)
|
||||
if style
|
||||
if style == 'sublist'
|
||||
" - #{message}"
|
||||
else
|
||||
STYLES[style] % message
|
||||
end
|
||||
else
|
||||
"- #{message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
# lib/todo_marker/version.rb
|
||||
module TodoMarker
|
||||
VERSION = '0.1.0'
|
||||
VERSION = '0.1.2'
|
||||
end
|
||||
|
|
30
test_project/TODO.md
Normal file
30
test_project/TODO.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# TODO List
|
||||
|
||||
- Complete method implementation
|
||||
(./test_project/file1.rb:1)
|
||||
# Main Section
|
||||
- Main task
|
||||
(./test_project/file1.rb:6)
|
||||
- Subtask 1
|
||||
- Subtask 2
|
||||
- Normal TODO item
|
||||
(./test_project/file1.rb:9)
|
||||
- Refactor this method
|
||||
(./test_project/subdir1/file2.rb:1)
|
||||
- Add error handling
|
||||
(./test_project/subdir1/file3.rb:1)
|
||||
## Secondary Section
|
||||
- Secondary Task
|
||||
(./test_project/subdir1/file3.rb:6)
|
||||
- Subtask A
|
||||
- Subtask B
|
||||
- Optimize performance
|
||||
(./test_project/subdir2/file4.rb:1)
|
||||
- Improve documentation
|
||||
(./test_project/subdir2/file5.rb:1)
|
||||
## Documentation Section
|
||||
- Documentation task
|
||||
(./test_project/subdir2/file5.rb:6)
|
||||
- Subtask X
|
||||
- Subtask Y
|
||||
## Title with version 1.0
|
|
@ -11,9 +11,9 @@ Gem::Specification.new do |spec|
|
|||
spec.summary = 'Standalone gem for generating TODO.md files'
|
||||
spec.description = "This standalone gem takes in source code files written in Ruby, and generates a TODO.md file from
|
||||
them.
|
||||
mark things to add to the TODO.md with the `# !!TODO!!` magic comment"
|
||||
mark things to add to the TODO.md with the # !!TODO!! magic comment"
|
||||
spec.homepage = 'https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Todo_Marker'
|
||||
spec.license = 'MIT'
|
||||
spec.license = 'GNU V3.0'
|
||||
spec.required_ruby_version = '>= 3.2'
|
||||
|
||||
spec.metadata['homepage_uri'] = spec.homepage
|
||||
|
|
Loading…
Reference in New Issue
Block a user