diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-07 00:52:49 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-07 00:52:49 -0500 |
commit | add2ce8c856d99a2f4cc0bbd4f630cc9aeb2ef05 (patch) | |
tree | c406a4dd5bd111cd2a47b077d8c552c8ad65bf05 /lib | |
parent | 3d989e2caf683d8300ae4e8191b81fd6fe0c0948 (diff) |
more
Diffstat (limited to 'lib')
-rw-r--r-- | lib/.gitignore | 1 | ||||
-rw-r--r-- | lib/sitegen.rb | 54 |
2 files changed, 46 insertions, 9 deletions
diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index e8db6e5..0000000 --- a/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/page.rb.txt
\ No newline at end of file diff --git a/lib/sitegen.rb b/lib/sitegen.rb index f565d20..c687375 100644 --- a/lib/sitegen.rb +++ b/lib/sitegen.rb @@ -1,27 +1,65 @@ # coding: utf-8 +require 'date' require 'set' module Sitegen def self.init - @set = Set[] @mk = {} + @want = Set[] end def self.add(page) - @set.add(page) + @deps = nil + page.local_depends.keys.each do |filename| + @mk[filename] = page unless filename.empty? + end end def self.pages - @set + @mk.values.to_set end def self.want(filename) - page = pages.select{|page|page.local_depends.keys.include?(filename)}.first - @mk[filename] = page + @deps = nil + @want.add(filename) + end + def self.dependencies + if @deps.nil? + libfiles = Dir::entries('lib').select{|s|s!='..'}.map{|s|"lib/#{s}"}.to_set + ret = {} + ret[:all] = @want + @want.each do |filename| + ret[filename] = libfiles.clone.merge(@mk[filename].local_depends[filename]) + end + @deps = ret + end + @deps end def self.Makefile() str = '' - str += "all: #{@mk.keys.sort.join(' ')}\n" - @mk.each do |filename, page| - str += "#{filename}: #{page.local_depends[filename].sort.join(' ')}\n" + dependencies.each do |target, deps| + str += "#{target.to_s}: #{deps.sort.join(' ')}\n" end return str end + + def self.make(target) + newest = DateTime::new(0) + (dependencies[target] || []).each do |dep| + ts = dep.make(dep) + newest = ts if ts > newest + end + unless target.is_a?(String) + return DateTime::now + end + if File::exist?(target) + ctime = File::ctime(target) + if ctime > newest + return ctime + end + end + generate(target) + return File::ctime(target) + end + + def self.generate(target) + # TODO + end end |