darthapo-stratus 0.2

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.
Files changed (88) hide show
  1. data/Changelog +3 -0
  2. data/Manifest +87 -0
  3. data/Rakefile +82 -0
  4. data/Readme.markdown +15 -0
  5. data/bin/stratus +8 -0
  6. data/lib/stratus/cli.rb +206 -0
  7. data/lib/stratus/filters.rb +73 -0
  8. data/lib/stratus/generator/builder.rb +147 -0
  9. data/lib/stratus/generator/context.rb +39 -0
  10. data/lib/stratus/generator/renderer.rb +100 -0
  11. data/lib/stratus/generator/scanner.rb +75 -0
  12. data/lib/stratus/generator.rb +12 -0
  13. data/lib/stratus/resources/attachment.rb +41 -0
  14. data/lib/stratus/resources/base.rb +257 -0
  15. data/lib/stratus/resources/content.rb +17 -0
  16. data/lib/stratus/resources/hash_db.rb +128 -0
  17. data/lib/stratus/resources/layout.rb +18 -0
  18. data/lib/stratus/resources/template.rb +22 -0
  19. data/lib/stratus/resources.rb +75 -0
  20. data/lib/stratus/settings.rb +19 -0
  21. data/lib/stratus/tags/markdown.rb +19 -0
  22. data/lib/stratus/tags/textile.rb +19 -0
  23. data/lib/stratus/tags.rb +3 -0
  24. data/lib/stratus/tasks/app/boilerplate/StratusSite +25 -0
  25. data/lib/stratus/tasks/app/boilerplate/config/defaults/page.default.html +10 -0
  26. data/lib/stratus/tasks/app/boilerplate/config/defaults/post.default.html +10 -0
  27. data/lib/stratus/tasks/app/boilerplate/config/site.yaml +16 -0
  28. data/lib/stratus/tasks/app/boilerplate/content/pages/home/index.html +35 -0
  29. data/lib/stratus/tasks/app/boilerplate/themes/default/styles/main.css +12 -0
  30. data/lib/stratus/tasks/app/boilerplate/themes/default/templates/layouts/main.html +31 -0
  31. data/lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/page.html +7 -0
  32. data/lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/page.index.html +10 -0
  33. data/lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/post.html +22 -0
  34. data/lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/post.index.html +10 -0
  35. data/lib/stratus/tasks/app/site.rake +68 -0
  36. data/lib/stratus/tasks/shared/system.rake +16 -0
  37. data/lib/stratus/tasks/site/new.rake +108 -0
  38. data/lib/stratus/tasks/site/site.rake +21 -0
  39. data/lib/stratus/tasks/site/theme.rake +13 -0
  40. data/lib/stratus.rb +62 -0
  41. data/stratus.gemspec +31 -0
  42. data/test/fixtures/site/StratusSite +26 -0
  43. data/test/fixtures/site/config/defaults/article.default.html +7 -0
  44. data/test/fixtures/site/config/defaults/content.default.html +7 -0
  45. data/test/fixtures/site/config/defaults/page.default.html +10 -0
  46. data/test/fixtures/site/config/defaults/post.default.html +10 -0
  47. data/test/fixtures/site/config/site.yaml +25 -0
  48. data/test/fixtures/site/content/articles/001_im-the-title/index.html +10 -0
  49. data/test/fixtures/site/content/pages/about/index.html +7 -0
  50. data/test/fixtures/site/content/pages/home/index.html +37 -0
  51. data/test/fixtures/site/content/pages/projects/index.html +6 -0
  52. data/test/fixtures/site/content/posts/001_new-blog/dom.js +123 -0
  53. data/test/fixtures/site/content/posts/001_new-blog/index.html +24 -0
  54. data/test/fixtures/site/content/posts/001_new-blog/old.html +18 -0
  55. data/test/fixtures/site/content/posts/002_fun-for-the-whole-family/index.html +12 -0
  56. data/test/fixtures/site/content/posts/002_fun-for-the-whole-family/snippet_one.rb +5 -0
  57. data/test/fixtures/site/content/posts/003_life-is-quite-fun-really/index.html +12 -0
  58. data/test/fixtures/site/themes/default/scripts/code_highlighter.js +188 -0
  59. data/test/fixtures/site/themes/default/scripts/code_syntax.js +92 -0
  60. data/test/fixtures/site/themes/default/styles/code_syntax.css +68 -0
  61. data/test/fixtures/site/themes/default/styles/main.css +66 -0
  62. data/test/fixtures/site/themes/default/templates/layouts/main.html +36 -0
  63. data/test/fixtures/site/themes/default/templates/objects/article.html +7 -0
  64. data/test/fixtures/site/themes/default/templates/objects/article.index.html +8 -0
  65. data/test/fixtures/site/themes/default/templates/objects/feed.xml +25 -0
  66. data/test/fixtures/site/themes/default/templates/objects/page.html +7 -0
  67. data/test/fixtures/site/themes/default/templates/objects/page.index.html +10 -0
  68. data/test/fixtures/site/themes/default/templates/objects/post.html +22 -0
  69. data/test/fixtures/site/themes/default/templates/objects/post.index.html +10 -0
  70. data/test/fixtures/site/www/index.html +82 -0
  71. data/test/fixtures/site/www/pages/about/index.html +43 -0
  72. data/test/fixtures/site/www/pages/home/index.html +82 -0
  73. data/test/fixtures/site/www/pages/index.html +52 -0
  74. data/test/fixtures/site/www/pages/projects/index.html +43 -0
  75. data/test/fixtures/site/www/posts/fun-for-the-whole-family/index.html +66 -0
  76. data/test/fixtures/site/www/posts/fun-for-the-whole-family/snippet_one.rb +5 -0
  77. data/test/fixtures/site/www/posts/index.html +63 -0
  78. data/test/fixtures/site/www/posts/life-is-quite-fun-really/index.html +58 -0
  79. data/test/fixtures/site/www/posts/new-blog/dom.js +123 -0
  80. data/test/fixtures/site/www/posts/new-blog/index.html +192 -0
  81. data/test/fixtures/site/www/posts/new-blog/old.html +18 -0
  82. data/test/fixtures/site/www/theme/scripts/code_highlighter.js +188 -0
  83. data/test/fixtures/site/www/theme/scripts/code_syntax.js +92 -0
  84. data/test/fixtures/site/www/theme/styles/code_syntax.css +68 -0
  85. data/test/fixtures/site/www/theme/styles/main.css +66 -0
  86. data/test/fixtures/site/www/themes/default/styles/main.css +62 -0
  87. data/test/test_helper.rb +0 -0
  88. metadata +143 -0
