Finished implementation of styles
This commit is contained in:
parent
f65d4f9132
commit
99b4b136c4
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -76,3 +76,4 @@ test_project/subdir1/file2.rb
|
||||||
test_project/subdir1/file3.rb
|
test_project/subdir1/file3.rb
|
||||||
test_project/subdir2/file4.rb
|
test_project/subdir2/file4.rb
|
||||||
test_project/subdir2/file5.rb
|
test_project/subdir2/file5.rb
|
||||||
|
test_project/TODO.md
|
||||||
|
|
|
@ -6,13 +6,10 @@ require 'find'
|
||||||
|
|
||||||
module TodoMarker
|
module TodoMarker
|
||||||
TODO_REGEX = /# !!TODO!!(?: style: (\w+))? "(.*?)"/
|
TODO_REGEX = /# !!TODO!!(?: style: (\w+))? "(.*?)"/
|
||||||
STYLE_REGEX = /`style: (\w+?)` (.*?)`/
|
|
||||||
STYLES = {
|
STYLES = {
|
||||||
'title' => '## %s',
|
'title' => '## %s',
|
||||||
'title1' => '# %s',
|
'title1' => '# %s',
|
||||||
'sublist' => ' - %s',
|
'sublist' => ' - %s'
|
||||||
'super-text' => '<sup>%s</sup>',
|
|
||||||
'sub-text' => '<sub>%s</sub>'
|
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def self.generate_todo_md(directory)
|
def self.generate_todo_md(directory)
|
||||||
|
@ -25,7 +22,6 @@ module TodoMarker
|
||||||
next unless line.match(TODO_REGEX)
|
next unless line.match(TODO_REGEX)
|
||||||
|
|
||||||
style, message = line.match(TODO_REGEX).captures
|
style, message = line.match(TODO_REGEX).captures
|
||||||
message = parse_styles(message)
|
|
||||||
todos << {
|
todos << {
|
||||||
style:,
|
style:,
|
||||||
message:,
|
message:,
|
||||||
|
@ -38,25 +34,13 @@ module TodoMarker
|
||||||
create_todo_file(directory, todos)
|
create_todo_file(directory, todos)
|
||||||
end
|
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)
|
def self.create_todo_file(directory, todos)
|
||||||
File.open(File.join(directory, 'TODO.md'), 'w') do |file|
|
File.open(File.join(directory, 'TODO.md'), 'w') do |file|
|
||||||
file.puts "# TODO List\n\n"
|
file.puts "# TODO List\n\n"
|
||||||
previous_style = nil
|
|
||||||
todos.each do |todo|
|
todos.each do |todo|
|
||||||
formatted_message = format_message(todo[:style], todo[:message])
|
formatted_message = format_message(todo[:style], todo[:message])
|
||||||
file.puts formatted_message
|
file.puts formatted_message
|
||||||
file.puts " (#{todo[:file]}:#{todo[:line]})" if todo[:style] != 'sublist' && todo[:style].nil?
|
file.puts " (#{todo[:file]}:#{todo[:line]})" if todo[:style].nil?
|
||||||
previous_style = todo[:style]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user