darthapo-cumulus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +45 -0
  3. data/PostInstall.txt +2 -0
  4. data/README.rdoc +56 -0
  5. data/Rakefile +39 -0
  6. data/bin/cumulus +11 -0
  7. data/bin/cumulus-gen +11 -0
  8. data/cumulus.gemspec +55 -0
  9. data/lib/cumulus.rb +29 -0
  10. data/lib/cumulus/builder.rb +121 -0
  11. data/lib/cumulus/cli.rb +64 -0
  12. data/lib/cumulus/hash_db.rb +137 -0
  13. data/lib/cumulus/resources.rb +46 -0
  14. data/lib/cumulus/resources/attachment.rb +35 -0
  15. data/lib/cumulus/resources/base_resource.rb +105 -0
  16. data/lib/cumulus/resources/content.rb +50 -0
  17. data/lib/cumulus/resources/layout.rb +29 -0
  18. data/lib/cumulus/resources/skin.rb +7 -0
  19. data/lib/cumulus/resources/template.rb +35 -0
  20. data/lib/cumulus/scanner.rb +65 -0
  21. data/lib/support/trollop.rb +694 -0
  22. data/script/console +10 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/test/fixtures/my_site/Rakefile +27 -0
  26. data/test/fixtures/my_site/config/content.yml +3 -0
  27. data/test/fixtures/my_site/config/publishing.yml +0 -0
  28. data/test/fixtures/my_site/config/site.yml +3 -0
  29. data/test/fixtures/my_site/content/articles/about/index.html +14 -0
  30. data/test/fixtures/my_site/content/articles/about/test.rb +11 -0
  31. data/test/fixtures/my_site/content/posts/001-hello-world/index.html +20 -0
  32. data/test/fixtures/my_site/output/articles/about/index.html +31 -0
  33. data/test/fixtures/my_site/output/articles/about/test.rb +11 -0
  34. data/test/fixtures/my_site/output/posts/001-hello-world/index.html +40 -0
  35. data/test/fixtures/my_site/skin/styles/screen.css +3 -0
  36. data/test/fixtures/my_site/skin/templates/layouts/main.html +21 -0
  37. data/test/fixtures/my_site/skin/templates/objects/article.html +7 -0
  38. data/test/fixtures/my_site/skin/templates/objects/article.summary.html +7 -0
  39. data/test/fixtures/my_site/skin/templates/objects/post.html +10 -0
  40. data/test/fixtures/my_site/skin/templates/objects/post.summary.html +7 -0
  41. data/test/test_helper.rb +5 -0
  42. data/test/unit/cumulus_cli_test.rb +22 -0
  43. data/test/unit/cumulus_test.rb +15 -0
  44. data/test/unit/hash_db_test.rb +29 -0
  45. metadata +167 -0
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-12-08
2
+
3
+ * 0 features complete:
4
+ * Initial import
@@ -0,0 +1,45 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/cumulus
7
+ bin/cumulus-gen
8
+ cumulus.gemspec
9
+ lib/cumulus.rb
10
+ lib/cumulus/builder.rb
11
+ lib/cumulus/cli.rb
12
+ lib/cumulus/hash_db.rb
13
+ lib/cumulus/resources.rb
14
+ lib/cumulus/resources/attachment.rb
15
+ lib/cumulus/resources/base_resource.rb
16
+ lib/cumulus/resources/content.rb
17
+ lib/cumulus/resources/layout.rb
18
+ lib/cumulus/resources/skin.rb
19
+ lib/cumulus/resources/template.rb
20
+ lib/cumulus/scanner.rb
21
+ lib/support/trollop.rb
22
+ script/console
23
+ script/destroy
24
+ script/generate
25
+ test/fixtures/my_site/Rakefile
26
+ test/fixtures/my_site/config/content.yml
27
+ test/fixtures/my_site/config/publishing.yml
28
+ test/fixtures/my_site/config/site.yml
29
+ test/fixtures/my_site/content/articles/about/index.html
30
+ test/fixtures/my_site/content/articles/about/test.rb
31
+ test/fixtures/my_site/content/posts/001-hello-world/index.html
32
+ test/fixtures/my_site/output/articles/about/index.html
33
+ test/fixtures/my_site/output/articles/about/test.rb
34
+ test/fixtures/my_site/output/posts/001-hello-world/index.html
35
+ test/fixtures/my_site/skin/styles/screen.css
36
+ test/fixtures/my_site/skin/templates/layouts/home.html
37
+ test/fixtures/my_site/skin/templates/layouts/main.html
38
+ test/fixtures/my_site/skin/templates/objects/article.html
39
+ test/fixtures/my_site/skin/templates/objects/article.summary.html
40
+ test/fixtures/my_site/skin/templates/objects/post.html
41
+ test/fixtures/my_site/skin/templates/objects/post.summary.html
42
+ test/test_helper.rb
43
+ test/unit/cumulus_cli_test.rb
44
+ test/unit/cumulus_test.rb
45
+ test/unit/hash_db_test.rb
@@ -0,0 +1,2 @@
1
+
2
+ For more information on cumulus, see http://github.com/darthapo/cumulus/wikis
@@ -0,0 +1,56 @@
1
+ = Cumulus
2
+
3
+ http://github.com/darthapo/cumulus
4
+
5
+ == DESCRIPTION:
6
+
7
+ **Non Functional / Still in Planning Stage**
8
+
9
+ Here's the high-level (brain dump):
10
+
11
+ * Site content is organized in collections
12
+ * Collections are serialized
13
+ * Each have support for next, previous, first, last, etc
14
+ * The content files are HTML
15
+ * Templates are object based (each content type can be rendered with their own templates)
16
+ * Templates are HTML with interspersed Liquid markup
17
+ * All meta data is described using HTML meta tags
18
+ * You custom meta data tags in a content objects
19
+ * You can specify 'prototype' content objects in a collection with a _proto folder in the collection
20
+
21
+
22
+ == REQUIREMENTS:
23
+
24
+ * hpricot >= 0.6
25
+ * liquid >= 1.9
26
+ * rake >= 0.8
27
+
28
+ == INSTALL:
29
+
30
+ gem sources -a http://gems.github.com
31
+ sudo gem install darthapo-cumulus
32
+
33
+ == LICENSE:
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) 2008 M@ McCray.
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ 'Software'), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, and/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ %w[rubygems rake rake/clean rake/testtask fileutils newgem rubigen shoulda/tasks].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/cumulus'
3
+
4
+
5
+ # Generate all the Rake tasks
6
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
+ $hoe = Hoe.new('cumulus', Cumulus::VERSION) do |p|
8
+ p.developer('M@ McCray', 'darthapo@gmail.com')
9
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
+ p.post_install_message = 'PostInstall.txt'
11
+ p.rubyforge_name = p.name
12
+ p.extra_deps = [
13
+ ['hpricot','>= 0.6'],
14
+ ['liquid', '>= 1.9'],
15
+ ['rake', '>= 0.8']
16
+ ]
17
+ p.extra_dev_deps = [
18
+ ['newgem', ">= #{::Newgem::VERSION}"],
19
+ ['shoulda', ">= 2.0"],
20
+ ['activesupport']
21
+ ]
22
+ p.test_globs = "test/**/*_test.rb"
23
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
24
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
25
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
26
+ p.rsync_args = '-av --delete --ignore-errors'
27
+ end
28
+
29
+ require 'newgem/tasks' # load /tasks/*.rake
30
+ Dir['tasks/**/*.rake'].each { |t| load t }
31
+
32
+ desc "Test shoulda specs"
33
+ Rake::TestTask.new('shoulda:specs') do |t|
34
+ t.libs << 'lib'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+ #task :default => ['shoulda:specs']
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-12-8.
4
+ # Copyright (c) 2008 M@ McCray. All rights reserved.
5
+
6
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/cumulus")
7
+
8
+ require "cumulus/cli"
9
+ CLI_MODE = :build
10
+
11
+ Cumulus::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-12-8.
4
+ # Copyright (c) 2008 M@ McCray. All rights reserved.
5
+
6
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/cumulus")
7
+
8
+ require "cumulus/cli"
9
+ CLI_MODE = :gen
10
+
11
+ Cumulus::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{cumulus}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["M@ McCray"]
9
+ s.date = %q{2008-12-09}
10
+ s.description = %q{**Non Functional / Still in Planning Stage** Here's the high-level (brain dump): * Site content is organized in collections * Collections are serialized * Each have support for next, previous, first, last, etc * The content files are HTML * Templates are object based (each content type can be rendered with their own templates) * Templates are HTML with interspersed Liquid markup * All meta data is described using HTML meta tags * You custom meta data tags in a content objects * You can specify 'prototype' content objects in a collection with a _proto folder in the collection}
11
+ s.email = ["darthapo@gmail.com"]
12
+ s.executables = ["cumulus", "cumulus-gen"]
13
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
14
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "bin/cumulus", "bin/cumulus-gen", "cumulus.gemspec", "lib/cumulus.rb", "lib/cumulus/builder.rb", "lib/cumulus/cli.rb", "lib/cumulus/hash_db.rb", "lib/cumulus/resources.rb", "lib/cumulus/resources/attachment.rb", "lib/cumulus/resources/base_resource.rb", "lib/cumulus/resources/content.rb", "lib/cumulus/resources/layout.rb", "lib/cumulus/resources/skin.rb", "lib/cumulus/resources/template.rb", "lib/cumulus/scanner.rb", "lib/support/trollop.rb", "script/console", "script/destroy", "script/generate", "test/fixtures/my_site/Rakefile", "test/fixtures/my_site/config/content.yml", "test/fixtures/my_site/config/publishing.yml", "test/fixtures/my_site/config/site.yml", "test/fixtures/my_site/content/articles/about/index.html", "test/fixtures/my_site/content/articles/about/test.rb", "test/fixtures/my_site/content/posts/001-hello-world/index.html", "test/fixtures/my_site/output/articles/about/index.html", "test/fixtures/my_site/output/articles/about/test.rb", "test/fixtures/my_site/output/posts/001-hello-world/index.html", "test/fixtures/my_site/skin/styles/screen.css", "test/fixtures/my_site/skin/templates/layouts/home.html", "test/fixtures/my_site/skin/templates/layouts/main.html", "test/fixtures/my_site/skin/templates/objects/article.html", "test/fixtures/my_site/skin/templates/objects/article.summary.html", "test/fixtures/my_site/skin/templates/objects/post.html", "test/fixtures/my_site/skin/templates/objects/post.summary.html", "test/test_helper.rb", "test/unit/cumulus_cli_test.rb", "test/unit/cumulus_test.rb", "test/unit/hash_db_test.rb"]
15
+ s.has_rdoc = true
16
+ s.homepage = %q{http://github.com/darthapo/cumulus}
17
+ s.post_install_message = %q{PostInstall.txt}
18
+ s.rdoc_options = ["--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{cumulus}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{**Non Functional / Still in Planning Stage** Here's the high-level (brain dump): * Site content is organized in collections * Collections are serialized * Each have support for next, previous, first, last, etc * The content files are HTML * Templates are object based (each content type can be rendered with their own templates) * Templates are HTML with interspersed Liquid markup * All meta data is described using HTML meta tags * You custom meta data tags in a content objects * You can specify 'prototype' content objects in a collection with a _proto folder in the collection}
23
+ s.test_files = ["test/unit/cumulus_cli_test.rb", "test/unit/cumulus_test.rb", "test/unit/hash_db_test.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.6"])
31
+ s.add_runtime_dependency(%q<liquid>, [">= 1.9"])
32
+ s.add_runtime_dependency(%q<rake>, [">= 0.8"])
33
+ s.add_development_dependency(%q<newgem>, [">= 1.1.0"])
34
+ s.add_development_dependency(%q<shoulda>, [">= 2.0"])
35
+ s.add_development_dependency(%q<activesupport>, [">= 0"])
36
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
37
+ else
38
+ s.add_dependency(%q<hpricot>, [">= 0.6"])
39
+ s.add_dependency(%q<liquid>, [">= 1.9"])
40
+ s.add_dependency(%q<rake>, [">= 0.8"])
41
+ s.add_dependency(%q<newgem>, [">= 1.1.0"])
42
+ s.add_dependency(%q<shoulda>, [">= 2.0"])
43
+ s.add_dependency(%q<activesupport>, [">= 0"])
44
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
45
+ end
46
+ else
47
+ s.add_dependency(%q<hpricot>, [">= 0.6"])
48
+ s.add_dependency(%q<liquid>, [">= 1.9"])
49
+ s.add_dependency(%q<rake>, [">= 0.8"])
50
+ s.add_dependency(%q<newgem>, [">= 1.1.0"])
51
+ s.add_dependency(%q<shoulda>, [">= 2.0"])
52
+ s.add_dependency(%q<activesupport>, [">= 0"])
53
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require 'pp'
4
+ require 'fileutils'
5
+ require 'liquid'
6
+ require 'active_support'
7
+
8
+ module Cumulus
9
+
10
+ VERSION = '0.0.1'
11
+
12
+ class << self
13
+
14
+ attr_accessor_with_default :output_dir, 'output'
15
+ attr_accessor_with_default :verbose, false
16
+ attr_accessor_with_default :dry_run, false
17
+
18
+ def config(&block)
19
+ self.instance_eval( &block )
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ require 'cumulus/resources'
27
+ require 'cumulus/scanner'
28
+ require 'cumulus/builder'
29
+ require 'cumulus/renderer'
@@ -0,0 +1,121 @@
1
+ # The builder class takes the resources and generates the output
2
+
3
+ require 'liquid/module_ex'
4
+
5
+ class Hash
6
+
7
+ end
8
+
9
+ module Cumulus
10
+
11
+ class Builder
12
+
13
+ attr_reader :options
14
+
15
+ def initialize(run_options={})
16
+ @options = {
17
+ :dry_run => false,
18
+ :verbose => false
19
+ }.merge!(run_options)
20
+ end
21
+
22
+ def execute
23
+ collection_types = {}
24
+ renderer = Cumulus::Renderer.new({})
25
+
26
+ Resources.collections.each do |content|
27
+ #content = content.clone
28
+ # Render content
29
+ output = nil
30
+ renderer.render_body(content)
31
+ template = renderer.template_for( content )
32
+ output = renderer.render(template, content, {'_content' => content})
33
+
34
+ # Render layout around content
35
+ layout = renderer.layout_for(template)
36
+ output = renderer.render(layout, output)
37
+
38
+ # Write to file
39
+ write_file content.output_path, output
40
+
41
+ # Copy attachments
42
+ content.attachments.each do |attachment|
43
+ copy_file attachment.source_path, attachment.output_path
44
+ end
45
+
46
+ collection_types[content.collection_type] ||= []
47
+ collection_types[content.collection_type] << content
48
+ end
49
+
50
+ collection_types.each do |coll, contents|
51
+ # Render the collection indices...
52
+ contents.map {|c| renderer.render_body(c) }
53
+ template = renderer.template_for( contents.first, 'index' )
54
+ source = renderer.render(template, '', {coll => contents, '_contents' => contents})
55
+
56
+ layout = renderer.layout_for(template)
57
+ output = renderer.render(layout, source)
58
+
59
+ write_file File.join(Cumulus.output_dir, coll, 'index.html'), output
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def temporarily_replace(content, value, field=:content)
66
+ old = content.metadata[field]
67
+ content.metadata[field] = value
68
+ yield
69
+ content.metadata[field] = old
70
+ end
71
+ # Use logging?
72
+ def info(msg, alt=nil)
73
+ if options[: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
+ # ================
89
+ # = File Helpers =
90
+ # ================
91
+
92
+ def make_dir(path)
93
+ FileUtils.mkdir_p( path )
94
+ end
95
+
96
+ def write_file(path, contents)
97
+ make_dir( File.dirname( path ) )
98
+ File.open( path, 'w' ) do |f|
99
+ f.write( contents )
100
+ info(" + #{ path }", '.')
101
+ end
102
+ end
103
+
104
+ def copy_file(path, to)
105
+ make_dir( File.dirname( path ) )
106
+ FileUtils.cp_r path, to
107
+ info(" - #{ to }", '.')
108
+ end
109
+
110
+ def delete_file(path, force=false)
111
+ if force
112
+ FileUtils.rm_rf( pathto )
113
+ else
114
+ FileUtils.rm_( pathto )
115
+ end
116
+ info(" x #{ path }", '.')
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,64 @@
1
+ require 'support/trollop'
2
+
3
+ # I'm thinking Trollop!
4
+ opts = Trollop::options do
5
+ version "cumulus #{Cumulus::VERSION} (c) 2008 M@ McCray"
6
+ banner <<-EOS
7
+ Usage:
8
+ cumulus#{" <path>" if CLI_MODE == :gen} [options]
9
+ where [options] are:
10
+ EOS
11
+
12
+ opt :verbose, "Generate output, loudly", :default => false
13
+ opt :force, "Force overwrite of all files", :default => false
14
+ opt :dry_run, "Don't write any files", :default => false
15
+
16
+ unless CLI_MODE == :gen
17
+ opt :theme, "Ignore config, render with specified theme", :default => false
18
+ end
19
+
20
+ # opt :file, "Extra data filename to read in, with a very long option description like this one", :type => String
21
+ # opt :volume, "Volume level", :default => 3.0
22
+ # opt :iters, "Number of iterations", :default => 5
23
+ end
24
+
25
+ # Trollop::die :volume, "must be non-negative" if opts[:volume] < 0
26
+ # Trollop::die :file, "must exist" unless File.exist?(opts[:file]) if opts[:file]
27
+
28
+ # module Cumulus
29
+ # class CLI
30
+ # def self.execute(stdout, arguments=[])
31
+ #
32
+ # # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
33
+ #
34
+ # options = {
35
+ # :path => '~'
36
+ # }
37
+ # mandatory_options = %w( )
38
+ #
39
+ # parser = OptionParser.new do |opts|
40
+ # opts.banner = <<-BANNER.gsub(/^ /,'')
41
+ # This application is wonderful because...
42
+ #
43
+ # Usage: #{File.basename($0)} [options]
44
+ #
45
+ # Options are:
46
+ # BANNER
47
+ # opts.separator ""
48
+ # opts.on("-p", "--path=PATH", String,
49
+ # "This is a sample message.",
50
+ # "For multiple lines, add more strings.",
51
+ # "Default: ~") { |arg| options[:path] = arg }
52
+ # opts.on("-h", "--help",
53
+ # "Show this help message.") { stdout.puts opts; exit }
54
+ # opts.parse!(arguments)
55
+ #
56
+ # if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
57
+ # stdout.puts opts; exit
58
+ # end
59
+ # end
60
+ #
61
+ # path = options[:path]
62
+ # end
63
+ # end
64
+ # end