Sha256: 8108f3eed33947bcc370aa2b2a47e46ed40e8dcf98a98f49ab17d1714587276f

Contents?: true

Size: 1.51 KB

Versions: 13

Compression:

Stored size: 1.51 KB

Contents

LEXT = ".lt3"

def newer?(f1, f2)
  File.mtime(f1) > File.mtime(f2)
end

def stale?(src, dst, deps, force = false)
  meh = File.new("/tmp/dammit-#{src.gsub(/\//, "-")}", "w")
  log!(enter: __method__, args: [src, dst], level: 3)
  raise "Source #{src} not found in #{Dir.pwd}" unless File.exist?(src)
  return true if force
  return true unless File.exist?(dst)
  return true if newer?(src, dst)
  deps.each {|dep| return true if newer?(dep, dst) }
  return false
end

def xlate(cwd: Dir.pwd, src:, 
          dst: (strip = true; File.basename(src).sub(/.lt3$/,"")), 
          deps: [], copy: nil, debug: false, force: false)
  src += LEXT unless src.end_with?(LEXT)
  dst += ".html" unless (dst.end_with?(".html"))   # || strip)
  indent = " "*12
  Dir.chdir(cwd) do
    if debug
      puts "#{indent} -- xlate #{src} >#{dst}"
      puts "#{indent}      in:   #{Dir.pwd}"
      puts "#{indent}      from: #{caller[0]}"
      puts "#{indent}      copy: #{copy}" if copy
    end
    stale = stale?(src, dst, deps, force)
    if stale
      rc = system("livetext #{src} >#{dst}")
      puts "...completed (shell returned #{rc})" if debug
      system!("cp #{dst} #{copy}") if copy
    else
      puts "#{indent} -- ^ Already up to date!" if debug
      return
    end
  end
end

def xlate!(cwd: Dir.pwd, src:, copy: nil, debug: false, force: false)
  output = "/tmp/xlate-#{File.basename(src).sub(/.lt3$/, "")}"
  xlate cwd: cwd, src: src, dst: output, debug: debug, force: force
  File.read(output + ".html")  # return all content as string
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
runeblog-0.2.66 lib/xlate.rb
runeblog-0.2.65 lib/xlate.rb
runeblog-0.2.64 lib/xlate.rb
runeblog-0.2.63 lib/xlate.rb
runeblog-0.2.62 lib/xlate.rb
runeblog-0.2.61 lib/xlate.rb
runeblog-0.2.60 lib/xlate.rb
runeblog-0.2.59 lib/xlate.rb
runeblog-0.2.58 lib/xlate.rb
runeblog-0.2.57 lib/xlate.rb
runeblog-0.2.56 lib/xlate.rb
runeblog-0.2.55 lib/xlate.rb
runeblog-0.2.54 lib/xlate.rb