bonsai 1.3.1 → 1.3.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.
data/lib/bonsai/page.rb CHANGED
@@ -68,8 +68,8 @@ module Bonsai
68
68
  end
69
69
 
70
70
  # This method is used for the exporter to copy assets
71
- def assets(disk_path = directory)
72
- Dir["#{disk_path}/**/*"].select{|path| !File.directory?(path) && !File.basename(path).include?("yml") }.map do |file|
71
+ def assets
72
+ Dir["#{directory}/**/*"].select{|path| !File.directory?(path) && !File.basename(path).include?("yml") }.map do |file|
73
73
  file_to_hash(file)
74
74
  end
75
75
  end
@@ -96,8 +96,8 @@ module Bonsai
96
96
  self.class.all(File.dirname(disk_path[/(.+)\/[^\/]*$/, 1]), "*").delete_if{|p| p == self}
97
97
  end
98
98
 
99
- def children(path = nil)
100
- self.class.all((path||directory), "*").delete_if{|p| p.floating? }
99
+ def children
100
+ self.class.all(File.dirname(disk_path), "*").delete_if{|p| p.floating? }
101
101
  end
102
102
 
103
103
  def ancestors
@@ -170,8 +170,8 @@ module Bonsai
170
170
  # that isn't itself, a child-page (a page object)
171
171
  def disk_assets
172
172
  assets = {}
173
- Dir["#{File.dirname(disk_path)}/**"].select{|p|
174
- File.directory?(p)}.reject {|p| Dir.entries(p).any?{|e| e.include? "yml" }
173
+ Dir["#{File.dirname(disk_path)}/**"].select{|p| File.directory?(p)}.reject {|p|
174
+ Dir.entries(p).any?{|e| e.include? "yml"}
175
175
  }.each{|asset_path| assets.merge!(map_to_disk(asset_path)) }
176
176
 
177
177
  assets
@@ -181,10 +181,9 @@ module Bonsai
181
181
  name = File.basename(path)
182
182
 
183
183
  {
184
- name.to_sym => {
185
- :files => assets(path),
186
- :children => children(path).map{|page| page.to_hash }
187
- }
184
+ name.to_sym => Dir["#{path}/*"].map do |file|
185
+ file_to_hash(file)
186
+ end
188
187
  }
189
188
  end
190
189
 
@@ -13,7 +13,7 @@ module Bonsai
13
13
  xml.changefreq(change_freq)
14
14
  }
15
15
 
