0
@@ -4,59 +4,86 @@ module StaticMatic
0
def initialize(staticmatic)
0
@staticmatic = staticmatic
0
+ def determine_last_build
0
+ versions_file = @staticmatic.root_dir + "/builds"
0
+ if File.exists?(versions_file)
0
+ @last_build = File.read(versions_file).split(/\n/)[0]
0
+ timestamp = Time.now.strftime("%Y%m%d%H%M%S")
0
+ versions_file = @staticmatic.root_dir + "/builds"
0
+ if File.exists?(versions_file)
0
+ current_versions = File.read(versions_file)
0
+ File.open(versions_file, "w") do |file|
0
+ file.puts current_versions
0
+ File.open(versions_file, "w") do |file|
0
["pages", "stylesheets"].each do |template_path|
0
Dir["#{@staticmatic.src_dir}/#{template_path}/**/*"].each do |path|
0
if File.directory? path
0
if !File.exists? build_path_for(path)
0
- puts "Creating: #{build_path_for(path)}"
0
+ @staticmatic.logger.info("Creating: #{build_path_for(path)}")
0
FileUtils.mkdir(build_path_for(path))
0
format = @staticmatic.determine_format_for(path).to_s
0
- path = base_template_name_for(path)
0
+ base_template_name = base_template_name_for(path)
0
@staticmatic.template.template_format = format
0
- if should_overwrite?(path, format)
0
+ build_file_path = "#{build_path_for(path)}.#{format}"
0
+ if should_overwrite?(path, build_file_path)
0
- output = @staticmatic.render_with_layout(
path)
0
+ output = @staticmatic.render_with_layout(
base_template_name)
0
- output = @staticmatic.render(
path)
0
+ output = @staticmatic.render(
base_template_name)
0
output_prefix = "#{template_path}/" if template_path != "pages"
0
- save_built_file(
path, output, format)
0
+ save_built_file(
build_file_path, output)
0
- def should_overwrite?(path, format)
0
- build_file = "#{build_path_for(path)}.#{format}"
0
+ def should_overwrite?(template_file, build_file)
0
- path = @staticmatic.full_template_path(path)
0
if File.exists? build_file
0
- template_path = @staticmatic.template.full_template_path(path, @staticmatic.template.finder.pick_template_extension(path))
0
- #file_changed? template_path, build_file
0
+ file_changed? template_file
0
- def file_changed?(src_file, build_file)
0
- build_modification_time = File.stat(build_file).mtime.strftime("%Y%m%d%H%M%s")
0
- template_modification_time = File.stat(src_file).mtime.strftime("%Y%m%d%H%M%s")
0
- if template_modification_time > build_modification_time
0
+ def file_changed?(src_file)
0
+ template_modification_time = File.stat(src_file).mtime.strftime("%Y%m%d%H%M%S")
0
+ puts "#{template_modification_time.to_i} > #{@last_build.to_i}"
0
+ if template_modification_time.to_i > @last_build.to_i
0
@@ -65,9 +92,11 @@ module StaticMatic
0
# Strip off src file path and extension
0
def base_template_name_for(path)
0
- path.gsub!(/^\.\/src\//, '')
0
- path.gsub!(/^pages\//, '') if path.match(/^pages/)
0
- path.gsub(/\.[a-z]+$/, '')
0
+ path.gsub("#{@staticmatic.root_dir}/", "").
0
# Return an output filename
0
@@ -76,9 +105,9 @@ module StaticMatic
0
# Save contents to the specified file with the given extension to the build directory
0
- def save_built_file(path, contents, extension)
0
- path = "#{build_path_for(path)}.#{extension}"
0
- puts "Generating #{path}"
0
+ def save_built_file(path, contents)
0
+ @staticmatic.logger.info("Generating #{path}")
0
File.open(path, 'w+') do |f|
Comments
No one has commented yet.