awestruct 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/awestruct/astruct_mixin.rb +1 -1
- data/lib/awestruct/cli/auto.rb +22 -1
- data/lib/awestruct/cli/deploy.rb +7 -4
- data/lib/awestruct/dependencies.rb +92 -3
- data/lib/awestruct/deploy/base_deploy.rb +25 -0
- data/lib/awestruct/deploy/github_pages_deploy.rb +8 -34
- data/lib/awestruct/deploy/rsync_deploy.rb +16 -5
- data/lib/awestruct/deploy/s3_deploy.rb +14 -0
- data/lib/awestruct/engine.rb +47 -6
- data/lib/awestruct/extensions/disqus.rb +1 -1
- data/lib/awestruct/extensions/minify.rb +4 -3
- data/lib/awestruct/extensions/posts.rb +56 -19
- data/lib/awestruct/extensions/remotePartial.rb +28 -4
- data/lib/awestruct/extensions/sitemap.rb +16 -12
- data/lib/awestruct/extensions/tag_cloud.html.haml +1 -1
- data/lib/awestruct/handler_chains.rb +4 -0
- data/lib/awestruct/handlers/base_handler.rb +3 -1
- data/lib/awestruct/handlers/file_handler.rb +1 -1
- data/lib/awestruct/handlers/interpolation_handler.rb +12 -1
- data/lib/awestruct/handlers/javascript_handler.rb +47 -0
- data/lib/awestruct/handlers/page_delegating_handler.rb +1 -0
- data/lib/awestruct/handlers/redirect_handler.rb +48 -0
- data/lib/awestruct/page.rb +24 -2
- data/lib/awestruct/page_loader.rb +1 -0
- data/lib/awestruct/version.rb +1 -1
- metadata +137 -37
data/lib/awestruct/cli/auto.rb
CHANGED
@@ -11,6 +11,9 @@ module Awestruct
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def run()
|
14
|
+
generate_thread = nil
|
15
|
+
current_path = nil
|
16
|
+
|
14
17
|
force_polling = ( RUBY_PLATFORM =~ /mingw/ ? true : false )
|
15
18
|
listener = Listen.to( @config.dir, :relative_paths=>true, :latency=>0.5, :force_polling=>force_polling )
|
16
19
|
listener.ignore( %r(\.awestruct) )
|
@@ -21,7 +24,25 @@ module Awestruct
|
|
21
24
|
engine = ::Awestruct::Engine.instance
|
22
25
|
unless ( path =~ %r(#{File.basename( engine.config.output_dir) }) || path =~ /.awestruct/ )
|
23
26
|
begin
|
24
|
-
|
27
|
+
if path.eql? current_path
|
28
|
+
unless generate_thread.nil?
|
29
|
+
puts "Same path triggered, stopping previous generation" if generate_thread.alive?
|
30
|
+
generate_thread.kill
|
31
|
+
end
|
32
|
+
else
|
33
|
+
generate_thread.join unless generate_thread.nil?
|
34
|
+
current_path = path
|
35
|
+
end
|
36
|
+
|
37
|
+
generate_thread = Thread.new {
|
38
|
+
begin
|
39
|
+
engine.generate_page_by_output_path( path )
|
40
|
+
puts "Generating.... done!"
|
41
|
+
rescue => e
|
42
|
+
puts e
|
43
|
+
puts e.backtrace
|
44
|
+
end
|
45
|
+
}
|
25
46
|
rescue => e
|
26
47
|
puts e
|
27
48
|
puts e.backtrace
|
data/lib/awestruct/cli/deploy.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'awestruct/deploy/s3_deploy'
|
1
2
|
require 'awestruct/deploy/rsync_deploy'
|
2
3
|
require 'awestruct/deploy/github_pages_deploy'
|
3
4
|
|
@@ -12,18 +13,20 @@ module Awestruct
|
|
12
13
|
def initialize(site_config, deploy_config)
|
13
14
|
@site_config = site_config
|
14
15
|
@deploy_config = deploy_config
|
15
|
-
deploy_config[
|
16
|
+
@deploy_config['type'] ||= (is_github? ? :github_pages : :rsync)
|
17
|
+
puts "Deploying to #{deploy_type}"
|
16
18
|
end
|
17
19
|
|
18
20
|
def deploy_type
|
19
|
-
deploy_config[
|
21
|
+
deploy_config['type']
|
20
22
|
end
|
21
23
|
|
22
24
|
def run()
|
23
|
-
deployer_class = Awestruct::Deployers.instance[ deploy_type ]
|
25
|
+
deployer_class = Awestruct::Deployers.instance[ deploy_type.to_sym ]
|
24
26
|
|
25
27
|
if ( deployer_class.nil? )
|
26
28
|
$stderr.puts "Unable to locate correct deployer for #{deploy_type}"
|
29
|
+
$stderr.puts "Deployers available for #{::Awestruct::Deployers.instance.collect {|k,v| "#{v} (#{k})"}.join(', ')}"
|
27
30
|
return
|
28
31
|
end
|
29
32
|
|
@@ -33,7 +36,7 @@ module Awestruct
|
|
33
36
|
|
34
37
|
private
|
35
38
|
def is_github?
|
36
|
-
deploy_config[
|
39
|
+
deploy_config['host'].to_s == 'github_pages' || deploy_config['host'].to_s == 'github_pages'
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -4,15 +4,30 @@ module Awestruct
|
|
4
4
|
|
5
5
|
attr_reader :page
|
6
6
|
attr_reader :dependencies
|
7
|
+
attr_reader :key_dependencies
|
7
8
|
attr_reader :dependents
|
9
|
+
attr_reader :key_dependents
|
10
|
+
attr_reader :content_hash
|
11
|
+
attr_reader :key_hash
|
12
|
+
attr_reader :has_changed_content
|
13
|
+
attr_reader :has_changed_keys
|
8
14
|
|
9
15
|
|
16
|
+
def self.track_dependencies=(bol)
|
17
|
+
@track_dependencies = bol
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.should_track_dependencies
|
21
|
+
@track_dependencies
|
22
|
+
end
|
23
|
+
|
10
24
|
def self.top_page
|
11
25
|
@pages ||= []
|
12
26
|
@pages.first
|
13
27
|
end
|
14
28
|
|
15
29
|
def self.push_page(page)
|
30
|
+
#puts "push #{page.output_path}"
|
16
31
|
if ( top_page.nil? )
|
17
32
|
page.dependencies.clear
|
18
33
|
else
|
@@ -23,6 +38,7 @@ module Awestruct
|
|
23
38
|
|
24
39
|
def self.pop_page
|
25
40
|
page = @pages.pop
|
41
|
+
#puts "pop #{page.output_path} #{@pages.empty?}"
|
26
42
|
if ( @pages.empty? && ! page.nil? )
|
27
43
|
page.dependencies.persist!
|
28
44
|
end
|
@@ -32,13 +48,58 @@ module Awestruct
|
|
32
48
|
def self.track_dependency(dep)
|
33
49
|
return if top_page.nil?
|
34
50
|
return if top_page == dep
|
51
|
+
#puts "dep #{top_page.relative_source_path} - #{dep.relative_source_path}"
|
35
52
|
top_page.dependencies.add_dependency(dep)
|
36
53
|
end
|
37
54
|
|
55
|
+
def self.track_key_dependency(dep, key)
|
56
|
+
return if !Awestruct::Dependencies.should_track_dependencies
|
57
|
+
return if top_page.nil?
|
58
|
+
return if top_page == dep
|
59
|
+
#puts "dep key #{top_page.relative_source_path} - #{dep.relative_source_path} -> #{key}"
|
60
|
+
#puts Kernel.caller(4)[0]
|
61
|
+
top_page.dependencies.add_key_dependency(dep)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
38
65
|
def initialize(page)
|
39
66
|
@page = page
|
40
67
|
@dependencies = Set.new
|
68
|
+
@key_dependencies = Set.new
|
41
69
|
@dependents = Set.new
|
70
|
+
@key_dependents = Set.new
|
71
|
+
@content_hash = nil
|
72
|
+
@key_hash = nil
|
73
|
+
@has_changed_content = false
|
74
|
+
@has_changed_keys = false
|
75
|
+
end
|
76
|
+
|
77
|
+
def key_hash=(key)
|
78
|
+
#puts "key_hash #{key}"
|
79
|
+
if @key_hash.nil?
|
80
|
+
@has_changed_keys = false
|
81
|
+
else
|
82
|
+
if key.eql? @key_hash
|
83
|
+
@has_changed_keys = false
|
84
|
+
else
|
85
|
+
@has_changed_keys = true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
@key_hash = key
|
89
|
+
end
|
90
|
+
|
91
|
+
def content_hash=(key)
|
92
|
+
#puts "content_hash #{key}"
|
93
|
+
if @content_hash.nil?
|
94
|
+
@has_changed_content = false
|
95
|
+
else
|
96
|
+
if key.eql? @content_hash
|
97
|
+
@has_changed_content = false
|
98
|
+
else
|
99
|
+
@has_changed_content = true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
@content_hash = key
|
42
103
|
end
|
43
104
|
|
44
105
|
def <<(dep)
|
@@ -53,10 +114,22 @@ module Awestruct
|
|
53
114
|
dep.dependencies.add_dependent( page )
|
54
115
|
end
|
55
116
|
|
117
|
+
def add_key_dependency(dep)
|
118
|
+
return if @page.do_not_track_dependencies
|
119
|
+
return if @page.output_path.nil?
|
120
|
+
return if dep == @page
|
121
|
+
@key_dependencies << dep
|
122
|
+
dep.dependencies.add_key_dependent( page )
|
123
|
+
end
|
124
|
+
|
56
125
|
def add_dependent(dep)
|
57
126
|
@dependents << dep
|
58
127
|
end
|
59
128
|
|
129
|
+
def add_key_dependent(dep)
|
130
|
+
@key_dependents << dep
|
131
|
+
end
|
132
|
+
|
60
133
|
def remove_dependent(dep)
|
61
134
|
@dependents.delete( dep )
|
62
135
|
end
|
@@ -69,10 +142,16 @@ module Awestruct
|
|
69
142
|
def persist!
|
70
143
|
return if page.output_path.nil? || page.output_path == ''
|
71
144
|
file = File.join( @page.site.config.dir, '.awestruct', 'dependency-cache', page.output_path )
|
145
|
+
#puts "store #{file}"
|
72
146
|
FileUtils.mkdir_p( File.dirname( file ) )
|
73
147
|
File.open( file, 'w' ) do |file|
|
148
|
+
file.puts "ch:#{@content_hash}"
|
149
|
+
file.puts "kh:#{@key_hash}"
|
74
150
|
@dependencies.collect{|e| e.relative_source_path }.uniq.each do |d|
|
75
|
-
file.puts d unless d.nil?
|
151
|
+
file.puts "c:#{d}" unless d.nil?
|
152
|
+
end
|
153
|
+
@key_dependencies.collect{|e| e.relative_source_path }.uniq.each do |d|
|
154
|
+
file.puts "k:#{d}" unless d.nil?
|
76
155
|
end
|
77
156
|
end
|
78
157
|
end
|
@@ -84,8 +163,18 @@ module Awestruct
|
|
84
163
|
if ( File.exist?( file ) )
|
85
164
|
File.open( file, 'r' ) do |file|
|
86
165
|
file.lines.each do |line|
|
87
|
-
|
88
|
-
|
166
|
+
type, path = line.split(':')
|
167
|
+
path.strip!
|
168
|
+
if type.eql? 'c' or type.eql? 'k'
|
169
|
+
d = find_page_by_path( path.strip )
|
170
|
+
unless d.nil?
|
171
|
+
add_dependency( d ) if 'c'.eql? type
|
172
|
+
add_key_dependency( d ) if 'k'.eql? type
|
173
|
+
end
|
174
|
+
else
|
175
|
+
self.content_hash = path if 'ch'.eql? type
|
176
|
+
self.key_hash = path if 'kh'.eql? type
|
177
|
+
end
|
89
178
|
end
|
90
179
|
end
|
91
180
|
return true
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'awestruct/deployers'
|
2
|
+
require 'git'
|
3
|
+
|
4
|
+
module Awestruct
|
5
|
+
module Deploy
|
6
|
+
class Base
|
7
|
+
UNCOMMITTED_CHANGES = "You have uncommitted changes in the working branch. Please commit or stash them."
|
8
|
+
def run
|
9
|
+
git.status.changed.empty? ? publish_site : existing_changes
|
10
|
+
end
|
11
|
+
|
12
|
+
def git
|
13
|
+
@git ||= ::Git.open('.')
|
14
|
+
end
|
15
|
+
|
16
|
+
def publish_site
|
17
|
+
$stderr.puts( "#{self.class.name}#publish_site not implemented." )
|
18
|
+
end
|
19
|
+
|
20
|
+
def existing_changes
|
21
|
+
$stderr.puts UNCOMMITTED_CHANGES
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,35 +1,23 @@
|
|
1
|
-
require 'awestruct/
|
2
|
-
require 'git'
|
1
|
+
require 'awestruct/deploy/base_deploy'
|
3
2
|
|
4
3
|
module Awestruct
|
5
4
|
module Deploy
|
6
|
-
|
7
|
-
class GitHubPagesDeploy
|
5
|
+
class GitHubPagesDeploy < Base
|
8
6
|
def initialize( site_config, deploy_config )
|
9
7
|
@site_path = site_config.output_dir
|
10
8
|
@branch = deploy_config[ 'branch' ] || 'gh-pages'
|
11
|
-
|
12
|
-
|
13
|
-
def run
|
14
|
-
git.status.changed.empty? ? publish_site : message_for(:existing_changes)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
def git
|
19
|
-
@git ||= ::Git.open('.')
|
9
|
+
@repo = deploy_config[ 'repository' ] || 'origin'
|
20
10
|
end
|
21
11
|
|
22
12
|
def publish_site
|
23
|
-
current_branch = git.
|
24
|
-
checkout_pages_branch
|
25
|
-
add_and_commit_site @site_path
|
26
|
-
push_and_restore current_branch
|
27
|
-
end
|
28
|
-
|
29
|
-
def checkout_pages_branch
|
13
|
+
current_branch = git.current_branch
|
30
14
|
git.branch( @branch ).checkout
|
15
|
+
add_and_commit_site @site_path
|
16
|
+
git.push( @repo, @branch )
|
17
|
+
git.checkout( current_branch )
|
31
18
|
end
|
32
19
|
|
20
|
+
private
|
33
21
|
def add_and_commit_site( path )
|
34
22
|
git.with_working( path ) do
|
35
23
|
git.add(".")
|
@@ -39,21 +27,7 @@ module Awestruct
|
|
39
27
|
$stderr.puts "Can't commit. #{e}."
|
40
28
|
end
|
41
29
|
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def push_and_restore( original_branch )
|
45
30
|
git.reset_hard
|
46
|
-
git.push( 'origin', @branch )
|
47
|
-
git.checkout( original_branch )
|
48
|
-
end
|
49
|
-
|
50
|
-
def message_for( key )
|
51
|
-
$stderr.puts case key
|
52
|
-
when :existing_changes
|
53
|
-
"You have uncommitted changes in the working branch. Please commit or stash them."
|
54
|
-
else
|
55
|
-
"An error occured."
|
56
|
-
end
|
57
31
|
end
|
58
32
|
end
|
59
33
|
end
|
@@ -1,19 +1,30 @@
|
|
1
|
-
require 'awestruct/
|
2
|
-
|
1
|
+
require 'awestruct/deploy/base_deploy'
|
2
|
+
require 'shellwords'
|
3
3
|
require 'open3'
|
4
4
|
|
5
5
|
module Awestruct
|
6
6
|
module Deploy
|
7
|
-
class RSyncDeploy
|
7
|
+
class RSyncDeploy < Base
|
8
8
|
|
9
9
|
def initialize(site_config, deploy_config)
|
10
10
|
@site_path = File.join( site_config.output_dir, '/' ).gsub(/^\w:\//, '/')
|
11
11
|
@host = deploy_config['host']
|
12
12
|
@path = File.join( deploy_config['path'], '/' )
|
13
|
+
@exclude = deploy_config['exclude']
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
16
|
+
def publish_site
|
17
|
+
exclude_option = ""
|
18
|
+
if ! (@exclude.nil? or @exclude.empty?)
|
19
|
+
exclude_option = "--exclude=#{@exclude}"
|
20
|
+
end
|
21
|
+
cmd = "rsync -r -l -i --no-p --no-g --chmod=Dg+sx,ug+rw --delete #{exclude_option} #{@site_path} #{@host}:#{@path}"
|
22
|
+
|
23
|
+
# Shellwords mangles windows rsync command so we need to skip shell words
|
24
|
+
if(RUBY_PLATFORM !~ /mingw/)
|
25
|
+
cmd = Shellwords.escape(cmd)
|
26
|
+
end
|
27
|
+
|
17
28
|
Open3.popen3( cmd ) do |stdin, stdout, stderr|
|
18
29
|
stdin.close
|
19
30
|
threads = []
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'awestruct/deploy/base_deploy'
|
2
|
+
|
3
|
+
module Awestruct
|
4
|
+
module Deploy
|
5
|
+
class S3Deploy < Base
|
6
|
+
def initialize( site_config, deploy_config )
|
7
|
+
@site_path = site_config.output_dir
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Awestruct::Deployers.instance[ :s3 ] = Awestruct::Deploy::S3Deploy
|
14
|
+
|
data/lib/awestruct/engine.rb
CHANGED
@@ -198,6 +198,11 @@ module Awestruct
|
|
198
198
|
Compass.configuration.css_dir = site.css_dir
|
199
199
|
Compass.configuration.javascripts_dir = 'javascripts'
|
200
200
|
Compass.configuration.images_dir = 'images'
|
201
|
+
Compass.configuration.line_comments = include_line_comments?
|
202
|
+
end
|
203
|
+
|
204
|
+
def include_line_comments?
|
205
|
+
site.key?(:compass_line_comments) ? !!site.compass_line_comments : !site.profile.eql?('production')
|
201
206
|
end
|
202
207
|
|
203
208
|
def load_pages
|
@@ -243,20 +248,56 @@ module Awestruct
|
|
243
248
|
page = site.pages.find{|p| p.relative_source_path.to_s==full_path} || site.layouts.find{|p| p.relative_source_path.to_s==full_path}
|
244
249
|
return if page.nil?
|
245
250
|
|
246
|
-
|
247
|
-
|
251
|
+
if !page.output_path.nil?
|
252
|
+
generate_page_internal(page)
|
253
|
+
end
|
254
|
+
|
255
|
+
pages = [] << page
|
256
|
+
|
257
|
+
pages.each{|page|
|
258
|
+
puts "--------------------"
|
259
|
+
puts "Page: #{page.output_path} #{page.relative_source_path} #{page.__is_layout ? 'Layout':''}"
|
260
|
+
puts "Detected change in content (#{page.dependencies.content_hash})" if page.dependencies.has_changed_content
|
261
|
+
puts "!! Detected change in front matter. To fully reflect the change you'll need to restart Awestruct (#{page.dependencies.key_hash})" if page.dependencies.has_changed_keys
|
262
|
+
puts "No changes detected" unless page.dependencies.has_changed_content or page.dependencies.has_changed_keys
|
263
|
+
puts "Dependencies Matrix: (non unique source path)"
|
264
|
+
puts "\t Outgoing dependencies:"
|
265
|
+
puts "\t\t Content -> #{page.dependencies.dependencies.size}"
|
266
|
+
puts "\t\t Key -> #{page.dependencies.key_dependencies.size}"
|
267
|
+
puts "\t Incoming dependencies:"
|
268
|
+
puts "\t\t Content <- #{page.dependencies.dependents.size}"
|
269
|
+
puts "\t\t Key <- #{page.dependencies.key_dependents.size}"
|
270
|
+
puts "--------------------"
|
271
|
+
}
|
248
272
|
|
249
273
|
regen_pages = Set.new
|
250
|
-
|
251
|
-
|
274
|
+
if page.dependencies.has_changed_content or page.__is_layout
|
275
|
+
regen_pages += page.dependencies.dependents
|
276
|
+
end
|
277
|
+
regen_pages = regen_pages.sort do |x, y|
|
278
|
+
xf = "#{@site.dir}#{x.relative_source_path}"
|
279
|
+
yf = "#{@site.dir}#{y.relative_source_path}"
|
280
|
+
xt = 0
|
281
|
+
yt = 0
|
282
|
+
xt = File.mtime(xf).to_i if File.exist? xf
|
283
|
+
yt = File.mtime(yf).to_i if File.exist? yf
|
284
|
+
|
285
|
+
yt <=> xt
|
286
|
+
end
|
287
|
+
|
288
|
+
puts "Starting regeneration of content dependent pages:" if regen_pages.size > 0
|
289
|
+
regen_pages.each{|x| puts x.output_path}
|
252
290
|
|
253
|
-
#puts regen_pages.collect{|e|e.output_path}.inspect
|
254
291
|
regen_pages.each do |p|
|
292
|
+
generate_page_internal(p)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def generate_page_internal(p)
|
255
297
|
unless ( p.output_path.nil? || p.__is_layout )
|
256
298
|
generated_path = File.join( site.config.output_dir, p.output_path )
|
257
299
|
generate_page( p, generated_path )
|
258
300
|
end
|
259
|
-
end
|
260
301
|
end
|
261
302
|
|
262
303
|
####
|