public
Clone URL: git://github.com/stevebartholomew/staticmatic.git
Added build tracking - only builds when templates have been altered, added 
license
Thu Jul 03 12:57:42 -0700 2008
commit  cc9dc9bbc95609cb4eb77bdf1b187d5bc3bd2b52
tree    ba9e5fe29f1d82ddd33a30ad4ecb1b5412aa1d97
parent  1ebd4d20e7b8a264cb62844420f112d9db9be4ca
...
4
5
6
7
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
12
13
 
14
15
16
 
 
17
18
19
20
21
22
 
 
23
24
 
 
 
25
26
 
27
28
 
29
30
31
32
 
33
34
35
36
37
38
39
40
41
42
 
43
44
45
46
47
48
49
50
 
51
52
53
54
55
56
57
58
59
 
 
 
 
60
61
62
...
65
66
67
68
69
70
 
 
 
 
 
71
72
73
...
76
77
78
79
80
81
 
 
 
82
83
84
...
4
5
6
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
47
48
49
50
51
52
53
 
54
55
56
 
57
58
59
60
 
61
62
 
63
64
65
66
 
67
68
69
70
71
72
73
 
 
 
 
74
75
 
 
76
 
 
 
 
77
78
79
80
81
82
 
 
 
 
83
84
85
86
87
88
89
...
92
93
94
 
 
 
95
96
97
98
99
100
101
102
...
105
106
107
 
 
 
108
109
110
111
112
113
0
@@ -4,59 +4,86 @@ module StaticMatic
0
     
0
     def initialize(staticmatic)
0
       @staticmatic = staticmatic
0
-
0
+ determine_last_build
0
       build_pages
0
+ log_version
0
+ end
0
+
0
+ def determine_last_build
0
+ versions_file = @staticmatic.root_dir + "/builds"
0
+
0
+ if File.exists?(versions_file)
0
+ @last_build = File.read(versions_file).split(/\n/)[0]
0
+ else
0
+ @last_build = ""
0
+ end
0
+ end
0
+
0
+ def log_version
0
+ timestamp = Time.now.strftime("%Y%m%d%H%M%S")
0
+ versions_file = @staticmatic.root_dir + "/builds"
0
+
0
+ if File.exists?(versions_file)
0
+ current_versions = File.read(versions_file)
0
+
0
+ File.open(versions_file, "w") do |file|
0
+ file.puts timestamp
0
+ file.puts current_versions
0
+ end
0
+ else
0
+ File.open(versions_file, "w") do |file|
0
+ file.puts timestamp
0
+ end
0
+ end
0
+
0
     end
0
     
0
     def build_pages
0
       ["pages", "stylesheets"].each do |template_path|
0
         Dir["#{@staticmatic.src_dir}/#{template_path}/**/*"].each do |path|
0
+
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
+
0
               FileUtils.mkdir(build_path_for(path))
0
             end
0
           else
0
 
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
+
0
             @staticmatic.template.template_format = format
0
- if should_overwrite?(path, format)
0
+ build_file_path = "#{build_path_for(path)}.#{format}"
0
+
0
+ if should_overwrite?(path, build_file_path)
0
               if format == "html"
0
- output = @staticmatic.render_with_layout(path)
0
+ output = @staticmatic.render_with_layout(base_template_name)
0
               else
0
- output = @staticmatic.render(path)
0
+ output = @staticmatic.render(base_template_name)
0
               end
0
                           
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
             end
0
           end
0
         end
0
       end
0
     end
0
     
0
- def should_overwrite?(path, format)
0
- return true
0
-
0
- build_file = "#{build_path_for(path)}.#{format}"
0
+ def should_overwrite?(template_file, build_file)
0
 
0
- path = @staticmatic.full_template_path(path)
0
-
0
       if File.exists? build_file
0
-
0
- template_path = @staticmatic.template.full_template_path(path, @staticmatic.template.finder.pick_template_extension(path))
0
- #file_changed? template_path, build_file
0
- true
0
+ file_changed? template_file
0
       else
0
         true
0
       end
0
     end
0
     
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
         true
0
       else
0
         false
0
@@ -65,9 +92,11 @@ module StaticMatic
0
     
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
+
0
+ path.gsub("#{@staticmatic.root_dir}/", "").
0
+ gsub(/^src\//, '').
0
+ gsub(/^pages\//, '').
0
+ gsub(/\.[a-z]+$/, '')
0
     end
0
     
0
     # Return an output filename
0
@@ -76,9 +105,9 @@ module StaticMatic
0
     end
0
     
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
+
0
+ @staticmatic.logger.info("Generating #{path}")
0
       File.open(path, 'w+') do |f|
0
         f << contents
0
       end
...
 
 
 
0
...
1
2
3
4
0
@@ -0,0 +1,3 @@
0
+require 'rake'
0
+require 'rubygems'
0
+require 'tasks/staticmatic'
0
\ No newline at end of file

Comments

    No one has commented yet.