16
- Bonsai::Page.all.delete_if{|p| p.permalink === "/index"}.each do |page|
16
+ Bonsai::Page.all.delete_if{|p| p.permalink === "/index/"}.each do |page|
17
17
  xml.url {
18
18
  xml.loc(Bonsai.site[:url] + page.permalink)
19
19
  xml.lastmod(page.mtime.utc.strftime("%Y-%m-%d"))
@@ -35,4 +35,4 @@ module Bonsai
35
35
  exit
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # The key value pairs found below are available within the templates.
2
- # {{site_name}}, {{url}}, {{copyright}} and {{analytics_code}} are examples
2
+ # {{site_name}}, {{url}}, {{copyright}} and {{analytics_code}}
3
3
 
4
4
  :site_name: Your website title
5
5
  :url: http://yourdomain.com
@@ -37,12 +37,12 @@ describe Bonsai::Generate do
37
37
  File.exists?("#{@path}/site.yml").should be_true
38
38
  end
39
39
 
40
- it "should generate 24 files" do
41
- Dir.glob("#{@path}/**/*", File::FNM_DOTMATCH).select{|f| File.file?(f) }.size.should == 24
40
+ it "should generate 22 files" do
41
+ Dir.glob("#{@path}/**/*", File::FNM_DOTMATCH).select{|f| File.file?(f) }.size.should == 22
42
42
  end
43
43
 
44
- it "should generate 16 directories" do
45
- Dir.glob("#{@path}/**/*").select{|f| File.directory?(f) }.size.should == 16
44
+ it "should generate 14 directories" do
45
+ Dir.glob("#{@path}/**/*").select{|f| File.directory?(f) }.size.should == 14
46
46
  end
47
47
  end
48
48
  end
@@ -65,53 +65,12 @@ describe Bonsai::Page do
65
65
  end
66
66
 
67
67
  it "should have the correct disk_path" do
68
- @page.assets.first[:disk_path].should == "/Users/ben/Documents/Projects/bonsai/spec/support/content/1.about-us/history/001.jpg"
68
+ @page.assets.first[:disk_path].should == File.join(Dir.pwd, "spec/support/content/1.about-us/history/001.jpg")
69
69
  end
70
70
 
71
71
  it "should titleize the name attribute and remove the file extension" do
72
72
  @page.assets[2][:name].should == "A File Asset"
73
73
  end
74
-
75
- describe "disk_assets" do
76
- before :all do
77
- @page = Bonsai::Page.find("about-us/contact")
78
- end
79
-
80
- it "should have magic" do
81
- @page.to_hash.should have_key(:magic)
82
- end
83
-
84
- it "should have assets" do
85
- @page.to_hash[:magic][:files].should be_an_instance_of(Array)
86
- @page.to_hash[:magic][:files].should_not be_empty
87
- end
88
-
89
- it "it should be a an array of hashes" do
90
- @page.to_hash[:magic][:files].should be_an_instance_of(Array)
91
- @page.to_hash[:magic][:files].first.should be_an_instance_of(Hash)
92
- @page.to_hash[:magic][:files].size.should == 2
93
- end
94
-
95
- it "should have children" do
96
- @page.to_hash[:magic][:children].should_not be_empty
97
- end
98
-
99
- describe "children (pages)" do
100
- it "should represent the children as pages" do
101
- @page.to_hash[:magic][:children].first.should be_an_instance_of(Bonsai::Page)
102
- end
103
-
104
- it "should contain a single child" do
105
- @page.to_hash[:magic][:children].size.should == 1
106
- end
107
-
108
- %w(slug permalink name page_title children siblings parent ancestors navigation updated_at created_at).each do |key|
109
- it "should have a to_hash key for #{key}" do
110
- @page.to_hash[:magic][:children].first.to_hash.keys.should include(key.to_sym)
111
- end
112
- end
113
- end
114
- end
115
74
  end
116
75
 
117
76
  it "should be equal" do
@@ -196,7 +155,7 @@ describe Bonsai::Page do
196
155
  end
197
156
 
198
157
  it "should replace mustache variables with properties from the content file" do
199
- @output.should == "Hello from our template, named Contact\n\nGet in touch\n\n/about-us/contact/images/image001.jpg\n/about-us/contact/child/\n/about-us/contact/magic/containing-a-page\n/about-us/contact/magic/image001.jpg\n/about-us/contact/magic/image002.jpg\nThis content should be inserted!\n\n<p>&ldquo;A designer knows he has achieved perfection\nnot when there is nothing left to add,\nbut when there is nothing left to take away.&rdquo;</p>\n\n<p>– Antoine de Saint-Exupery</p>\n"
158
+ @output.should == "Hello from our template, named Contact\n\nGet in touch\n\n/about-us/contact/images/image001.jpg\n/about-us/contact/child/\n/about-us/contact/magic/image001.jpg\n/about-us/contact/magic/image002.jpg\nThis content should be inserted!\n\n<p>&#8220;A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.&#8221;</p>\n\n<p>– Antoine de Saint-Exupery</p>"
200
159
  end
201
160
 
202
161
  it "should write in images" do
@@ -216,11 +175,11 @@ describe Bonsai::Page do
216
175
  end
217
176
 
218
177
  it "should use markdown for multiple line content" do
219
- @output.should =~ /<p>&ldquo;A designer knows he/
178
+ @output.should =~ /<p>&#8220;A designer knows he/
220
179
  end
221
180
 
222
181
  it "should use smartypants" do
223
- @output.should =~ /&rdquo;/
182
+ @output.should =~ /&#8220;/
224
183
  end
225
184
  end
226
185
  end
@@ -245,6 +204,28 @@ describe Bonsai::Page do
245
204
  @page.to_hash[:url].should == "http://tinytree.info"
246
205
  @page.to_hash[:copyright].should == 2010
247
206
  end
207
+
208
+ describe "disk_assets" do
209
+ before :all do
210
+ @vars = @page.to_hash
211
+ end
212
+
213
+ describe "enum" do
214
+ it "should not have a child" do
215
+ @vars.should_not have_key(:child)
216
+ end
217
+
218
+ it "should have magic" do
219
+ @vars.should have_key(:magic)
220
+ end
221
+
222
+ it "it should be a an array of hashes" do
223
+ @vars[:magic].should be_an_instance_of(Array)
224
+ @vars[:magic].first.should be_an_instance_of(Hash)
225
+ @vars[:magic].size.should == 2
226
+ end
227
+ end
228
+ end
248
229
  end
249
230
 
250
231
  describe "broken page" do
@@ -13,7 +13,7 @@ describe Bonsai::Template do
13
13
  describe "instance" do
14
14
  it "should give the template source" do
15
15
  @template = Bonsai::Template.find("demo-template")
16
- File.read(@template.path).should == "Hello from our template, named {{name}}\n\n{{page_title}}\n\n{{#images}}\n {{#files}}\n {{path}}\n {{/files}}\n{{/images}}\n\n{{#children}}\n {{permalink}}\n{{/children}}\n\n{{#magic}}\n {{path}}\n{{/magic}}\n\n{{>partials/inserted}}\n\n{{{body}}}"
16
+ File.read(@template.path).should == "Hello from our template, named {{name}}\n\n{{page_title}}\n\n{{#images}}\n {{path}}\n{{/images}}\n\n{{#children}}\n {{permalink}}\n{{/children}}\n\n{{#magic}}\n {{path}}\n{{/magic}}\n\n{{>partials/inserted}}\n\n{{{body}}}"
17
17
  end
18
18
  end
19
19
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'bonsai'
4
- require 'spec'
5
- require 'spec/autorun'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
6
 
7
- Spec::Runner.configure do |config|
7
+ RSpec.configure do |config|
8
8
  Bonsai.config = { :enable_logging => false }
9
9
 
10
10
  BONSAI_PATH = "#{File.dirname(__FILE__)}/support" unless defined? BONSAI_PATH
@@ -3,9 +3,7 @@ Hello from our template, named {{name}}
3
3
  {{page_title}}
4
4
 
5
5
  {{#images}}
6
- {{#files}}
7
- {{path}}
8
- {{/files}}
6
+ {{path}}
9
7
  {{/images}}
10
8
 
11
9
  {{#children}}