awestruct 0.2.7 → 0.2.8

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 CHANGED
@@ -216,6 +216,14 @@ if ( options.auto )
216
216
  puts "Triggered regeneration #{base} #{relative}"
217
217
  generate_cmd.run
218
218
  puts "Done"
219
+ if relative == '.'
220
+ # It's necessary to restart the monitor on individual files
221
+ # after a change is handled
222
+ monitor.file(base) do
223
+ update &call_generate
224
+ create &call_generate
225
+ end
226
+ end
219
227
  end
220
228
  end
221
229
 
@@ -1,3 +1,4 @@
1
+ !!!
1
2
  %html
2
3
  %head
3
4
  %title
@@ -1,3 +1,4 @@
1
+ !!!
1
2
  %html
2
3
  %head
3
4
  %title
@@ -1,4 +1,3 @@
1
-
2
1
  require 'ostruct'
3
2
  require 'find'
4
3
  require 'compass'
@@ -54,6 +53,7 @@ module Awestruct
54
53
 
55
54
  @helpers = []
56
55
  @max_site_mtime = nil
56
+ adjust_load_path
57
57
  end
58
58
 
59
59
  def skin_dir
@@ -148,7 +148,7 @@ module Awestruct
148
148
  context
149
149
  end
150
150
 
151
- def set_urls(pages)
151
+ def set_urls(pages)
152
152
  pages.each do |page|
153
153
  page_path = page.output_path
