awestruct 0.1.9 → 0.2.0

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
@@ -104,14 +104,23 @@ unless options.init
104
104
  site_yaml = YAML.load( File.read( site_yaml_file ) )
105
105
  if site_yaml
106
106
  @profiles_data = site_yaml['profiles'] || {}
107
- @profile_data = @profiles_data.nil? ? nil : @profiles_data[options.profile]
107
+ @profile_data = if @profiles_data.nil?
108
+ nil
109
+ else
110
+ if options.profile
111
+ @profiles_data[options.profile]
112
+ else
113
+ # if no profile given, pick the first with deploy config
114
+ options.profile, profile_data = @profiles_data.select { |k,v| v['deploy'] }.first
115
+ profile_data
116
+ end
117
+ end
108
118
  end
109
119
  end
110
120
 
111
121
  config = Awestruct::Config.new(Dir.pwd)
112
122
  # config.input_dir = File.join(Dir.pwd, '_root')
113
123
 
114
-
115
124
  if ( options.init )
116
125
  if ( options.generate || options.auto || options.server )
117
126
  $stderr.puts "--init may not be used with --generate, --auto or --server"
@@ -122,6 +131,31 @@ if ( options.init )
122
131
  exit
123
132
  end
124
133
 
134
+ default_base_url = 'http://localhost:4242'
135
+
136
+ def camelize(str)
137
+ str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
138
+ end
139
+
140
+ if ( options.script )
141
+ puts "Running #{options.script} and exiting"
142
+ require "awestruct/scripts/#{options.script}"
143
+ script_class = eval "Awestruct::Scripts::#{camelize(options.script)}"
144
+ script = script_class.new(*ARGV)
145
+ script.run
146
+ exit
147
+ end
148
+
149
+ if ( options.server )
150
+ hostname = ( options.bind_addr == '0.0.0.0' ? 'localhost' : options.bind_addr )
151
+ default_base_url = "http://#{hostname}:#{options.port}"
152
+ end
153
+
154
+ if ( options.generate )
155
+ cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url, options.force )
156
+ cmd.run
157
+ end
158
+
125
159
  if ( options.deploy )
126
160
  if ( options.auto || options.server )
127
161
  $stderr.puts "--deploy may not be used with --auto or --server"
@@ -133,13 +167,11 @@ if ( options.deploy )
133
167
  exit
134
168
  end
135
169
 
136
-
137
170
  if ( @profiles_data.nil? )
138
171
  $stderr.puts "_config/site.yml must define a 'profiles' section"
139
172
  exit
140
173
  end
141
174
 
142
-
143
175
  if ( @profile_data.nil? )
144
176
  $stderr.puts "Unknown profile '#{options.profile}'"
145
177
  exit
@@ -156,39 +188,15 @@ if ( options.deploy )
156
188
  exit
157
189
  end
158
190
 
191
+ puts "deploying to '#{options.profile}'"
159
192
  cmd = Awestruct::Commands::Deploy.new( site_path, deploy_data )
160
-
161
193
  cmd.run
162
- exit
163
- end
164
-
165
- default_base_url = 'http://localhost:4242'
166
-
167
- def camelize(str)
168
- str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
169
- end
170
-
171
- if ( options.script )
172
- puts "Running #{options.script} and exiting"
173
- require "awestruct/scripts/#{options.script}"
174
- script_class = eval "Awestruct::Scripts::#{camelize(options.script)}"
175
- script = script_class.new(*ARGV)
176
- script.run
194
+ puts "deploy finished"
177
195
  exit
178
196
  end
179
197
 
180
198
  threads = []
181
199
 
182
- if ( options.server )
183
- hostname = ( options.bind_addr == '0.0.0.0' ? 'localhost' : options.bind_addr )
184
- default_base_url = "http://#{hostname}:#{options.port}"
185
- end
186
-
187
- if ( options.generate )
188
- cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url, options.force )
189
- cmd.run
190
- end
191
-
192
200
  if ( options.auto )
