lib/howzit/buildnote.rb in howzit-2.0.8 vs lib/howzit/buildnote.rb in howzit-2.0.9
- old
+ new
@@ -8,11 +8,11 @@
attr_reader :metadata, :title
def initialize(file: nil, args: [])
@topics = []
create_note if note_file.nil?
- @metadata = IO.read(note_file).split(/^#/)[0].strip.get_metadata
+ @metadata = Util.read_file(note_file).split(/^#/)[0].strip.get_metadata
read_help(file)
end
def inspect
@@ -87,11 +87,11 @@
end
# Create a buildnotes skeleton
def create_note
trap('SIGINT') do
- Howzit.console.info "\nCanceled"
+ Howzit.console.info "\nCancelled"
exit!
end
default = !$stdout.isatty || Howzit.options[:default]
# First make sure there isn't already a buildnotes file
if note_file
@@ -208,23 +208,25 @@
Dir.chdir(home)
buildnotes.reverse
end
- def is_build_notes(filename)
- return false if filename.downcase !~ /(^howzit[^.]*|build[^.]+)/
+ def build_note?(filename)
+ return false if filename.downcase !~ /^(howzit[^.]*|build[^.]+)/
+
return false if Howzit.config.should_ignore(filename)
+
true
end
def glob_note
filename = nil
# Check for a build note file in the current folder. Filename must start
# with "build" and have an extension of txt, md, or markdown.
Dir.glob('*.{txt,md,markdown}').each do |f|
- if is_build_notes(f)
+ if build_note?(f)
filename = f
break
end
end
filename
@@ -260,11 +262,11 @@
end
topics_dict
end
def ensure_requirements(template)
- t_leader = IO.read(template).split(/^#/)[0].strip
+ t_leader = Util.read_file(template).split(/^#/)[0].strip
if t_leader.length > 0
t_meta = t_leader.get_metadata
if t_meta.key?('required')
required = t_meta['required'].strip.split(/\s*,\s*/)
required.each do |req|
@@ -328,11 +330,11 @@
def include_file(m)
file = File.expand_path(m[1])
return m[0] unless File.exist?(file)
- content = IO.read(file)
+ content = Util.read_file(file)
home = ENV['HOME']
short_path = File.dirname(file.sub(/^#{home}/, '~'))
prefix = "#{short_path}/#{File.basename(file)}:"
parts = content.split(/^##+/)
parts.shift
@@ -342,11 +344,11 @@
"## #{parts.join('## ')}".gsub(/^(##+ *)(?=\S)/, "\\1#{prefix}")
end
end
def note_title(truncate = 0)
- help = IO.read(note_file).strip
+ help = Util.read_file(note_file)
title = help.match(/(?:^(\S.*?)(?=\n==)|^# ?(.*?)$)/)
title = if title
title[1].nil? ? title[2] : title[1]
else
note_file.sub(/(\.\w+)?$/, '')
@@ -359,10 +361,10 @@
def read_help_file(path = nil)
topics = []
filename = path.nil? ? note_file : path
- help = IO.read(filename)
+ help = Util.read_file(filename)
@title = note_title
help.gsub!(/@include\((.*?)\)/) do
include_file(Regexp.last_match)