bonsai 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
- $KCODE = "U"
1
+ # coding: utf-8
2
+
2
3
  require 'rubygems'
3
4
  require 'rake'
4
5
 
@@ -16,6 +17,7 @@ begin
16
17
  gem.add_development_dependency "yard", ">= 0"
17
18
  gem.add_dependency "tilt", ">= 0.4"
18
19
  gem.add_dependency "mustache", ">= 0.5.0"
20
+ gem.add_dependency "builder", ">= 2.1.2"
19
21
  gem.add_dependency "thin", ">= 1.0.0"
20
22
  gem.add_dependency "watch", ">= 0.1.0"
21
23
  gem.add_dependency "sinatra", ">= 0.9.4"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
data/bin/bonsai CHANGED
@@ -1,4 +1,5 @@
1
- #!/usr/bin/env ruby -KU
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
2
3
 
3
4
  require 'optparse'
4
5
  require 'bonsai'
data/bonsai.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bonsai}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Schwarz"]
12
- s.date = %q{2010-01-02}
12
+ s.date = %q{2010-01-05}
13
13
  s.default_executable = %q{bonsai}
14
14
  s.description = %q{A static site generator that uses the best toolset available}
15
15
  s.email = %q{ben.schwarz@gmail.com}
@@ -35,10 +35,13 @@ Gem::Specification.new do |s|
35
35
  "lib/bonsai/generate.rb",
36
36
  "lib/bonsai/navigation.rb",
37
37
  "lib/bonsai/page.rb",
38
+ "lib/bonsai/sitemap.rb",
38
39
  "lib/bonsai/template.rb",
39
40
  "lib/bonsai/templates/content/index/default.yml",
40
41
  "lib/bonsai/templates/public/.htaccess",
41
42
  "lib/bonsai/templates/public/docs/css/base.less",
43
+ "lib/bonsai/templates/public/robots.txt",
44
+ "lib/bonsai/templates/site.yml",
42
45
  "lib/bonsai/templates/templates/default.mustache",
43
46
  "lib/bonsai/webserver.rb",
44
47
  "spec/bonsai/console_spec.rb",
@@ -46,11 +49,18 @@ Gem::Specification.new do |s|
46
49
  "spec/bonsai/generate_spec.rb",
47
50
  "spec/bonsai/navigation_spec.rb",
48
51
  "spec/bonsai/page_spec.rb",
52
+ "spec/bonsai/sitemap_spec.rb",
49
53
  "spec/bonsai/template_spec.rb",
50
54
  "spec/bonsai_spec.rb",
51
55
  "spec/spec.opts",
52
56
  "spec/spec_helper.rb",
53
57
  "spec/support/broken/content/broken_page/demo-template.yml",
58
+ "spec/support/broken/site.yml",
59
+ "spec/support/broken/templates/content/index/default.yml",
60
+ "spec/support/broken/templates/public/.htaccess",
61
+ "spec/support/broken/templates/public/docs/css/base.less",
62
+ "spec/support/broken/templates/public/robots.txt",
63
+ "spec/support/broken/templates/templates/default.mustache",
54
64
  "spec/support/content/1.about-us/1.contact/1.child/a_file_asset.txt",
55
65
  "spec/support/content/1.about-us/1.contact/1.child/demo-template.yml",
56
66
  "spec/support/content/1.about-us/1.contact/demo-template.yml",
@@ -76,6 +86,7 @@ Gem::Specification.new do |s|
76
86
  "spec/support/public/js/script.js",
77
87
  "spec/support/public/stylesheets/base.less",
78
88
  "spec/support/public/stylesheets/broken.less",
89
+ "spec/support/site.yml",
79
90
  "spec/support/templates/demo-template.mustache",
80
91
  "spec/support/templates/partials/inserted.mustache",
81
92
  "vendor/yui-compressor/yuicompressor-2.4.2.jar"
@@ -100,6 +111,7 @@ Gem::Specification.new do |s|
100
111
  "spec/bonsai/generate_spec.rb",
