lib/howzit/buildnote.rb in howzit-2.1.10 vs lib/howzit/buildnote.rb in howzit-2.1.12
- old
+ new
@@ -67,10 +67,11 @@
##
## @param term [String] The search term
##
def find_topic(term = nil)
return @topics if term.nil?
+
@topics.filter do |topic|
rx = term.to_rx
topic.title.downcase.sub(/ *\(.*?\) *$/, '') =~ rx
end
end
@@ -112,11 +113,11 @@
## Return an array of topic titles
##
## @return [Array] array of topic titles
##
def list_topics
- @topics.map { |topic| topic.title }
+ @topics.map(&:title)
end
##
## Return a list of topic titles suitable for shell completion
##
@@ -358,23 +359,25 @@
## @param template [String] The template to read
## from
##
def ensure_requirements(template)
t_leader = Util.read_file(template).split(/^#/)[0].strip
- if t_leader.length > 0
- t_meta = t_leader.get_metadata
+ return unless t_leader.length.positive?
- if t_meta.key?('required')
- required = t_meta['required'].strip.split(/\s*,\s*/)
- required.each do |req|
- unless @metadata.keys.include?(req.downcase)
- Howzit.console.error %({bRw}ERROR:{xbr} Missing required metadata key from template '{bw}#{File.basename(template, '.md')}{xr}'{x}).c
- Howzit.console.error %({br}Please define {by}#{req.downcase}{xr} in build notes{x}).c
- Process.exit 1
- end
- end
- end
+ t_meta = t_leader.get_metadata
+
+ return unless t_meta.key?('required')
+
+ required = t_meta['required'].strip.split(/\s*,\s*/)
+ required.each do |req|
+ next if @metadata.keys.include?(req.downcase)
+
+ Howzit.console.error %({bRw}ERROR:{xbr} Missing required metadata key from template '{bw}#{File.basename(
+ template, '.md'
+ )}{xr}'{x}).c
+ Howzit.console.error %({br}Please define {by}#{req.downcase}{xr} in build notes{x}).c
+ Process.exit 1
end
end
##
## Test a template string for bracketed subtopics
@@ -386,11 +389,11 @@
##
def detect_subtopics(template)
subtopics = nil
if template =~ /\[(.*?)\]$/
- subtopics = Regexp.last_match[1].split(/\s*\|\s*/).map { |t| t.gsub(/\*/, '.*?')}
+ subtopics = Regexp.last_match[1].split(/\s*\|\s*/).map { |t| t.gsub(/\*/, '.*?') }
template.sub!(/\[.*?\]$/, '').strip
end
[template, subtopics]
end
@@ -638,15 +641,14 @@
@topics.push(topic) unless find_topic(topic.title.sub(/^.+:/, '')).count.positive?
end
Howzit.has_read_upstream = true
end
- if note_file && @topics.empty?
- Howzit.console.error("{br}Note file found but no topics detected in #{note_file}{x}".c)
- Process.exit 1
- end
+ return unless note_file && @topics.empty?
+ Howzit.console.error("{br}Note file found but no topics detected in #{note_file}{x}".c)
+ Process.exit 1
end
##
## Open build note in editor
##
@@ -702,11 +704,11 @@
new_topic.run
else
new_topic.print_out({ single: single })
end
- output.nil? ? '' : output.join("\n")
+ output.nil? ? '' : output.join("\n\n")
end
##
## Search and process the build note
##
@@ -780,10 +782,10 @@
when :best
topic_matches.push(matches.sort.min_by { |t| t.title.length })
when :all
topic_matches.concat(matches)
else
- titles = matches.map { |topic| topic.title }
+ titles = matches.map(&:title)
res = Prompt.choose(titles)
old_matching = Howzit.options[:matching]
Howzit.options[:matching] = 'exact'
res.each { |title| topic_matches.concat(find_topic(title)) }
Howzit.options[:matching] = old_matching