awestruct 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/awestruct +11 -4
- data/lib/awestruct/commands/generate.rb +3 -3
- data/lib/awestruct/config.rb +10 -6
- data/lib/awestruct/engine.rb +13 -13
- data/lib/awestruct/extensions/atomizer.rb +2 -2
- data/lib/awestruct/extensions/collection.rb +52 -0
- data/lib/awestruct/extensions/disqus.rb +5 -3
- data/lib/awestruct/extensions/google_analytics.rb +19 -1
- data/lib/awestruct/extensions/posts.rb +2 -1
- data/lib/awestruct/renderable_file.rb +4 -0
- data/lib/awestruct/site.rb +8 -3
- metadata +4 -3
data/bin/awestruct
CHANGED
@@ -98,13 +98,20 @@ def site_path
|
|
98
98
|
end
|
99
99
|
|
100
100
|
options = parse(ARGV)
|
101
|
+
|
101
102
|
unless options.init
|
102
103
|
site_yaml_file = File.join( Dir.pwd, '_config', 'site.yml' )
|
103
104
|
site_yaml = YAML.load( File.read( site_yaml_file ) )
|
104
|
-
|
105
|
-
|
105
|
+
if site_yaml
|
106
|
+
@profiles_data = site_yaml['profiles'] || {}
|
107
|
+
@profile_data = @profiles_data.nil? ? nil : @profiles_data[options.profile]
|
108
|
+
end
|
106
109
|
end
|
107
110
|
|
111
|
+
config = Awestruct::Config.new(Dir.pwd)
|
112
|
+
# config.input_dir = File.join(Dir.pwd, '_root')
|
113
|
+
|
114
|
+
|
108
115
|
if ( options.init )
|
109
116
|
if ( options.generate || options.auto || options.server )
|
110
117
|
$stderr.puts "--init may not be used with --generate, --auto or --server"
|
@@ -178,13 +185,13 @@ if ( options.server )
|
|
178
185
|
end
|
179
186
|
|
180
187
|
if ( options.generate )
|
181
|
-
cmd = Awestruct::Commands::Generate.new(
|
188
|
+
cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url, options.force )
|
182
189
|
cmd.run
|
183
190
|
end
|
184
191
|
|
185
192
|
if ( options.auto )
|
186
193
|
threads << Thread.new {
|
187
|
-
generate_cmd = Awestruct::Commands::Generate.new(
|
194
|
+
generate_cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url )
|
188
195
|
while ( true )
|
189
196
|
generate_cmd.run
|
190
197
|
sleep(1)
|
@@ -4,13 +4,13 @@ module Awestruct
|
|
4
4
|
module Commands
|
5
5
|
class Generate
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@dir =
|
7
|
+
def initialize(config, profile=nil, base_url=nil, default_base_url='http://localhost:4242', force=false)
|
8
|
+
@dir = config.input_dir
|
9
9
|
@profile = profile
|
10
10
|
@base_url = base_url
|
11
11
|
@default_base_url = default_base_url
|
12
12
|
@force = force
|
13
|
-
@engine = Awestruct::Engine.new(
|
13
|
+
@engine = Awestruct::Engine.new( config )
|
14
14
|
end
|
15
15
|
|
16
16
|
def run()
|
data/lib/awestruct/config.rb
CHANGED
@@ -6,16 +6,20 @@ module Awestruct
|
|
6
6
|
attr_accessor :layouts_dir
|
7
7
|
attr_accessor :config_dir
|
8
8
|
attr_accessor :extension_dir
|
9
|
+
attr_accessor :input_dir
|
9
10
|
attr_accessor :output_dir
|
11
|
+
attr_accessor :tmp_dir
|
10
12
|
attr_accessor :skin_dir
|
11
13
|
attr_accessor :ignore
|
12
14
|
|
13
|
-
def initialize()
|
14
|
-
@layouts_dir = '_layouts'
|
15
|
-
@config_dir = '_config'
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
15
|
+
def initialize(dir)
|
16
|
+
@layouts_dir = File.join(dir, '_layouts')
|
17
|
+
@config_dir = File.join(dir, '_config')
|
18
|
+
@input_dir = File.join(dir, '')
|
19
|
+
@output_dir = File.join(dir, '_site')
|
20
|
+
@extension_dir = File.join(dir, '_ext')
|
21
|
+
@skin_dir = File.join(dir, '_skin')
|
22
|
+
@tmp_dir = File.join(dir, '_tmp')
|
19
23
|
@ignore = [ ]
|
20
24
|
end
|
21
25
|
|
data/lib/awestruct/engine.rb
CHANGED
@@ -22,6 +22,7 @@ require 'awestruct/context_helper'
|
|
22
22
|
|
23
23
|
require 'awestruct/extensions/pipeline'
|
24
24
|
require 'awestruct/extensions/posts'
|
25
|
+
require 'awestruct/extensions/collection'
|
25
26
|
require 'awestruct/extensions/indexifier'
|
26
27
|
require 'awestruct/extensions/data_dir'
|
27
28
|
require 'awestruct/extensions/paginator'
|
@@ -44,15 +45,14 @@ module Awestruct
|
|
44
45
|
attr_reader :dir
|
45
46
|
attr_reader :site
|
46
47
|
|
47
|
-
def initialize(
|
48
|
-
@dir =
|
48
|
+
def initialize(config)
|
49
|
+
@dir = config.input_dir
|
49
50
|
@config = config
|
50
|
-
|
51
|
+
|
52
|
+
@site = Site.new( config )
|
51
53
|
@site.engine = self
|
52
|
-
|
54
|
+
|
53
55
|
@helpers = []
|
54
|
-
FileUtils.mkdir_p( @site.tmp_dir )
|
55
|
-
FileUtils.mkdir_p( @site.output_dir )
|
56
56
|
@max_yaml_mtime = nil
|
57
57
|
end
|
58
58
|
|
@@ -76,7 +76,7 @@ module Awestruct
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def find_and_load_site_page(simple_path)
|
79
|
-
path_glob = File.join(
|
79
|
+
path_glob = File.join( config.input_dir, simple_path + '.*' )
|
80
80
|
candidates = Dir[ path_glob ]
|
81
81
|
return nil if candidates.empty?
|
82
82
|
throw Exception.new( "too many choices for #{simple_path}" ) if candidates.size != 1
|
@@ -194,7 +194,7 @@ module Awestruct
|
|
194
194
|
def generate_page(page, force)
|
195
195
|
return unless requires_generation?(page, force)
|
196
196
|
|
197
|
-
generated_path = File.join(
|
197
|
+
generated_path = File.join( config.output_dir, page.output_path )
|
198
198
|
$stderr.puts "rendering #{page.source_path} -> #{page.output_path}"
|
199
199
|
rendered = render_page(page, true)
|
200
200
|
FileUtils.mkdir_p( File.dirname( generated_path ) )
|
@@ -205,7 +205,7 @@ module Awestruct
|
|
205
205
|
|
206
206
|
def requires_generation?(page,force)
|
207
207
|
return true if force
|
208
|
-
generated_path = File.join(
|
208
|
+
generated_path = File.join( config.output_dir, page.output_path )
|
209
209
|
return true unless File.exist?( generated_path )
|
210
210
|
now = Time.now
|
211
211
|
generated_mtime = File.mtime( generated_path )
|
@@ -247,7 +247,7 @@ module Awestruct
|
|
247
247
|
def load_layouts
|
248
248
|
site.layouts.clear
|
249
249
|
dir_pathname = Pathname.new( dir )
|
250
|
-
Dir[ File.join(
|
250
|
+
Dir[ File.join( config.layouts_dir, '*.haml' ) ].each do |layout_path|
|
251
251
|
layout_pathname = Pathname.new( layout_path )
|
252
252
|
relative_path = layout_pathname.relative_path_from( dir_pathname ).to_s
|
253
253
|
name = File.basename( layout_path, '.haml' )
|
@@ -267,7 +267,7 @@ module Awestruct
|
|
267
267
|
end
|
268
268
|
|
269
269
|
def load_site_yaml(profile)
|
270
|
-
site_yaml = File.join(
|
270
|
+
site_yaml = File.join( config.config_dir, 'site.yml' )
|
271
271
|
if ( File.exist?( site_yaml ) )
|
272
272
|
mtime = File.mtime( site_yaml )
|
273
273
|
if ( mtime > ( @max_yaml_mtime || Time.at(0) ) )
|
@@ -290,7 +290,7 @@ module Awestruct
|
|
290
290
|
end
|
291
291
|
|
292
292
|
def load_yamls
|
293
|
-
Dir[ File.join(
|
293
|
+
Dir[ File.join( config.config_dir, '*.yml' ) ].each do |yaml_path|
|
294
294
|
load_yaml( yaml_path ) unless ( File.basename( yaml_path ) == 'site.yml' )
|
295
295
|
end
|
296
296
|
end
|
@@ -373,7 +373,7 @@ module Awestruct
|
|
373
373
|
pipeline = nil
|
374
374
|
skin_pipeline = nil
|
375
375
|
|
376
|
-
ext_dir = File.join(
|
376
|
+
ext_dir = File.join( config.extension_dir )
|
377
377
|
if ( $LOAD_PATH.index( ext_dir ).nil? )
|
378
378
|
$LOAD_PATH << ext_dir
|
379
379
|
end
|
@@ -8,9 +8,9 @@ module Awestruct
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def execute(site)
|
11
|
-
entries = site.send( @entries_name )
|
11
|
+
entries = site.send( @entries_name ) || []
|
12
12
|
unless ( @num_entries == :all )
|
13
|
-
entries = entries[0
|
13
|
+
entries = entries[0, @num_entries]
|
14
14
|
end
|
15
15
|
input_page = File.join( File.dirname(__FILE__), 'template.atom.haml' )
|
16
16
|
page = site.engine.load_page( input_page )
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module Awestruct
|
3
|
+
module Extensions
|
4
|
+
class Collection
|
5
|
+
|
6
|
+
def initialize(assign_to, path_prefix = nil, default_layout = nil)
|
7
|
+
@assign_to = assign_to
|
8
|
+
@path_prefix = path_prefix || '_' + assign_to.to_s
|
9
|
+
@default_layout = default_layout || assign_to.to_s.singularize
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(site)
|
13
|
+
posts = []
|
14
|
+
|
15
|
+
Dir[ "#{@path_prefix}/*" ].each do |entry|
|
16
|
+
if entry =~ /^#{@path_prefix}\/(20[01][0-9])-([01][0-9])-([0123][0-9])-([^.]+)\..*$/
|
17
|
+
if ( File.directory?( entry ) )
|
18
|
+
# TODO deal with dirs
|
19
|
+
else
|
20
|
+
page = site.engine.load_page( entry )
|
21
|
+
year = $1
|
22
|
+
month = $2
|
23
|
+
day = $3
|
24
|
+
slug = $4
|
25
|
+
page.date = Time.utc( year.to_i, month.to_i, day.to_i )
|
26
|
+
page.slug = slug
|
27
|
+
page.output_path = "/#{year}/#{month}/#{day}/#{slug}/index.html"
|
28
|
+
page.layout ||= @default_layout
|
29
|
+
|
30
|
+
posts << page
|
31
|
+
site.pages << page
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
posts = posts.sort_by{|each| [each.date, each.sequence || 0, File.mtime( each.source_path ), each.slug ] }.reverse
|
37
|
+
|
38
|
+
last = nil
|
39
|
+
singular = @assign_to.to_s.singularize
|
40
|
+
posts.each do |e|
|
41
|
+
if ( last != nil )
|
42
|
+
e.send( "next_#{singular}=", last )
|
43
|
+
last.send( "previous_#{singular}=", e )
|
44
|
+
end
|
45
|
+
last = e
|
46
|
+
end
|
47
|
+
|
48
|
+
site.send( "#{@assign_to}=", posts )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -3,15 +3,17 @@ module Awestruct
|
|
3
3
|
class Disqus
|
4
4
|
|
5
5
|
def execute(site)
|
6
|
-
site.pages.each{|p| p.extend Disqus }
|
6
|
+
site.pages.each{ |p| p.extend Disqus }
|
7
7
|
end
|
8
8
|
|
9
9
|
module Disqus
|
10
10
|
def disqus_comments()
|
11
|
+
developer = (site.disqus_developer) ? 'var disqus_developer = 1;' : ''
|
11
12
|
%Q{
|
12
13
|
<div id="disqus_thread"></div>
|
13
14
|
<script type="text/javascript">
|
14
15
|
var disqus_url = "#{self.url}";
|
16
|
+
#{developer}
|
15
17
|
(function() {
|
16
18
|
var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
|
17
19
|
dsq.src = "http://#{site.disqus}.disqus.com/embed.js";
|
@@ -26,10 +28,10 @@ module Awestruct
|
|
26
28
|
%Q{ <a href="#{self.url}#disqus_thread">Comments</a> }
|
27
29
|
end
|
28
30
|
|
29
|
-
def
|
31
|
+
def disqus_comments_count()
|
30
32
|
%Q{
|
31
33
|
<script type="text/javascript">
|
32
|
-
var
|
34
|
+
var disqus = "#{site.disqus}";
|
33
35
|
(function () {
|
34
36
|
var s = document.createElement('script'); s.async = true;
|
35
37
|
s.src = "http://disqus.com/forums/#{site.disqus}/count.js";
|
@@ -14,7 +14,25 @@ module Awestruct
|
|
14
14
|
html += %Q(var pageTracker = _gat._getTracker("#{site.google_analytics}");\n)
|
15
15
|
html += %Q(pageTracker._trackPageview();\n)
|
16
16
|
html += %Q(} catch(err) {}</script>\n)
|
17
|
-
html
|
17
|
+
html
|
18
|
+
end
|
19
|
+
|
20
|
+
def google_analytics_async()
|
21
|
+
html = ''
|
22
|
+
html += %Q(<script type="text/javascript">\n)
|
23
|
+
html += %Q(var _gaq = [['_setAccount','#{site.google_analytics}"'],)
|
24
|
+
if site.google_analytics_anonymize
|
25
|
+
html += %Q(['_gat._anonymizeIp'],)
|
26
|
+
end
|
27
|
+
html += %Q(['_trackPageview']];\n)
|
28
|
+
html += %Q[(function(d, t) {\n]
|
29
|
+
html += %Q( var g = d.createElement(t),\n)
|
30
|
+
html += %Q( s = d.getElementsByTagName(t)[0];\n)
|
31
|
+
html += %Q( g.async = true;\n)
|
32
|
+
html += %Q( g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n)
|
33
|
+
html += %Q( s.parentNode.insertBefore(g, s);\n)
|
34
|
+
html += %Q[})(document, 'script');\n]
|
35
|
+
html
|
18
36
|
end
|
19
37
|
end
|
20
38
|
end
|
@@ -10,7 +10,7 @@ module Awestruct
|
|
10
10
|
|
11
11
|
def execute(site)
|
12
12
|
posts = []
|
13
|
-
|
13
|
+
|
14
14
|
site.pages.each do |page|
|
15
15
|
if ( page.relative_source_path =~ /^#{@path_prefix}\/(20[01][0-9])-([01][0-9])-([0123][0-9])-([^.]+)\..*$/ )
|
16
16
|
year = $1
|
@@ -25,6 +25,7 @@ module Awestruct
|
|
25
25
|
})
|
26
26
|
#page.body = page.render( context )
|
27
27
|
page.output_path = "#{@path_prefix}/#{year}/#{month}/#{day}/#{slug}.html"
|
28
|
+
#page.layout = 'post'
|
28
29
|
posts << page
|
29
30
|
end
|
30
31
|
end
|
data/lib/awestruct/site.rb
CHANGED
@@ -9,11 +9,16 @@ module Awestruct
|
|
9
9
|
attr_reader :layouts
|
10
10
|
attr_accessor :pages
|
11
11
|
|
12
|
-
|
12
|
+
attr_accessor :config
|
13
|
+
|
14
|
+
def initialize(config)
|
13
15
|
super({})
|
14
16
|
|
15
|
-
@dir =
|
16
|
-
@output_dir =
|
17
|
+
@dir = config.input_dir
|
18
|
+
@output_dir = config.output_dir
|
19
|
+
@config = config
|
20
|
+
|
21
|
+
FileUtils.mkdir_p( @output_dir )
|
17
22
|
|
18
23
|
@pages = []
|
19
24
|
@layouts = {}
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awestruct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bob McWhirter
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- lib/awestruct/erb_file.rb
|
168
168
|
- lib/awestruct/erbable.rb
|
169
169
|
- lib/awestruct/extensions/atomizer.rb
|
170
|
+
- lib/awestruct/extensions/collection.rb
|
170
171
|
- lib/awestruct/extensions/data_dir.rb
|
171
172
|
- lib/awestruct/extensions/disqus.rb
|
172
173
|
- lib/awestruct/extensions/google_analytics.rb
|