154
154
  if ( page_path =~ /^\// )
@@ -164,6 +164,19 @@ module Awestruct
164
164
 
165
165
  private
166
166
 
167
+ def adjust_load_path
168
+ ext_dir = File.join( config.extension_dir )
169
+ if ( $LOAD_PATH.index( ext_dir ).nil? )
170
+ $LOAD_PATH << ext_dir
171
+ end
172
+ if ( skin_dir )
173
+ skin_ext_dir = File.join( skin_dir, config.extension_dir )
174
+ if ( $LOAD_PATH.index( skin_ext_dir ).nil? )
175
+ $LOAD_PATH << skin_ext_dir
176
+ end
177
+ end
178
+ end
179
+
167
180
  def configure_compass
168
181
  Compass.configuration.project_type = :standalone
169
182
  Compass.configuration.project_path = dir
@@ -214,8 +227,20 @@ module Awestruct
214
227
  now = Time.now
215
228
  generated_mtime = File.mtime( generated_path )
216
229
  return true if ( ( @max_site_mtime || Time.at(0) ) > generated_mtime )
217
- source_mtime = File.mtime( page.source_path )
218
- return true if ( source_mtime > generated_mtime ) && ( source_mtime + 1 < now )
230
+
231
+ while true
232
+ now = Time.now
233
+ source_mtime = File.mtime( page.source_path )
234
+ if ( now - source_mtime > 1 )
235
+ if ( source_mtime - generated_mtime >= 0 )
236
+ return true
237
+ else
238
+ break
239
+ end
240
+ end
241
+ sleep 0.1
242
+ end
243
+
219
244
  ext = page.output_extension
220
245
  layout_name = page.layout
221
246
  while ( ! layout_name.nil? )
@@ -313,6 +338,16 @@ module Awestruct
313
338
  site.send( "#{name}=", massage_yaml( data ) )
314
339
  end
315
340
 
341
+ def inherit_front_matter( page )
342
+ layout = page.layout
343
+ while ( layout )
344
+ layout_name = layout.to_s + page.output_extension
345
+ current = site.layouts[ layout_name ]
346
+ current.front_matter.each { |k,v| page.send( "#{k}=", v ) unless page.send( "#{k}" ) } if current
347
+ layout = current.layout
348
+ end
349
+ end
350
+
316
351
  def load_pages()
317
352
  site.pages.clear
318
353
  dir_pathname = Pathname.new( dir )
@@ -330,6 +365,7 @@ module Awestruct
330
365
  relative_path = file_pathname.relative_path_from( dir_pathname ).to_s
331
366
  page = load_page( path, :relative_path => relative_path )
332
367
  if ( page )
368
+ inherit_front_matter( page )
333
369
  site.pages << page
334
370
  end
335
371
  end
@@ -351,6 +387,7 @@ module Awestruct
351
387
  relative_path = file_pathname.relative_path_from( skin_dir_pathname ).to_s
352
388
  page = load_page( path, :relative_path => relative_path )
353
389
  if ( page )
390
+ inherit_front_matter( page )
354
391
  site.pages << page
355
392
  end
356
393
  end
@@ -382,9 +419,6 @@ module Awestruct
382
419
  skin_pipeline = nil
383
420
 
384
421
  ext_dir = File.join( config.extension_dir )
385
- if ( $LOAD_PATH.index( ext_dir ).nil? )
386
- $LOAD_PATH << ext_dir
387
- end
388
422
  pipeline_file = File.join( ext_dir, 'pipeline.rb' )
389
423
  if ( File.exists?( pipeline_file ) )
390
424
  pipeline = eval File.read( pipeline_file )
@@ -0,0 +1,66 @@
1
+ # Generates a sitemap for search engines. Defaults to /sitemap.xml
2
+ # Ignores images, css, robots, atoms, javascript files.
3
+ # Add a sitemap.yml file to add files that for one reason or
4
+ # another won't be hanging off of site (e.g. they're in .htaccess)
5
+ require 'ostruct'
6
+
7
+ module Awestruct
8
+ module Extensions
9
+ class Sitemap
10
+
11
+ def execute( site )
12
+
13
+ # Go through all of the site's pages and add sitemap metadata
14
+ sitemap_pages = []
15
+ entries = site.pages
16
+ entries.each { |entry| sitemap_pages << set_sitemap_data( entry ) if valid_sitemap_entry( entry ) } if entries
17
+
18
+ # Generate sitemap pages for stuff in _config/sitemap.yml
19
+ site.sitemap.pages.each do |entry|
20
+ page = Awestruct::Renderable.new( site )
21
+ page.output_path = entry.url
22
+ page.date = entry.date( nil )
23
+ page.priority = entry.priority( nil )
24
+ page.change_frequency = entry.change_frequency( nil )
25
+ sitemap_pages << page
26
+ end if site.sitemap
27
+
28
+ # Generate the correct urls for each page in the sitemap
29
+ site.engine.set_urls( sitemap_pages )
30
+
31
+ # Create a sitemap.xml file from our template
32
+ sitemap = File.join( File.dirname(__FILE__), 'sitemap.xml.haml' )
33
+ page = site.engine.load_page( sitemap )
34
+ page.output_path = 'sitemap.xml'
35
+ page.sitemap_entries = sitemap_pages
36
+
37
+ # Add the sitemap to our site
38
+ site.pages << page
39
+ end
40
+
41
+ protected
42
+ def set_sitemap_data( page )
43
+ site = page.site
44
+ page.date ||= Time.now
45
+ page.priority ||= (site.priority or 0.1)
46
+ page.change_frequency ||= (site.change_frequency or 'never')
47
+ page
48
+ end
49
+
50
+ def valid_sitemap_entry( page )
51
+ page.output_filename != '.htaccess' &&
52
+ page.output_filename != 'screen.css' &&
53
+ page.output_filename != 'print.css' &&
54
+ page.output_filename != 'ie.css' &&
55
+ page.output_filename != 'robots.txt' &&
56
+ page.output_extension != '.atom' &&
57
+ page.output_extension != '.scss' &&
58
+ page.output_extension != '.css' &&
59
+ page.output_extension != '.png' &&
60
+ page.output_extension != '.jpg' &&
61
+ page.output_extension != '.gif' &&
62
+ page.output_extension != '.js'
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ ---
3
+ !!! XML
4
+
5
+ %urlset{ :xmlns=>'http://www.sitemaps.org/schemas/sitemap/0.9' }
6
+ - unless page.sitemap_entries.empty?
7
+ - for entry in page.sitemap_entries
8
+ %url
9
+ %loc= "#{entry.site.base_url}#{entry.url}"
10
+ - if entry.date
11
+ %lastmod= entry.date
12
+ - if entry.priority
13
+ %priority= entry.priority
14
+ - if entry.change_frequency
15
+ %changefreq= entry.change_frequency
16
+
@@ -4,5 +4,4 @@
4
4
  .tag-cloud
5
5
  - for tag in page.tags
6
6
  %span.tag{:class=>"tag-#{tag.group}"}
7
- %a{:href=>tag.primary_page.url}
8
- = tag.to_s
7
+ %a{:href=>tag.primary_page.url}= tag
@@ -17,6 +17,14 @@ module Awestruct
17
17
  end
18
18
  end
19
19
 
20
+ module TagLinker
21
+ attr_accessor :tags
22
+ def tag_links(delimiter = ', ', style_class = nil)
23
+ class_attr = (style_class ? ' class="' + style_class + '"' : '')
24
+ tags.map{|tag| %Q{<a#{class_attr} href="#{tag.primary_page.url}">#{tag}</a>}}.join(delimiter)
25
+ end
26
+ end
27
+
20
28
  def initialize(tagged_items_property, input_path, output_path='tags', pagination_opts={})
21
29
  @tagged_items_property = tagged_items_property
22
30
  @input_path = input_path
@@ -42,6 +50,7 @@ module Awestruct
42
50
 
43
51
  all.each do |page|
44
52
  page.tags = (page.tags||[]).collect{|t| @tags[t]}
53
+ page.extend( TagLinker )
45
54
  end
46
55
 
47
56
  ordered_tags = @tags.values
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Awestruct
3
- VERSION='0.2.7'
3
+ VERSION='0.2.8'
4
4
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- version: 0.2.7
8
+ - 8
9
+ version: 0.2.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bob McWhirter
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-31 00:00:00 -04:00
17
+ date: 2011-11-17 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -187,6 +187,7 @@ files:
187
187
  - lib/awestruct/extensions/partial.rb
188
188
  - lib/awestruct/extensions/pipeline.rb
189
189
  - lib/awestruct/extensions/posts.rb
190
+ - lib/awestruct/extensions/sitemap.rb
190
191
  - lib/awestruct/extensions/tag_cloud.rb
191
192
  - lib/awestruct/extensions/tagger.rb
192
193
  - lib/awestruct/front_matter_file.rb
@@ -212,6 +213,7 @@ files:
212
213
  - lib/awestruct/commands/frameworks/960/base_layout.html.haml
213
214
  - lib/awestruct/commands/frameworks/base_index.html.haml
214
215
  - lib/awestruct/commands/frameworks/blueprint/base_layout.html.haml
216
+ - lib/awestruct/extensions/sitemap.xml.haml
215
217
  - lib/awestruct/extensions/tag_cloud.html.haml
216
218
  - lib/awestruct/extensions/template.atom.haml
217
219
  has_rdoc: true