101
112
  "spec/bonsai/navigation_spec.rb",
102
113
  "spec/bonsai/page_spec.rb",
114
+ "spec/bonsai/sitemap_spec.rb",
103
115
  "spec/bonsai/template_spec.rb",
104
116
  "spec/bonsai_spec.rb",
105
117
  "spec/spec_helper.rb"
@@ -114,6 +126,7 @@ Gem::Specification.new do |s|
114
126
  s.add_development_dependency(%q<yard>, [">= 0"])
115
127
  s.add_runtime_dependency(%q<tilt>, [">= 0.4"])
116
128
  s.add_runtime_dependency(%q<mustache>, [">= 0.5.0"])
129
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
117
130
  s.add_runtime_dependency(%q<thin>, [">= 1.0.0"])
118
131
  s.add_runtime_dependency(%q<watch>, [">= 0.1.0"])
119
132
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
@@ -124,6 +137,7 @@ Gem::Specification.new do |s|
124
137
  s.add_dependency(%q<yard>, [">= 0"])
125
138
  s.add_dependency(%q<tilt>, [">= 0.4"])
126
139
  s.add_dependency(%q<mustache>, [">= 0.5.0"])
140
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
127
141
  s.add_dependency(%q<thin>, [">= 1.0.0"])
128
142
  s.add_dependency(%q<watch>, [">= 0.1.0"])
129
143
  s.add_dependency(%q<sinatra>, [">= 0.9.4"])
@@ -135,6 +149,7 @@ Gem::Specification.new do |s|
135
149
  s.add_dependency(%q<yard>, [">= 0"])
136
150
  s.add_dependency(%q<tilt>, [">= 0.4"])
137
151
  s.add_dependency(%q<mustache>, [">= 0.5.0"])
152
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
138
153
  s.add_dependency(%q<thin>, [">= 1.0.0"])
139
154
  s.add_dependency(%q<watch>, [">= 0.1.0"])
140
155
  s.add_dependency(%q<sinatra>, [">= 0.9.4"])
@@ -24,6 +24,8 @@ module Bonsai
24
24
  compress_assets
25
25
  write_index
26
26
  write_pages
27
+ write_sitemap
28
+ write_readme
27
29
  cleanup
28
30
  end
29
31
 
@@ -54,6 +56,24 @@ module Bonsai
54
56
  end
55
57
  end
56
58
 