193
201
  threads << Thread.new {
194
202
  generate_cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url )
@@ -210,6 +218,3 @@ end
210
218
  threads.each do |thr|
211
219
  thr.join
212
220
  end
213
-
214
-
215
-
@@ -6,7 +6,13 @@ module Awestruct
6
6
  def render(context)
7
7
  rendered = ''
8
8
  begin
9
- doc = BlueCloth.new( context.interpolate_string( raw_page_content ) )
9
+ bluecloth_options = { :smartypants => true }
10
+
11
+ unless self.options.nil?
12
+ bluecloth_options.merge!({ :smartypants => false }) if self.options[:html_entities] == false
13
+ end
14
+
15
+ doc = BlueCloth.new( context.interpolate_string( raw_page_content ), bluecloth_options )
10
16
  rendered = doc.to_html
11
17
  rescue => e
12
18
  puts e
@@ -12,19 +12,28 @@ module Awestruct
12
12
 
13
13
  def run
14
14
  cmd = "rsync -r -l -i --no-p --no-g --chmod=Dg+s,ug+w --delete #{@site_path} #{@host}:#{@path}"
15
- puts "running #{cmd}"
16
- Open3.popen3( cmd ) do |stdin, stdout, stderr|
15
+ Open3.popen3( cmd ) do |stdin, stdout, stderr|
17
16
  stdin.close
18
17
  threads = []
19
18
  threads << Thread.new(stdout) do |i|
20
19
  while ( ! i.eof? )
21
- line = i.readline
22
- puts line
20
+ line = i.readline
21
+ case line[0,9]
22
+ when '<f.sT....'
23
+ puts " updating #{line[10..-1]}"
24
+ when '<f+++++++'
25
+ puts " adding #{line[10..-1]}"
26
+ when '<f..T....'
27
+ # ignoring unchanged files
28
+ # puts " no change to #{line[10..-1]}"
29
+ else
30
+ puts line
31
+ end
23
32
  end
24
33
  end
25
34
  threads << Thread.new(stderr) do |i|
26
35
  while ( ! i.eof? )
27
- line = i.readline
36
+ line = i.readline
28
37
  puts line
29
38
  end
30
39
  end
@@ -14,7 +14,12 @@ module Awestruct
14
14
  end
15
15
 
16
16
  def run()
17
- @engine.generate( @profile, @base_url, @default_base_url, @force )
17
+ begin
18
+ @engine.generate( @profile, @base_url, @default_base_url, @force )
19
+ rescue =>e
20
+ puts e
21
+ puts e.backtrace
22
+ end
18
23
  end
19
24
  end
20
25
  end
@@ -8,8 +8,8 @@ module Awestruct
8
8
  attr_accessor :extension_dir
9
9
  attr_accessor :input_dir
10
10
  attr_accessor :output_dir
11
- attr_accessor :tmp_dir
12
11
  attr_accessor :skin_dir
12
+ attr_accessor :tmp_dir
13
13
  attr_accessor :ignore
14
14
 
15
15
  def initialize(dir)
@@ -11,13 +11,35 @@ module Awestruct
11
11
  str.gsub( /&nbsp;/, ' ' )
12
12
  end
13
13
 
14
- def summarize(text, numwords=20)
15
- text.split()[0, numwords].join(' ')
14
+ def without_images(str)
15
+ str.gsub(/<img[^>]+>/,'').gsub(/<a[^>]+>([^<]*)<\/a>/, '\1')
16
16
  end
17
-
17
+
18
+ def close_tags(s)
19
+ stack = []
20
+ s.scan(/<\/?[^>]+>/).each do |tag|
21
+ if tag[1] != '/'
22
+ tag = tag[1..-1].scan(/\w+/).first
23
+ stack = [ tag ] + stack
24
+ else
25
+ tag = tag[2..-1].scan(/\w+/).first
26
+ if stack[0] == tag
27
+ stack = stack.drop(1)
28
+ else
29
+ raise "Malformed HTML expected #{tag[0]} but got #{tag} '#{s}'"
30
+ end
31
+ end
32
+ end
33
+ stack.inject(s) { |memo,tag| memo += "</#{tag}>" }
34
+ end
35
+
36
+ def summarize(text, numwords=20, ellipsis='...')
37
+ close_tags(text.split()[0, numwords].join(' ') + ellipsis)
38
+ end
39
+
18
40
  def fully_qualify_urls(base_url, text)
