lib/bhook/md_file.rb in bhook-0.1.1 vs lib/bhook/md_file.rb in bhook-0.1.2

- old
+ new

@@ -6,33 +6,37 @@ extend T::Sig PAGE_TEMPLATE = T.let(File.read(Bhook::PAGE_TEMPLATE_PATH), String) AFTER_H1_TEMPLATE = T.let(File.read(Bhook::AFTER_H1_TEMPLATE_PATH), String) - sig { params(src_file_path: Pathname, git: Git::Base).void } - def initialize(src_file_path, git) + sig { returns(Pathname) } + attr_reader :src_file_path + + sig { params(src_file_path: Pathname, out_path: Pathname, git: Git::Base).void } + def initialize(src_file_path, out_path, git) + L.debug "Reading: #{src_file_path}" @md = T.let(File.read(src_file_path), String) - @src_file_path = T.let(src_file_path.expand_path, Pathname) - src_file_date, src_file_sha = git.lib.send(:command, 'log', - '-n 1', - '--pretty=format:%ad|%h', - '--date=short', - '--', + @src_file_path = src_file_path + @out_path = out_path + src_file_date, src_file_sha = git.lib.send(:command, 'log', + '-n 1', + '--pretty=format:%ad|%h', + '--date=short', + '--', @src_file_path).split('|') @src_file_date = T.let(src_file_date, T.nilable(String)) @src_file_sha = T.let(src_file_sha, T.nilable(String)) end - sig { returns(Pathname) } - attr_reader :src_file_path + sig { params(theme: Bhook::Theme).void } + def write!(theme) + out_file_name = @src_file_path.basename.sub(/\.md$/, '.html') + out_file_path = @out_path.join(out_file_name) - sig { params(out_path: String, theme: Bhook::Theme).void } - def write!(out_path, theme) - out_file_name = File.basename(@src_file_path).gsub(/\.md$/, '.html') - out_file_path = File.join(out_path, out_file_name) - puts "Processing: #{@src_file_sha} #{@src_file_path}" + L.debug "Processing: #{@src_file_sha || 'unversioned'} #{@src_file_path}" rendered_page = theme.render_page(@md, @src_file_sha, @src_file_date) - puts "Writing: #{@src_file_sha} #{out_file_path}" + + L.debug "Writing: #{@src_file_sha} #{out_file_path}" File.write(out_file_path, rendered_page) end sig { returns(String) } def to_s