59
+ def write_sitemap
60
+ Bonsai.log "Writing sitemap"
61
+ File.open("#{path}/sitemap.xml", "w") {|file| file.write(Bonsai::Sitemap.generate) }
62
+ end
63
+
64
+ def write_readme
65
+ Bonsai.log "Writing ABOUT-THIS-SITE"
66
+
67
+ readme = <<-README
68
+ This site was built using Bonsai (http://tinytree.info)
69
+
70
+ To make changes to the site you will require the original source files.
71
+ Please contact the author of your site for details.
72
+ README
73
+
74
+ File.open("#{path}/ABOUT-THIS-SITE", "w") {|file| file.write(readme) }
75
+ end
76
+
57
77
  def copy_assets
58
78
  Bonsai.log "Copying page assets"
59
79
  Page.all.each do |page|
data/lib/bonsai/page.rb CHANGED
@@ -50,6 +50,9 @@ module Bonsai
50
50
  web_path(directory)
51
51
  end
52
52
 
53
+ def ctime; File.ctime(disk_path); end
54
+ def mtime; File.mtime(disk_path); end
55
+
53
56
  def write_path
54
57
  "#{permalink}/index.html"
55
58
  end
@@ -0,0 +1,30 @@
1
+ module Bonsai
2
+ class Sitemap
3
+ def self.generate(change_freq = "monthly")
4
+ index = Bonsai::Page.find("index")
5
+
6
+ template = Tilt::BuilderTemplate.new do
7
+ lambda { |xml|
8
+ xml.instruct!
9
+ xml.urlset(:xmlns=>'http://www.sitemaps.org/schemas/sitemap/0.9') {
10
+ xml.url {
11
+ xml.loc(Bonsai.site[:site][:url])
12
+ xml.lastmod(index.mtime.utc.strftime("%Y-%m-%d"))
13
+ xml.changefreq(change_freq)
14
+ }
15
+
16
+ Bonsai::Page.all.delete_if{|p| p.permalink === "/index"}.each do |page|
17
+ xml.url {
18
+ xml.loc(Bonsai.site[:site][:url] + page.permalink)
19
+ xml.lastmod(page.mtime.utc.strftime("%Y-%m-%d"))
20
+ xml.changefreq(change_freq)
21
+ }
22
+ end
23
+ }
24
+ }
25
+ end
26
+
27
+ template.render
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,2 @@
1
+ User-agent: *
2
+ Allow: /
@@ -0,0 +1,4 @@
1
+ :site:
2
+ :name: Your website title
3
+ :url: http://yourdomain.com
4
+ :copyright: 2010
data/lib/bonsai.rb CHANGED
@@ -42,6 +42,12 @@ module Bonsai
42
42
  File.read("#{File.dirname(__FILE__)}/../VERSION")
43
43
  end
44
44
 
45
+ def site
46
+ YAML::load(File.read("#{Bonsai.root_dir}/site.yml")) || {}
47
+ rescue ArgumentError
48
+ Bonsai.log "Badly formatted site.yml"
49
+ end
50
+
45
51
  private
46
52
  def is_a_bonsai?(path)
47
53
  File.directory?("#{path}/content") && File.directory?("#{path}/public") && File.directory?("#{path}/templates")
@@ -50,6 +56,7 @@ module Bonsai
50
56
 
51
57
  autoload :Page, "page"
52
58
  autoload :Console, "console"
59
+ autoload :Sitemap, "sitemap"
53
60
  autoload :Exporter, "exporter"
54
61
  autoload :Template, "template"
55
62
  autoload :Generate, "generate"
@@ -108,7 +108,13 @@ describe Bonsai::Exporter do
108
108
  File.exists?("#{Bonsai::Exporter.path}/index.html").should be_true
109
109
  end
110
110
 
111
- it "should write a readme file to explain how the site was generated"
111
+ it "should write a sitemap.xml" do
112
+ File.exists?("#{Bonsai::Exporter.path}/sitemap.xml").should be_true
113
+ end
114
+
115
+ it "should write a readme file to explain how the site was generated" do
116
+ File.exists?("#{Bonsai::Exporter.path}/ABOUT-THIS-SITE").should be_true
117
+ end
112
118
 
113
119
  describe "asset compression" do
114
120
  it "should compress the css file" do
@@ -29,8 +29,16 @@ describe Bonsai::Generate do
29
29
  File.exists?("#{@path}/templates/default.mustache").should be_true
30
30
  end
31
31
 
32
- it "should generate 4 files" do
33
- Dir.glob("#{@path}/**/*", File::FNM_DOTMATCH).select{|f| File.file?(f) }.size.should == 4
32
+ it "should create a robots.txt" do
33
+ File.exists?("#{@path}/public/robots.txt").should be_true
34
+ end
35
+
36
+ it "should create a site.yml" do
37
+ File.exists?("#{@path}/site.yml").should be_true
38
+ end
39
+
40
+ it "should generate 6 files" do
41
+ Dir.glob("#{@path}/**/*", File::FNM_DOTMATCH).select{|f| File.file?(f) }.size.should == 6
34
42
  end
35
43
 
36
44
  it "should generate 7 directories" do
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  require "#{File.dirname(__FILE__)}/../spec_helper"
2
4
 
3
5
  describe Bonsai::Page do
@@ -26,6 +28,15 @@ describe Bonsai::Page do
26
28
  @page.permalink.should == "/about-us/history"
27
29
  end
28
30
 
31
+ it "should have a ctime" do
32
+ @page.should respond_to :ctime
33
+ @page.ctime.should be_an_instance_of(Time)
34
+ end
35
+
36
+ it "should have an mtime" do
37
+ @page.should respond_to :mtime
38
+ @page.mtime.should be_an_instance_of(Time)
39
+ end
29
40
  it "should remove numbers over 10 from the permalink" do
30
41
  Bonsai::Page.find("many-pages").permalink.should == "/many-pages"
31
42
  end
@@ -0,0 +1,15 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe Bonsai::Sitemap do
4
+ before :all do
5
+ @sitemap = Bonsai::Sitemap.generate
6
+ end
7
+
8
+ it "should contain /" do
9
+ @sitemap.should include "<loc>http://tinytree.info</loc>"
10
+ end
11
+
12
+ it "should not include /index" do
13
+ @sitemap.should_not include "<loc>http://tinytree.info/index</loc>"
14
+ end
15
+ end
data/spec/bonsai_spec.rb CHANGED
@@ -18,4 +18,32 @@ describe Bonsai do
18
18
  it "should know the version" do
19
19
  Bonsai.version.should =~ /\d+.\d+.\d+/
20
20
  end
21
+
22
+
23
+ describe "site yml" do
24
+ describe "working" do
25
+ it "should respond to site" do
26
+ Bonsai.should respond_to(:site)
27
+ end
28
+
29
+ it "should contain the contents of the site yml" do
30
+ Bonsai.site.should == YAML.load(File.read("#{Bonsai.root_dir}/site.yml"))
31
+ end
32
+ end
33
+
34
+ describe "broken" do
35
+ before :all do
36
+ Bonsai.root_dir = "spec/support/broken"
37
+ end
38
+
39
+ after :all do
40
+ Bonsai.root_dir = "spec/support"
41
+ end
42
+
43
+ it "should log rather than raising exception with badly formatted yml" do
44
+ Bonsai.should_receive(:log).with("Badly formatted site.yml")
45
+ lambda { Bonsai.site }.should_not raise_error
46
+ end
47
+ end
48
+ end
21
49
  end
@@ -1,3 +1,2 @@
1
- :page_variable: A popular plastic chair that has returned direct from 1971. Casalino was very popular during the 1970’s, however the design become out of vogue during the 1980’s and has not been available since. It wasn’t until the original moulds were rediscovered recently that Casalino has found a new life.
2
-
3
- A popular plastic chair that has returned direct from 1971. Casalino was very popular during the 1970’s, however the design become out of vogue during the 1980’s and has not been available since. It wasn’t until the original moulds were rediscovered recently that Casalino has found a new life.
1
+ :page_variable:
2
+ Broken, broken broken
@@ -0,0 +1,6 @@
1
+ :site:
2
+ :name: My broken site
3
+ :url: http://broke.it
4
+ :copyright: 2010
5
+ :how-to-break-it:
6
+ Just start writing like you don't know what you're doing.
@@ -0,0 +1,3 @@
1
+ headline: Welcome to Bonsai
2
+ body: |
3
+ A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.
@@ -0,0 +1,28 @@
1
+ DirectoryIndex index.html
2
+ FileETag All
3
+
4
+ # Compress all static assets
5
+ <IfModule mod_deflate.c>
6
+ # compress content with type html, text, and css
7
+ AddOutputFilterByType DEFLATE text/css text/html text/javascript application/javascript application/x-javascript text/js text/plain text/xml
8
+
9
+ <IfModule mod_headers.c>
10
+ # properly handle requests coming from behind proxies
11
+ Header append Vary User-Agent
12
+ </IfModule>
13
+ </IfModule>
14
+
15
+ # Cache, aggressively
16
+ <IfModule mod_expires.c>
17
+ ExpiresActive On
18
+ ExpiresDefault "access plus 10 days"
19
+
20
+ <FilesMatch "\.(eot|ttf|otf)$">
21
+ ExpiresDefault "access plus 10 years"
22
+ </filesMatch>
23
+ </IfModule>
24
+
25
+ # Mime-types
26
+ AddType application/vnd.ms-fontobject .eot
27
+ AddType font/ttf .ttf
28
+ AddType font/otf .otf
@@ -0,0 +1 @@
1
+ /* Put your styles here */
@@ -0,0 +1,2 @@
1
+ User-agent: *
2
+ Allow: /
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
+ <title>{{name}}</title>
6
+ <link rel="stylesheet" href="/css/base.css" type="text/css">
7
+ </head>
8
+ <body id="{{slug}}" class="default">
9
+ <header>
10
+ <h1>{{headline}}</h1>
11
+ {{{body}}}
12
+ </header>
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ :site:
2
+ :name: Bonsai
3
+ :url: http://tinytree.info
4
+ :copyright: 2010
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bonsai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-02 00:00:00 +11:00
12
+ date: 2010-01-05 00:00:00 +11:00
13
13
  default_executable: bonsai
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,16 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 0.5.0
54
54
  version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: builder
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.1.2
64
+ version:
55
65
  - !ruby/object:Gem::Dependency
56
66
  name: thin
57
67
  type: :runtime
@@ -128,10 +138,13 @@ files:
128
138
  - lib/bonsai/generate.rb
129
139
  - lib/bonsai/navigation.rb
130
140
  - lib/bonsai/page.rb
141
+ - lib/bonsai/sitemap.rb
131
142
  - lib/bonsai/template.rb
132
143
  - lib/bonsai/templates/content/index/default.yml
133
144
  - lib/bonsai/templates/public/.htaccess
134
145
  - lib/bonsai/templates/public/docs/css/base.less
146
+ - lib/bonsai/templates/public/robots.txt
147
+ - lib/bonsai/templates/site.yml
135
148
  - lib/bonsai/templates/templates/default.mustache
136
149
  - lib/bonsai/webserver.rb
137
150
  - spec/bonsai/console_spec.rb
@@ -139,11 +152,18 @@ files:
139
152
  - spec/bonsai/generate_spec.rb
140
153
  - spec/bonsai/navigation_spec.rb
141
154
  - spec/bonsai/page_spec.rb
155
+ - spec/bonsai/sitemap_spec.rb
142
156
  - spec/bonsai/template_spec.rb
143
157
  - spec/bonsai_spec.rb
144
158
  - spec/spec.opts
145
159
  - spec/spec_helper.rb
146
160
  - spec/support/broken/content/broken_page/demo-template.yml
161
+ - spec/support/broken/site.yml
162
+ - spec/support/broken/templates/content/index/default.yml
163
+ - spec/support/broken/templates/public/.htaccess
164
+ - spec/support/broken/templates/public/docs/css/base.less
165
+ - spec/support/broken/templates/public/robots.txt
166
+ - spec/support/broken/templates/templates/default.mustache
147
167
  - spec/support/content/1.about-us/1.contact/1.child/a_file_asset.txt
148
168
  - spec/support/content/1.about-us/1.contact/1.child/demo-template.yml
149
169
  - spec/support/content/1.about-us/1.contact/demo-template.yml
@@ -169,6 +189,7 @@ files:
169
189
  - spec/support/public/js/script.js
170
190
  - spec/support/public/stylesheets/base.less
171
191
  - spec/support/public/stylesheets/broken.less
192
+ - spec/support/site.yml
172
193
  - spec/support/templates/demo-template.mustache
173
194
  - spec/support/templates/partials/inserted.mustache
174
195
  - vendor/yui-compressor/yuicompressor-2.4.2.jar
@@ -206,6 +227,7 @@ test_files:
206
227
  - spec/bonsai/generate_spec.rb
207
228
  - spec/bonsai/navigation_spec.rb
208
229
  - spec/bonsai/page_spec.rb
230
+ - spec/bonsai/sitemap_spec.rb
209
231
  - spec/bonsai/template_spec.rb
210
232
  - spec/bonsai_spec.rb
211
233
  - spec/spec_helper.rb