19
41
  doc = Hpricot( text )
20
-
42
+
21
43
  doc.search( "//a" ).each do |a|
22
44
  a['href'] = fix_url( base_url, a['href'] )
23
45
  end
@@ -29,7 +51,7 @@ module Awestruct
29
51
  end
30
52
  return doc.to_s
31
53
  end
32
-
54
+
33
55
  def fix_url(base_url, url)
34
56
  return url unless ( url =~ /^\// )
35
57
  "#{base_url}#{url}"
@@ -22,7 +22,6 @@ require 'awestruct/context_helper'
22
22
 
23
23
  require 'awestruct/extensions/pipeline'
24
24
  require 'awestruct/extensions/posts'
25
- require 'awestruct/extensions/collection'
26
25
  require 'awestruct/extensions/indexifier'
27
26
  require 'awestruct/extensions/data_dir'
28
27
  require 'awestruct/extensions/paginator'
@@ -70,8 +69,8 @@ module Awestruct
70
69
  load_layouts
71
70
  load_pages
72
71
  load_extensions
73
- set_urls
74
- configure_compass
72
+ set_urls(site.pages)
73
+ configure_compass
75
74
  generate_files(force)
76
75
  end
77
76
 
@@ -83,39 +82,39 @@ module Awestruct
83
82
  dir_pathname = Pathname.new( dir )
84
83
  path_name = Pathname.new( candidates[0] )
85
84
  relative_path = path_name.relative_path_from( dir_pathname ).to_s
86
- load_page( candidates[0], relative_path )
85
+ load_page( candidates[0], :relative_path => relative_path )
87
86
  end
88
87
 
89
88
  def load_site_page(relative_path)
90
89
  load_page( File.join( dir, relative_path ) )
91
90
  end
92
91
 
93
- def load_page(path, relative_path=nil)
92
+ def load_page(path, options = {})
94
93
  page = nil
95
- if ( relative_path.nil? )
94
+ if ( options[:relative_path].nil? )
96
95
  #dir_pathname = Pathname.new( dir )
97
96
  #path_name = Pathname.new( path )
98
97
  #relative_path = path_name.relative_path_from( dir_pathname ).to_s
99
98
  end
100
99
 
101
- fixed_relative_path = ( relative_path.nil? ? nil : File.join( '', relative_path ) )
100
+ fixed_relative_path = ( options[:relative_path].nil? ? nil : File.join( '', options[:relative_path] ) )
102
101
 
103
102
  if ( path =~ /\.haml$/ )
104
- page = HamlFile.new( site, path, fixed_relative_path )
103
+ page = HamlFile.new( site, path, fixed_relative_path, options )
105
104
  elsif ( path =~ /\.erb$/ )
106
- page = ErbFile.new( site, path, fixed_relative_path )
105
+ page = ErbFile.new( site, path, fixed_relative_path, options )
107
106
  elsif ( path =~ /\.textile$/ )
108
- page = TextileFile.new( site, path, fixed_relative_path )
107
+ page = TextileFile.new( site, path, fixed_relative_path, options )
109
108
  elsif ( path =~ /\.md$/ )
110
- page = MarukuFile.new( site, path, fixed_relative_path )
109
+ page = MarukuFile.new( site, path, fixed_relative_path, options )
111
110
  elsif ( path =~ /\.sass$/ )
112
- page = SassFile.new( site, path, fixed_relative_path )
111
+ page = SassFile.new( site, path, fixed_relative_path, options )
113
112
  elsif ( path =~ /\.scss$/ )
114
- page = ScssFile.new( site, path, fixed_relative_path )
113
+ page = ScssFile.new( site, path, fixed_relative_path, options )
115
114
  elsif ( path =~ /\.org$/ )
116
- page = OrgModeFile.new( site, path, fixed_relative_path )
115
+ page = OrgModeFile.new( site, path, fixed_relative_path, options )
117
116
  elsif ( File.file?( path ) )
118
- page = VerbatimFile.new( site, path, fixed_relative_path )
117
+ page = VerbatimFile.new( site, path, fixed_relative_path, options )
119
118
  end
120
119
  page
121
120
  end
@@ -133,17 +132,32 @@ module Awestruct
133
132
  str = str.gsub( /\\/, '\\\\\\\\' )
134
133
  str = str.gsub( /\\\\#/, '\\#' )
135
134
  str = str.gsub( '@', '\@' )
135
+ str = str.gsub( '#{', '\#\{' )
136
136
  str = "%@#{str}@"
137
137
  result = instance_eval( str )
138
138
  result
139
139
  end
140
140
  def evaluate_erb(erb)
141
- erb.result( binding )
141
+ erb.result( binding )
142
142
  end
143
143
  end
144
144
  context
145
145
  end
146
146
 
147
+ def set_urls(pages)
148
+ pages.each do |page|
149
+ page_path = page.output_path
150
+ if ( page_path =~ /^\// )
151
+ page.url = page_path
152
+ else
153
+ page.url = "/#{page_path}"
154
+ end
155
+ if ( page.url =~ /^(.*\/)index.html$/ )
156
+ page.url = $1
157
+ end
158
+ end
159
+ end
160
+
147
161
  private
148
162
 
149
163
  def configure_compass
@@ -161,30 +175,16 @@ module Awestruct
161
175
  end
162
176
 
163
177
  if ( site.base_url.nil? )
164
- site.base_url = @default_base_url
178
+ site.base_url = @default_base_url
165
179
  end
166
180
 
167
- if ( site.base_url )
181
+ if ( site.base_url )
168
182
  if ( site.base_url =~ /^(.*)\/$/ )
169
183
  site.base_url = $1
170
184
  end
171
185
  end
172
186
  end
173
187
 
174
- def set_urls
175
- site.pages.each do |page|
176
- page_path = page.output_path
177
- if ( page_path =~ /^\// )
178
- page.url = page_path
179
- else
180
- page.url = "/#{page_path}"
181
- end
182
- if ( page.url =~ /^(.*\/)index.html$/ )
183
- page.url = $1
184
- end
185
- end
186
- end
187
-
188
188
  def generate_files(force)
189
189
  site.pages.each do |page|
190
190
  generate_page( page, force )
@@ -203,7 +203,7 @@ module Awestruct
203
203
  end
204
204
  end
205
205
 
206
- def requires_generation?(page,force)
206
+ def requires_generation?(page, force)
207
207
  return true if force
208
208
  generated_path = File.join( config.output_dir, page.output_path )
209
209
  return true unless File.exist?( generated_path )
@@ -241,6 +241,9 @@ module Awestruct
241
241
  end
242
242
  end
243
243
  end
244
+ @transformers.each do |transformer|
245
+ rendered = transformer.transform(site, page, rendered)
246
+ end
244
247
  rendered
245
248
  end
246
249
 
@@ -251,7 +254,7 @@ module Awestruct
251
254
  layout_pathname = Pathname.new( layout_path )
252
255
  relative_path = layout_pathname.relative_path_from( dir_pathname ).to_s
253
256
  name = File.basename( layout_path, '.haml' )
254
- site.layouts[ name ] = load_page( layout_path, relative_path )
257
+ site.layouts[ name ] = load_page( layout_path, :relative_path => relative_path )
255
258
  end
256
259
  if ( skin_dir )
257
260
  skin_dir_pathname = Pathname.new( skin_dir )
@@ -260,7 +263,7 @@ module Awestruct
260
263
  relative_path = layout_pathname.relative_path_from( skin_dir_pathname ).to_s
261
264
  name = File.basename( layout_path, '.haml' )
262
265
  unless ( site.layouts.key?( name ) )
263
- site.layouts[ name ] = load_page( layout_path, relative_path )
266
+ site.layouts[ name ] = load_page( layout_path, :relative_path => relative_path )
264
267
  end
265
268
  end
266
269
  end
@@ -320,7 +323,7 @@ module Awestruct
320
323
  unless ( site.has_page?( path ) )
321
324
  file_pathname = Pathname.new( path )
322
325
  relative_path = file_pathname.relative_path_from( dir_pathname ).to_s
323
- page = load_page( path, relative_path )
326
+ page = load_page( path, :relative_path => relative_path )
324
327
  if ( page )
325
328
  site.pages << page
326
329
  end
@@ -341,7 +344,7 @@ module Awestruct
341
344
  unless ( site.has_page?( path ) )
342
345
  file_pathname = Pathname.new( path )
343
346
  relative_path = file_pathname.relative_path_from( skin_dir_pathname ).to_s
344
- page = load_page( path, relative_path )
347
+ page = load_page( path, :relative_path => relative_path )
345
348
  if ( page )
346
349
  site.pages << page
347
350
  end
@@ -378,9 +381,10 @@ module Awestruct
378
381
  $LOAD_PATH << ext_dir
379
382
  end
380
383
  pipeline_file = File.join( ext_dir, 'pipeline.rb' )
381
- if ( File.exists?( pipeline_file ) )
384
+ if ( File.exists?( pipeline_file ) )
382
385
  pipeline = eval File.read( pipeline_file )
383
386
  @helpers = pipeline.helpers || []
387
+ @transformers = pipeline.transformers || []
384
388
  end
385
389
 
386
390
  if ( skin_dir )
@@ -392,6 +396,7 @@ module Awestruct
392
396
  if ( File.exists?( skin_pipeline_file ) )
393
397
  skin_pipeline = eval File.read( skin_pipeline_file )
394
398
  @helpers = ( @helpers + skin_pipeline.helpers || [] ).flatten
399
+ @transformers = ( @transformers + skin_pipeline.transformers || [] ).flatten
395
400
  end
396
401
  end
397
402
 
@@ -8,8 +8,8 @@ module Awestruct
8
8
 
9
9
  include Erbable
10
10
 
11
- def initialize(site, source_path, relative_source_path)
12
- super(site, source_path, relative_source_path)
11
+ def initialize(site, source_path, relative_source_path, options = {})
12
+ super(site, source_path, relative_source_path, options)
13
13
  end
14
14
 
15
15
  def output_filename
@@ -12,15 +12,28 @@ module Awestruct
12
12
  unless ( @num_entries == :all )
13
13
  entries = entries[0, @num_entries]
14
14
  end
15
+
16
+ atom_pages = []
17
+
18
+ entries.each do |entry|
19
+ feed_entry = site.engine.load_page(entry.source_path, :relative_path => entry.relative_source_path, :html_entities => false)
20
+
21
+ feed_entry.output_path = entry.output_path
22
+ feed_entry.date = feed_entry.timestamp.nil? ? entry.date : feed_entry.timestamp
23
+
24
+ atom_pages << feed_entry
25
+ end
26
+
27
+ site.engine.set_urls(atom_pages)
28
+
15
29
  input_page = File.join( File.dirname(__FILE__), 'template.atom.haml' )
16
30
  page = site.engine.load_page( input_page )
17
31
  page.date = page.timestamp unless page.timestamp.nil?
18
32
  page.output_path = @output_path
19
- page.entries = entries
33
+ page.entries = atom_pages
20
34
  page.title = site.title || site.base_url
21
35
  site.pages << page
22
36
  end
23
-
24
37
  end
25
38
  end
26
39
  end
@@ -12,7 +12,8 @@ module Awestruct
12
12
  %Q{
13
13
  <div id="disqus_thread"></div>
14
14
  <script type="text/javascript">
15
- var disqus_url = "#{self.url}";
15
+ var disqus_shortname = '#{site.disqus}';
16
+ var disqus_url = "#{site.base_url}/#{self.url}";
16
17
  #{developer}
17
18
  (function() {
18
19
  var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true;
@@ -31,7 +32,7 @@ module Awestruct
31
32
  def disqus_comments_count()
32
33
  %Q{
33
34
  <script type="text/javascript">
34
- var disqus = "#{site.disqus}";
35
+ var disqus_shortname = '#{site.disqus}';
35
36
  (function () {
36
37
  var s = document.createElement('script'); s.async = true;
37
38
  s.src = "http://disqus.com/forums/#{site.disqus}/count.js";
@@ -20,18 +20,17 @@ module Awestruct
20
20
  def google_analytics_async()
21
21
  html = ''
22
22
  html += %Q(<script type="text/javascript">\n)
23
- html += %Q(var _gaq = [['_setAccount','#{site.google_analytics}"'],)
23
+ html += %Q(var _gaq = _gaq || [];\n)
24
+ html += %Q(_gaq.push(['_setAccount','#{site.google_analytics}']);\n)
24
25
  if site.google_analytics_anonymize
25
- html += %Q(['_gat._anonymizeIp'],)
26
+ html += %Q(_gaq.push(['_gat._anonymizeIp']);\n)
26
27
  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]
28
+ html += %Q(_gaq.push(['_trackPageview']);\n)
29
+ html += %Q[(function() {\n]
30
+ html += %Q( var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n)
31
+ html += %Q( ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n)
32
+ html += %Q( var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n)
33
+ html += %Q[})();\n</script>\n]
35
34
  html
36
35
  end
37
36
  end
@@ -7,10 +7,12 @@ module Awestruct
7
7
  attr_reader :extensions
8
8
  attr_reader :after_extensions
9
9
  attr_reader :helpers
10
+ attr_reader :transformers
10
11
 
11
12
  def initialize(&block)
12
13
  @extensions = []
13
14
  @helpers = []
15
+ @transformers = []
14
16
  instance_eval &block if block
15
17
  end
16
18
 
@@ -22,6 +24,10 @@ module Awestruct
22
24
  @helpers << helper
23
25
  end
24
26
 
27
+ def transformer(transformer)
28
+ @transformers << transformer
29
+ end
30
+
25
31
  def execute(site)
26
32
  extensions.each do |ext|
27
33
  ext.execute( site )
@@ -2,26 +2,35 @@
2
2
  ---
3
3
  !!! XML
4
4
 
5
- %feed{ 'xml:base'=>site.base_url, 'xml:lang'=>'en-US', :xmlns=>'http://www.w3.org/2005/Atom' }
6
- %id #{site.base_url}
5
+ %feed{ 'xml:lang'=>'en-US', :xmlns=>'http://www.w3.org/2005/Atom' }
6
+ %id= "#{site.base_url}/"
7
7
  %title #{page.title}
8
+ - if ( defined?( site.author ) )
9
+ %author
10
+ - if ( defined?( site.author.name ) )
11
+ %name= site.author.name
12
+ - if ( site.author.email )
13
+ %email= site.author.email
14
+ - else
15
+ %name= site.author
8
16
  - unless page.entries.empty?
9
17
  %updated= page.entries.first.date.xmlschema
10
- %link{:rel=>"alternate", :type=>"text/html", :href=>site.base_url}
11
18
  %link{:rel=>"self", :type=>"application/atom+xml", :href=>"#{site.base_url}#{page.url}" }
19
+ %link{:rel=>"alternate", :type=>"text/html", :href=>"#{site.base_url}/" }
12
20
  - for entry in page.entries
13
21
  %entry
14
22
  %id #{site.base_url}#{entry.url}
15
23
  %title= escape_once( entry.title )
16
24
  %updated= entry.date.xmlschema
17
25
  %link{:rel=>"alternate", :type=>"text/html", :href=>"#{site.base_url}#{entry.url}" }
18
- %author
19
- - if ( defined?( entry.author.name ) )
20
- %name= entry.author.name
21
- - if ( entry.author.email )
22
- %name= entry.author.email
23
- - else
24
- %name= entry.author
26
+ - if ( defined?( entry.author ) )
27
+ %author
28
+ - if ( defined?( entry.author.name ) )
29
+ %name= entry.author.name
30
+ - if ( entry.author.email )
31
+ %email= entry.author.email
32
+ - else
33
+ %name= entry.author
25
34
  %summary
26
35
  #{summarize( html_to_text( entry.content ), 100 )}...
27
36
  %content{:type=>'html'}
@@ -6,8 +6,8 @@ module Awestruct
6
6
  attr_reader :raw_page_content
7
7
  attr_reader :front_matter
8
8
 
9
- def initialize(site, source_path, relative_source_path)
10
- super( site, source_path, relative_source_path )
9
+ def initialize(site, source_path, relative_source_path, options = {})
10
+ super( site, source_path, relative_source_path, options )
11
11
  @raw_page_content = ''
12
12
  load_page
13
13
  end
@@ -45,7 +45,7 @@ module Awestruct
45
45
  @front_matter.each do |k,v|
46
46
  self.send( "#{k}=", v )
47
47
  end
48
- rescue=>e
48
+ rescue => e
49
49
  puts "error reading #{self}: #{e}"
50
50
  end
51
51
  end
@@ -8,8 +8,8 @@ module Awestruct
8
8
 
9
9
  include Hamlable
10
10
 
11
- def initialize(site, source_path, relative_source_path)
12
- super(site, source_path, relative_source_path)
11
+ def initialize(site, source_path, relative_source_path, options = {})
12
+ super(site, source_path, relative_source_path, options)
13
13
  end
14
14
 
15
15
  def output_filename
@@ -4,7 +4,8 @@ module Awestruct
4
4
  def render(context)
5
5
  rendered = ''
6
6
  begin
7
- haml_engine = Haml::Engine.new( raw_page_content )
7
+ options = (site.haml || {}).inject({}){|h,(k,v)| h[k.to_sym] = v.to_sym; h }
8
+ haml_engine = Haml::Engine.new( raw_page_content, options )
8
9
  rendered = haml_engine.render( context )
9
10
  rescue => e
10
11
  puts e
@@ -9,8 +9,8 @@ module Awestruct
9
9
  #include Marukuable
10
10
  include Blueclothable
11
11
 
12
- def initialize(site, source_path, relative_source_path)
13
- super(site, source_path, relative_source_path)
12
+ def initialize(site, source_path, relative_source_path, options = {})
13
+ super(site, source_path, relative_source_path, options)
14
14
  end
15
15
 
16
16
  def output_filename
@@ -8,8 +8,8 @@ module Awestruct
8
8
 
9
9
  include OrgModeable
10
10
 
11
- def initialize(site, source_path, relative_source_path)
12
- super( site, source_path, relative_source_path )
11
+ def initialize(site, source_path, relative_source_path, options = {})
12
+ super( site, source_path, relative_source_path, options )
13
13
  end
14
14
 
15
15
  def output_filename
@@ -4,10 +4,11 @@ require 'awestruct/renderable'
4
4
  module Awestruct
5
5
  class RenderableFile < Renderable
6
6
 
7
- def initialize(site, source_path, relative_source_path)
7
+ def initialize(site, source_path, relative_source_path, options = {})
8
8
  super( site )
9
9
  self.source_path = source_path
10
10
  self.relative_source_path = relative_source_path
11
+ self.options = options
11
12
  unless ( relative_source_path.nil? )
12
13
  dir_name = File.dirname( relative_source_path )
13
14
  if ( dir_name == '.' )
@@ -18,10 +19,6 @@ module Awestruct
18
19
  end
19
20
  end
20
21
 
21
- def to_root
22
- '../' * ( self.output_path.count('/') - 1 )
23
- end
24
-
25
22
  def raw_page_content
26
23
  File.read( self.source_path )
27
24
  end
@@ -8,8 +8,8 @@ module Awestruct
8
8
 
9
9
  include Sassable
10
10
 
11
- def initialize(site, source_path, relative_source_path)
12
- super( site, source_path, relative_source_path )
11
+ def initialize(site, source_path, relative_source_path, options = {})
12
+ super( site, source_path, relative_source_path, options )
13
13
  end
14
14
 
15
15
  def output_filename
@@ -2,6 +2,13 @@ require 'sass'
2
2
 
3
3
  require 'compass'
4
4
 
5
+ module Sass::Script::Functions
6
+ def site(path)
7
+ site = options[:custom]
8
+ Sass::Script::String.new(site.send(path.value.to_s).to_s)
9
+ end
10
+ end
11
+
5
12
  module Awestruct
6
13
  module Sassable
7
14
 
@@ -11,8 +18,9 @@ module Awestruct
11
18
  Compass::Frameworks::ALL.each do |framework|
12
19
  sass_opts[:load_paths] << framework.stylesheets_directory
13
20
  end
14
- sass_opts[:load_paths] << File.dirname( self.source_path )
21
+ sass_opts[:load_paths] << File.dirname( self.source_path )
15
22
  sass_opts[:syntax] = syntax()
23
+ sass_opts[:custom] = site
16
24
  sass_engine = Sass::Engine.new( raw_page_content, sass_opts )
17
25
  sass_engine.render
18
26
  end
@@ -8,8 +8,8 @@ module Awestruct
8
8
 
9
9
  include Sassable
10
10
 
11
- def initialize(site, source_path, relative_source_path)
12
- super( site, source_path, relative_source_path )
11
+ def initialize(site, source_path, relative_source_path, options = {})
12
+ super( site, source_path, relative_source_path, options )
13
13
  end
14
14
 
15
15
  def output_filename
@@ -5,20 +5,20 @@ module Awestruct
5
5
 
6
6
  attr_reader :dir
7
7
  attr_reader :output_dir
8
+ attr_reader :tmp_dir
8
9
 
9
10
  attr_reader :layouts
10
11
  attr_accessor :pages
11
12
 
12
- attr_accessor :config
13
-
14
13
  def initialize(config)
15
14
  super({})
16
15
 
17
16
  @dir = config.input_dir
18
17
  @output_dir = config.output_dir
19
- @config = config
18
+ @tmp_dir = config.tmp_dir
20
19
 
21
20
  FileUtils.mkdir_p( @output_dir )
21
+ FileUtils.mkdir_p( @tmp_dir )
22
22
 
23
23
  @pages = []
24
24
  @layouts = {}
@@ -7,8 +7,8 @@ module Awestruct
7
7
 
8
8
  include Textilable
9
9
 
10
- def initialize(site, source_path, relative_source_path)
11
- super(site, source_path, relative_source_path)
10
+ def initialize(site, source_path, relative_source_path, options = {})
11
+ super(site, source_path, relative_source_path, options)
12
12
  end
13
13
 
14
14
  def output_filename
@@ -4,8 +4,8 @@ module Awestruct
4
4
 
5
5
  class VerbatimFile < RenderableFile
6
6
 
7
- def initialize(site, source_path, relative_source_path)
8
- super( site, source_path, relative_source_path )
7
+ def initialize(site, source_path, relative_source_path, options = {})
8
+ super( site, source_path, relative_source_path, options )
9
9
  end
10
10
 
11
11
  end
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: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 9
10
- version: 0.1.9
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bob McWhirter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-20 00:00:00 Z
18
+ date: 2011-06-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: hpricot
@@ -167,7 +167,6 @@ 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
171
170
  - lib/awestruct/extensions/data_dir.rb
172
171
  - lib/awestruct/extensions/disqus.rb
173
172
  - lib/awestruct/extensions/google_analytics.rb
@@ -1,52 +0,0 @@
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