data/Changelog ADDED
@@ -0,0 +1,3 @@
1
+ 2008-12-11 18:37:01 -0600
2
+ Initial import of stratus
3
+
data/Manifest ADDED
@@ -0,0 +1,87 @@
1
+ Changelog
2
+ Manifest
3
+ Rakefile
4
+ Readme.markdown
5
+ bin/stratus
6
+ lib/stratus.rb
7
+ lib/stratus/cli.rb
8
+ lib/stratus/filters.rb
9
+ lib/stratus/generator.rb
10
+ lib/stratus/generator/builder.rb
11
+ lib/stratus/generator/context.rb
12
+ lib/stratus/generator/renderer.rb
13
+ lib/stratus/generator/scanner.rb
14
+ lib/stratus/resources.rb
15
+ lib/stratus/resources/attachment.rb
16
+ lib/stratus/resources/base.rb
17
+ lib/stratus/resources/content.rb
18
+ lib/stratus/resources/hash_db.rb
19
+ lib/stratus/resources/layout.rb
20
+ lib/stratus/resources/template.rb
21
+ lib/stratus/settings.rb
22
+ lib/stratus/tags.rb
23
+ lib/stratus/tags/markdown.rb
24
+ lib/stratus/tags/textile.rb
25
+ lib/stratus/tasks/app/boilerplate/StratusSite
26
+ lib/stratus/tasks/app/boilerplate/config/defaults/page.default.html
27
+ lib/stratus/tasks/app/boilerplate/config/defaults/post.default.html
28
+ lib/stratus/tasks/app/boilerplate/config/site.yaml
29
+ lib/stratus/tasks/app/boilerplate/content/pages/home/index.html
30
+ lib/stratus/tasks/app/boilerplate/themes/default/styles/main.css
31
+ lib/stratus/tasks/app/boilerplate/themes/default/templates/layouts/main.html
32
+ lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/page.html
33
+ lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/page.index.html
34
+ lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/post.html
35
+ lib/stratus/tasks/app/boilerplate/themes/default/templates/objects/post.index.html
36
+ lib/stratus/tasks/app/site.rake
37
+ lib/stratus/tasks/shared/system.rake
38
+ lib/stratus/tasks/site/new.rake
39
+ lib/stratus/tasks/site/site.rake
40
+ lib/stratus/tasks/site/theme.rake
41
+ stratus.gemspec
42
+ test/fixtures/site/StratusSite
43
+ test/fixtures/site/config/defaults/article.default.html
44
+ test/fixtures/site/config/defaults/content.default.html
45
+ test/fixtures/site/config/defaults/page.default.html
46
+ test/fixtures/site/config/defaults/post.default.html
47
+ test/fixtures/site/config/site.yaml
48
+ test/fixtures/site/content/articles/001_im-the-title/index.html
49
+ test/fixtures/site/content/pages/about/index.html
50
+ test/fixtures/site/content/pages/home/index.html
51
+ test/fixtures/site/content/pages/projects/index.html
52
+ test/fixtures/site/content/posts/001_new-blog/dom.js
53
+ test/fixtures/site/content/posts/001_new-blog/index.html
54
+ test/fixtures/site/content/posts/001_new-blog/old.html
55
+ test/fixtures/site/content/posts/002_fun-for-the-whole-family/index.html
56
+ test/fixtures/site/content/posts/002_fun-for-the-whole-family/snippet_one.rb
57
+ test/fixtures/site/content/posts/003_life-is-quite-fun-really/index.html
58
+ test/fixtures/site/themes/default/scripts/code_highlighter.js
59
+ test/fixtures/site/themes/default/scripts/code_syntax.js
60
+ test/fixtures/site/themes/default/styles/code_syntax.css
61
+ test/fixtures/site/themes/default/styles/main.css
62
+ test/fixtures/site/themes/default/templates/layouts/main.html
63
+ test/fixtures/site/themes/default/templates/objects/article.html
64
+ test/fixtures/site/themes/default/templates/objects/article.index.html
65
+ test/fixtures/site/themes/default/templates/objects/feed.xml
66
+ test/fixtures/site/themes/default/templates/objects/page.html
67
+ test/fixtures/site/themes/default/templates/objects/page.index.html
68
+ test/fixtures/site/themes/default/templates/objects/post.html
69
+ test/fixtures/site/themes/default/templates/objects/post.index.html
70
+ test/fixtures/site/www/index.html
71
+ test/fixtures/site/www/pages/about/index.html
72
+ test/fixtures/site/www/pages/home/index.html
73
+ test/fixtures/site/www/pages/index.html
74
+ test/fixtures/site/www/pages/projects/index.html
75
+ test/fixtures/site/www/posts/fun-for-the-whole-family/index.html
76
+ test/fixtures/site/www/posts/fun-for-the-whole-family/snippet_one.rb
77
+ test/fixtures/site/www/posts/index.html
78
+ test/fixtures/site/www/posts/life-is-quite-fun-really/index.html
79
+ test/fixtures/site/www/posts/new-blog/dom.js
80
+ test/fixtures/site/www/posts/new-blog/index.html
81
+ test/fixtures/site/www/posts/new-blog/old.html
82
+ test/fixtures/site/www/theme/scripts/code_highlighter.js
83
+ test/fixtures/site/www/theme/scripts/code_syntax.js
84
+ test/fixtures/site/www/theme/styles/code_syntax.css
85
+ test/fixtures/site/www/theme/styles/main.css
86
+ test/fixtures/site/www/themes/default/styles/main.css
87
+ test/test_helper.rb
data/Rakefile ADDED
@@ -0,0 +1,82 @@
1
+ $: << 'lib'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/gempackagetask'
5
+ require 'stratus'
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "A simple static blog building tool."
10
+ s.name = 'stratus'
11
+ s.version = Stratus::VERSION
12
+ s.author = 'M@ McCray'
13
+ s.email = 'darthapo@gmail.com'
14
+ s.homepage = 'http://github.com/darthapo/stratus/wikis'
15
+
16
+ s.requirements << 'rake'
17
+ s.requirements << 'active_support'
18
+ s.requirements << 'chronic'
19
+ s.requirements << 'hpricot'
20
+ s.requirements << 'liquid'
21
+ s.require_path = 'lib'
22
+ s.autorequire = 'rake'
23
+ s.files = File.read("Manifest").split
24
+ s.executables = s.files.grep(/bin/) { |f| File.basename(f) }
25
+ s.description = <<EOF
26
+ A simple static blog building tool.
27
+ EOF
28
+ end
29
+
30
+ Rake::GemPackageTask.new(spec) do |pkg|
31
+ pkg.need_zip = true
32
+ pkg.need_tar = true
33
+ end
34
+
35
+ namespace :gem do
36
+ desc "Create the gemspec file"
37
+ task :spec do
38
+ File.open("stratus.gemspec", "w") do |file|
39
+ file.puts spec.to_ruby
40
+ end
41
+ end
42
+ end
43
+
44
+ desc 'Clean up'
45
+ task :clean => :clobber_package do
46
+ %w(diff diff email ri *.gem **/*~).each do |pattern|
47
+ files = Dir[pattern]
48
+ rm_rf files unless files.empty?
49
+ end
50
+ end
51
+
52
+ namespace :manifest do
53
+ desc "Verify the manifest"
54
+ task :check => :clean do
55
+ f = "Manifest.tmp"
56
+ require 'find'
57
+ files = []
58
+ Find.find '.' do |path|
59
+ next unless File.file? path
60
+ next if path =~ /\.git|tmp$|\.DS_Store/
61
+ files << path[2..-1]
62
+ end
63
+ files = files.sort.join "\n"
64
+ File.open f, 'w' do |fp| fp.puts files end
65
+ system "diff -du Manifest #{f}"
66
+ rm f
67
+ end
68
+
69
+ desc "Create the manifest"
70
+ task :create => :clean do
71
+ f = "Manifest"
72
+ require 'find'
73
+ files = []
74
+ Find.find '.' do |path|
75
+ next unless File.file? path
76
+ next if path =~ /\.git|tmp$|\.DS_Store/
77
+ files << path[2..-1]
78
+ end
79
+ files = files.sort.join "\n"
80
+ File.open f, 'w' do |fp| fp.puts files end
81
+ end
82
+ end
data/Readme.markdown ADDED
@@ -0,0 +1,15 @@
1
+ # Stratus
2
+
3
+ A static blog generation tool based on the ideas from Cumulus (http://github.com/darthapo/cumulus).
4
+
5
+ And yes, I know, I'm on a weird cloud kick.
6
+
7
+ # Todo
8
+
9
+
10
+ * Read default content templates from config/defaults/
11
+ * RSS/Atom feed generation
12
+ * Incremental rendering
13
+ * Publishing (S/FTP)
14
+ * Tagging support (limited)
15
+ * Category support (limited)
data/bin/stratus ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2008 M@ McCray. All rights reserved.
4
+ $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
5
+ require "stratus"
6
+ require "stratus/cli"
7
+
8
+ Stratus::CLI.run(ARGV)
@@ -0,0 +1,206 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require 'rake'
4
+
5
+ module Stratus
6
+
7
+ class CLI
8
+
9
+ def initialize(out)
10
+ @out = out
11
+ @mode = :site
12
+ end
13
+
14
+ def run(args)
15
+ args = args.dup
16
+ parse args
17
+ init args
18
+ rake
19
+ end
20
+
21
+ # Parse the command line _args_ for options and commands to invoke.
22
+ def parse( args )
23
+ opts = OptionParser.new
24
+ opts.banner = 'Usage: stratus [options] target [target args]'
25
+
26
+ opts.separator ''
27
+
28
+ desired_opts = %[--describe --prereqs --tasks --trace]
29
+ app.standard_rake_options.each do |options|
30
+ next unless desired_opts.include?(options.first)
31
+ opts.on(*options)
32
+ end
33
+
34
+ opts.separator ''
35
+ opts.separator 'common options:'
36
+
37
+ opts.on_tail( '-h', '--help', 'show this message' ) do
38
+ @out.puts opts
39
+ exit
40
+ end
41
+ opts.on_tail( '--version', 'show version' ) do
42
+ @out.puts "Stratus #{::Stratus::VERSION}"
43
+ exit
44
+ end
45
+
46
+ begin
47
+ opts.parse! args
48
+ rescue OptionParser::InvalidOption => ex
49
+ puts "!! #{ex}"
50
+ end
51
+
52
+
53
+ ARGV.replace Array(args.shift)
54
+ args.delete_if do |arg|
55
+ if %r/^[A-Z_]+=/ =~ arg
56
+ ARGV << arg
57
+ next true
58
+ end
59
+ false
60
+ end
61
+
62
+ args
63
+ end
64
+
65
+ # Initialize the Rake application object and load the core rake tasks, the
66
+ # site specific rake tasks, and the site specific ruby code. Any extra
67
+ # command line arguments are converted into a page name and directory that
68
+ # might get created (depending upon the task invoked).
69
+ def init( args )
70
+ # Make sure we're in a folder with a Sitefile
71
+ options = app.standard_rake_options
72
+ [['--rakefile', 'StratusSite'],
73
+ ['--no-search', nil],
74
+ ['--silent', nil]].each {|opt, value| options.assoc(opt).last.call(value)}
75
+
76
+ unless app.have_rakefile
77
+ @mode = :app
78
+ end
79
+
80
+ import_default_tasks
81
+ import_website_tasks
82
+ require_lib_files
83
+ capture_command_line_args(args)
84
+
85
+ # if args.length == 0 && @mode == :app
86
+ # puts "Try using:\n stratus -T"
87
+ # end
88
+
89
+ args
90
+ end
91
+
92
+ # Execute the rake command.
93
+ #
94
+ def rake
95
+ app.init 'stratus'
96
+ app.load_rakefile
97
+ app.top_level
98
+ end
99
+
100
+ # Return the Rake application object.
101
+ #
102
+ def app
103
+ Rake.application
104
+ end
105
+
106
+ # Returns the options hash from the Rake application object.
107
+ #
108
+ def options
109
+ app.options
110
+ end
111
+
112
+ def import_default_tasks
113
+ path = (@mode == :app)? %w(stratus tasks app *.rake) : %w(stratus tasks site *.rake)
114
+ Dir.glob(::Stratus.libpath(path)).sort.each {|fn| load fn}
115
+ Dir.glob(::Stratus.libpath(%w(stratus tasks shared *.rake))).sort.each {|fn| load fn}
116
+ end
117
+
118
+ def import_website_tasks
119
+ return if (@mode == :app)
120
+ Dir.glob(::File.join(%w[tasks *.rake])).sort.each {|fn| load fn}
121
+ end
122
+
123
+ def require_lib_files
124
+ return if (@mode == :app)
125
+ Dir.glob(::File.join(%w[lib ** *.rb])).sort.each {|fn| require fn}
126
+ end
127
+
128
+ def capture_command_line_args(args)
129
+ ::Stratus.args = args # set the args in a place where all rake tasks can read 'em
130
+ ::Stratus.site_path = File.expand_path('.')
131
+ args
132
+ end
133
+
134
+ class << self
135
+ def run(args, out=STDOUT)
136
+ self.new(out).run(args)
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+
145
+ # :stopdoc:
146
+ # Monkey patches so that rake displays the correct application name in the
147
+ # help messages.
148
+ #
149
+ class Rake::Application
150
+ def display_prerequisites
151
+ tasks.each do |t|
152
+ puts "#{name} #{t.name}"
153
+ t.prerequisites.each { |pre| puts " #{pre}" }
154
+ end
155
+ end
156
+
157
+ def display_tasks_and_comments
158
+ displayable_tasks = tasks.select { |t|
159
+ t.comment && t.name =~ options.show_task_pattern
160
+ }
161
+ if options.full_description
162
+ displayable_tasks.each do |t|
163
+ puts "#{name} #{t.name_with_args}"
164
+ t.full_comment.split("\n").each do |line|
165
+ puts " #{line}"
166
+ end
167
+ puts
168
+ end
169
+ else
170
+ width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
171
+ max_column = truncate_output? ? terminal_width - name.size - width - 7 : nil
172
+ displayable_tasks.each do |t|
173
+ printf "#{name} %-#{width}s # %s\n",
174
+ t.name_with_args, max_column ? truncate(t.comment, max_column) : t.comment
175
+ end
176
+ end
177
+ end
178
+
179
+ # Provide standard execption handling for the given block.
180
+ def standard_exception_handling
181
+ begin
182
+ yield
183
+ rescue SystemExit => ex
184
+ # Exit silently with current status
185
+ exit(ex.status)
186
+ rescue SystemExit, OptionParser::InvalidOption => ex
187
+ # Exit silently
188
+ exit(1)
189
+ rescue Exception => ex
190
+ return if ex.message =~ /Rakefile/
191
+ # Exit with error message
192
+ $stderr.puts "#{name} aborted!"
193
+ $stderr.puts "!> #{ex.message}"
194
+ if options.trace
195
+ $stderr.puts ex.backtrace.join("\n")
196
+ else
197
+ $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
198
+ $stderr.puts "(See full trace by running task with --trace)"
199
+ end
200
+ exit(1)
201
+ end
202
+ end
203
+ end # class Rake::Application
204
+ # :startdoc:
205
+
206
+ # EOF
@@ -0,0 +1,73 @@
1
+ module Stratus
2
+
3
+ module Filters
4
+
5
+ def short_date(date)
6
+ if date.respond_to? :strftime
7
+ date.strftime('%m/%d/%Y')
8
+ else
9
+ "<!-- ??/??/???? -->"
10
+ end
11
+ end
12
+
13
+ def date_to_xmlschema(date)
14
+ date.xmlschema
15
+ end
16
+
17
+ def xml_escape(input)
18
+ input.gsub("<", "&lt;").gsub(">", "&gt;")
19
+ end
20
+
21
+ def number_of_words(input)
22
+ input.split.length
23
+ end
24
+
25
+ EXTS = {
26
+ '.rb' => 'ruby',
27
+ '.css' => 'css',
28
+ '.js' => 'javascript',
29
+ '.html' => 'html',
30
+ '.xml' => 'html'
31
+ }
32
+ LANG_BY_EXT = Hash.new {|h,k| h[k] = EXTS.fetch(k, 'text') }
33
+
34
+ def sourcecode(input)
35
+ if input.is_a? Hash
36
+ source = IO.readlines( input['source_path'] ).join
37
+ %Q|<pre><code class="#{ LANG_BY_EXT[ input['ext'] ]}">#{source}</code></pre>|
38
+ else
39
+ "<pre><code>#{input}</code></pre>"
40
+ end
41
+ end
42
+
43
+ def url(input)
44
+ base_url = Stratus.settings('base_url', nil, 'feed')
45
+ if input.is_a? Hash
46
+ "#{base_url}/#{input.full_path}"
47
+ else
48
+ "#{base_url}/#{input}"
49
+ end
50
+ end
51
+
52
+ def uri(input)
53
+ if input.is_a? Hash
54
+ "/#{input.full_path}"
55
+ else
56
+ "/#{input}"
57
+ end
58
+ end
59
+
60
+ def uri_rel(input)
61
+ case input
62
+ when Hash
63
+ "#{Stratus::Generator::LiquidContext.path_to_root}#{input['full_path']}"
64
+ when Array
65
+ "#{Stratus::Generator::LiquidContext.path_to_root}#{input[0]['collection_type']}/index.html"
66
+ else
67
+ "#{Stratus::Generator::LiquidContext.path_to_root}#{input}"
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,147 @@
1
+ module Stratus::Generator
2
+
3
+ class Builder
4
+
5
+ def initialize(root_path, verbose=true)
6
+ @root_path = root_path
7
+ @verbose = verbose
8
+ end
9
+
10
+ def execute
11
+ info "Scanning source structure..."
12
+ scanner = Stratus::Generator::Scanner.new(@root_path)
13
+ scanner.sweep
14
+
15
+ info "Rendering output..."
16
+ make_dir Stratus.output_dir
17
+ Stratus::Resources.posts.each do |r|
18
+ output = renderer.render_content( r )
19
+ write_file r.output_path, fix_up_paths(output)
20
+ # Copy attachments
21
+ r.attachments.each do |attachment|
22
+ copy_file attachment.source_path, attachment.output_path
23
+ end
24
+
25
+ end
26
+ output = renderer.render_index_for( 'posts', 'index' )
27
+ write_file Stratus.output_dir('posts', 'index.html'), fix_up_paths(output)
28
+
29
+ Stratus::Resources.pages.each do |r|
30
+ output = renderer.render_content( r )
31
+ write_file r.output_path, fix_up_paths(output)
32
+ # Copy attachments
33
+ r.attachments.each do |attachment|
34
+ copy_file attachment.source_path, attachment.output_path
35
+ end
36
+ end
37
+ output = renderer.render_index_for( 'pages', 'index' )
38
+ write_file Stratus.output_dir('pages', 'index.html'), fix_up_paths(output)
39
+
40
+ # Render HOME
41
+ home = Stratus::Resources.homepage
42
+ if home
43
+ output = renderer.render_content( home, '' )
44
+ #output = renderer.render_index_for( 'home', nil )
45
+ write_file Stratus.output_dir('index.html'), fix_up_paths(output)
46
+ else
47
+ puts "NO HOME PAGE DEFINED! UPDATE YOUR CONFIG FILE!!!"
48
+ end
49
+ # TODO: Render FEED
50
+
51
+ copy_theme_files
52
+
53
+ #pp Stratus::Resources.all.db
54
+ end
55
+
56
+ def copy_theme_files
57
+ delete_file Stratus.output_dir('theme'), true
58
+ theme = Stratus.setting('theme', 'default')
59
+ copy_file Stratus.site_path('themes', theme, 'images'), Stratus.output_dir('theme', 'images')
60
+ copy_file Stratus.site_path('themes', theme, 'styles'), Stratus.output_dir('theme', 'styles')
61
+ copy_file Stratus.site_path('themes', theme, 'scripts'), Stratus.output_dir('theme', 'scripts')
62
+ end
63
+
64
+ protected
65
+
66
+ def renderer
67
+ @renderer ||= LiquidRenderer.new
68
+ end
69
+
70
+
71
+ # Use logging?
72
+ def info(msg, alt=nil)
73
+ if @verbose
74
+ puts msg
75
+ else
76
+ puts alt unless alt.nil?
77
+ end
78
+ end
79
+
80
+ def error
81
+ puts msg
82
+ end
83
+
84
+ def fatal
85
+ puts msg
86
+ end
87
+
88
+ def fix_up_paths(output, path_to_root='/')
89
+ # doc = Hpricot(output)
90
+ # doc.search("//[@src]") do |elem|
91
+ # unless elem[:src] =~ /^(http|mailto|\/)/
92
+ # puts "src: #{elem[:src]}"
93
+ # end
94
+ # end
95
+ # puts "looking for @href"
96
+ # doc.search("//[@href]") do |elem|
97
+ # unless elem[:href] =~ /^(http|mailto|\/)/
98
+ # puts "href: #{elem[:href]}"
99
+ # end
100
+ # end
101
+ #
102
+ # doc.to_html
103
+ output
104
+ end
105
+
106
+ # ================
107
+ # = File Helpers =
108
+ # ================
109
+
110
+ def make_dir(path)
111
+ FileUtils.mkdir_p( path )# unless File.exists?(path)
112
+ end
113
+
114
+ def write_file(path, contents)
115
+ make_dir( File.dirname( path ) )
116
+ File.open( path, 'w' ) do |f|
117
+ f.write( contents )
118
+ info(" + #{ path }", '.')
119
+ end
120
+ end
121
+
122
+ def copy_file(path, to)
123
+ make_dir( File.dirname( to ) )
124
+ FileUtils.cp_r path, to
125
+ info(" - #{ to }", '.')
126
+ end
127
+
128
+ def delete_file(path, force=false)
129
+ if force
130
+ FileUtils.rm_rf( path )
131
+ else
132
+ FileUtils.rm( path )
133
+ end
134
+ info(" x #{ path }", '.')
135
+ end
136
+
137
+ end
138
+
139
+ class << self
140
+
141
+ def build(root_path)
142
+ Builder.new(root_path).execute
143
+ end
144
+
145
+ end
146
+
147
+ end
@@ -0,0 +1,39 @@
1
+ module Stratus::Generator
2
+
3
+ # ==========
4
+ # = Liquid =
5
+ # ==========
6
+ class LiquidContext < Hash
7
+
8
+ def initialize
9
+ super
10
+ self.merge!({
11
+ 'site' => Stratus.settings['site'],
12
+ 'posts' => Stratus::Resources.posts(:sort_by=>:publish_date, :reverse=>true),
13
+ 'post' => hashify( Stratus::Resources.posts ),
14
+ 'pages' => Stratus::Resources.pages(:sort_by=>:title),
15
+ 'page' => hashify( Stratus::Resources.pages )
16
+ })
17
+ self
18
+ end
19
+
20
+ def self.path_to_root
21
+ @@path_to_root ||= ''
22
+ end
23
+ def self.path_to_root=(path)
24
+ @@path_to_root = path
25
+ end
26
+
27
+ protected
28
+
29
+ def hashify(list)
30
+ returning({}) do |h|
31
+ list.each do |item|
32
+ h[item.slug] = item
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end