nesta 0.9.11 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -11
  3. data/.gitmodules +6 -0
  4. data/.hound.yml +2 -0
  5. data/{spec/spec.opts → .rspec} +0 -0
  6. data/.travis.yml +11 -0
  7. data/CHANGES +250 -2
  8. data/Gemfile +2 -2
  9. data/Gemfile.lock +89 -33
  10. data/Guardfile +7 -0
  11. data/LICENSE +1 -1
  12. data/README.md +38 -6
  13. data/RELEASING.md +21 -0
  14. data/Rakefile +20 -4
  15. data/bin/nesta +131 -14
  16. data/config.ru +3 -0
  17. data/lib/nesta.rb +9 -1
  18. data/lib/nesta/app.rb +21 -107
  19. data/lib/nesta/commands.rb +5 -256
  20. data/lib/nesta/commands/command.rb +57 -0
  21. data/lib/nesta/commands/demo.rb +1 -0
  22. data/lib/nesta/commands/demo/content.rb +56 -0
  23. data/lib/nesta/commands/edit.rb +21 -0
  24. data/lib/nesta/commands/new.rb +57 -0
  25. data/lib/nesta/commands/plugin.rb +1 -0
  26. data/lib/nesta/commands/plugin/create.rb +82 -0
  27. data/lib/nesta/commands/theme.rb +3 -0
  28. data/lib/nesta/commands/theme/create.rb +36 -0
  29. data/lib/nesta/commands/theme/enable.rb +22 -0
  30. data/lib/nesta/commands/theme/install.rb +31 -0
  31. data/lib/nesta/config.rb +51 -22
  32. data/lib/nesta/helpers.rb +115 -0
  33. data/lib/nesta/models.rb +111 -70
  34. data/lib/nesta/navigation.rb +36 -12
  35. data/lib/nesta/overrides.rb +10 -5
  36. data/lib/nesta/plugin.rb +10 -8
  37. data/lib/nesta/version.rb +1 -1
  38. data/nesta.gemspec +14 -13
  39. data/templates/Gemfile +6 -3
  40. data/templates/config.ru +3 -0
  41. data/templates/config/config.yml +14 -14
  42. data/templates/config/deploy.rb +2 -2
  43. data/templates/index.haml +2 -0
  44. data/templates/plugins/Gemfile +4 -0
  45. data/templates/plugins/README.md +13 -0
  46. data/templates/plugins/Rakefile +58 -0
  47. data/templates/plugins/gitignore +3 -0
  48. data/templates/plugins/lib/init.rb +13 -0
  49. data/templates/plugins/lib/required.rb +3 -0
  50. data/templates/plugins/lib/version.rb +5 -0
  51. data/templates/plugins/plugin.gemspec +28 -0
  52. data/templates/themes/README.md +1 -1
  53. data/templates/themes/app.rb +1 -1
  54. data/templates/themes/views/layout.haml +7 -0
  55. data/templates/themes/views/master.sass +3 -0
  56. data/templates/themes/views/page.haml +1 -0
  57. data/{spec → test}/fixtures/nesta-plugin-test/Gemfile +0 -0
  58. data/{spec → test}/fixtures/nesta-plugin-test/Rakefile +0 -0
  59. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test.rb +0 -0
  60. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/init.rb +1 -3
  61. data/{spec → test}/fixtures/nesta-plugin-test/lib/nesta-plugin-test/version.rb +0 -0
  62. data/{spec → test}/fixtures/nesta-plugin-test/nesta-plugin-test.gemspec +0 -0
  63. data/test/integration/atom_feed_test.rb +178 -0
  64. data/test/integration/commands/demo/content_test.rb +31 -0
  65. data/test/integration/commands/edit_test.rb +21 -0
  66. data/test/integration/commands/new_test.rb +120 -0
  67. data/test/integration/commands/plugin/create_test.rb +128 -0
  68. data/test/integration/commands/theme/create_test.rb +35 -0
  69. data/test/integration/commands/theme/enable_test.rb +22 -0
  70. data/test/integration/commands/theme/install_test.rb +62 -0
  71. data/test/integration/default_theme_test.rb +220 -0
  72. data/test/integration/overrides_test.rb +118 -0
  73. data/test/integration/route_handlers_test.rb +96 -0
  74. data/test/integration/sitemap_test.rb +85 -0
  75. data/test/integration_test_helper.rb +61 -0
  76. data/test/support/model_factory.rb +169 -0
  77. data/test/support/silence_commands_during_tests.rb +5 -0
  78. data/test/support/temporary_files.rb +33 -0
  79. data/test/support/test_configuration.rb +19 -0
  80. data/test/test_helper.rb +26 -0
  81. data/test/unit/commands_test.rb +23 -0
  82. data/test/unit/config_test.rb +138 -0
  83. data/test/unit/file_model_test.rb +71 -0
  84. data/test/unit/menu_test.rb +82 -0
  85. data/test/unit/page_test.rb +571 -0
  86. data/test/unit/path_test.rb +41 -0
  87. data/test/unit/plugin_test.rb +47 -0
  88. data/views/analytics.haml +9 -10
  89. data/views/atom.haml +4 -4
  90. data/views/comments.haml +1 -1
  91. data/views/error.haml +1 -1
  92. data/views/feed.haml +1 -1
  93. data/views/layout.haml +6 -3
  94. data/views/master.sass +144 -134
  95. data/views/mixins.sass +53 -28
  96. data/views/normalize.scss +396 -0
  97. data/views/page_meta.haml +2 -2
  98. data/views/sitemap.haml +2 -2
  99. data/views/summaries.haml +2 -2
  100. metadata +258 -232
  101. data/lib/nesta/cache.rb +0 -139
  102. data/lib/nesta/nesta.rb +0 -7
  103. data/spec/atom_spec.rb +0 -138
  104. data/spec/commands_spec.rb +0 -364
  105. data/spec/config_spec.rb +0 -67
  106. data/spec/model_factory.rb +0 -92
  107. data/spec/models_spec.rb +0 -588
  108. data/spec/overrides_spec.rb +0 -132
  109. data/spec/page_spec.rb +0 -498
  110. data/spec/path_spec.rb +0 -28
  111. data/spec/plugin_spec.rb +0 -51
  112. data/spec/sitemap_spec.rb +0 -100
  113. data/spec/spec_helper.rb +0 -76
@@ -1,67 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
-
3
- describe "Config" do
4
- after(:each) do
5
- ENV.keys.each { |variable| ENV.delete(variable) if variable =~ /NESTA_/ }
6
- end
7
-
8
- describe "when settings defined in ENV" do
9
- before(:each) do
10
- @title = "Title from ENV"
11
- ENV["NESTA_TITLE"] = @title
12
- end
13
-
14
- it "should never try and access config.yml" do
15
- stub_config_key("subtitle", "Subtitle in YAML file")
16
- Nesta::Config.subtitle.should be_nil
17
- end
18
-
19
- it "should override config.yml" do
20
- stub_config_key("title", "Title in YAML file")
21
- Nesta::Config.title.should == @title
22
- end
23
-
24
- it "should know how to cope with boolean values" do
25
- ENV["NESTA_CACHE"] = "true"
26
- Nesta::Config.cache.should be_true
27
- ENV["NESTA_CACHE"] = "false"
28
- Nesta::Config.cache.should be_false
29
- end
30
-
31
- it "should set author hash from ENV" do
32
- name = "Name from ENV"
33
- uri = "URI from ENV"
34
- ENV["NESTA_AUTHOR__NAME"] = name
35
- ENV["NESTA_AUTHOR__URI"] = uri
36
- Nesta::Config.author["name"].should == name
37
- Nesta::Config.author["uri"].should == uri
38
- Nesta::Config.author["email"].should be_nil
39
- end
40
- end
41
-
42
- describe "when settings only defined in config.yml" do
43
- before(:each) do
44
- @title = "Title in YAML file"
45
- stub_config_key("subtitle", @title)
46
- end
47
-
48
- it "should read configuration from YAML" do
49
- Nesta::Config.subtitle.should == @title
50
- end
51
-
52
- it "should set author hash from YAML" do
53
- name = "Name from YAML"
54
- uri = "URI from YAML"
55
- stub_config_key("author", { "name" => name, "uri" => uri })
56
- Nesta::Config.author["name"].should == name
57
- Nesta::Config.author["uri"].should == uri
58
- Nesta::Config.author["email"].should be_nil
59
- end
60
-
61
- it "should override top level settings with RACK_ENV specific settings" do
62
- stub_config_key('content', 'general/path')
63
- stub_config_key('content', 'rack_env/path', :rack_env => true)
64
- Nesta::Config.content.should == 'rack_env/path'
65
- end
66
- end
67
- end
@@ -1,92 +0,0 @@
1
- module ModelFactory
2
- def create_page(options)
3
- extension = options[:ext] || :mdown
4
- path = filename(Nesta::Config.page_path, options[:path], extension)
5
- create_file(path, options)
6
- yield(path) if block_given?
7
- Nesta::Page.new(path)
8
- end
9
-
10
- def create_article(options = {}, &block)
11
- o = {
12
- :path => 'article-prefix/my-article',
13
- :heading => 'My article',
14
- :content => 'Content goes here',
15
- :metadata => {
16
- 'date' => '29 December 2008'
17
- }.merge(options.delete(:metadata) || {})
18
- }.merge(options)
19
- create_page(o, &block)
20
- end
21
-
22
- def create_category(options = {}, &block)
23
- o = {
24
- :path => 'category-prefix/my-category',
25
- :heading => 'My category',
26
- :content => 'Content goes here'
27
- }.merge(options)
28
- create_page(o, &block)
29
- end
30
-
31
- def write_menu_item(indent, file, menu_item)
32
- if menu_item.is_a?(Array)
33
- indent.sub!(/^/, ' ')
34
- menu_item.each { |path| write_menu_item(indent, file, path) }
35
- indent.sub!(/^ /, '')
36
- else
37
- file.write("#{indent}#{menu_item}\n")
38
- end
39
- end
40
-
41
- def create_menu(menu_text)
42
- file = filename(Nesta::Config.content_path, 'menu', :txt)
43
- File.open(file, 'w') { |file| file.write(menu_text) }
44
- end
45
-
46
- def delete_page(type, permalink, extension)
47
- file = filename(Nesta::Config.page_path, permalink, extension)
48
- FileUtils.rm(file)
49
- end
50
-
51
- def create_content_directories
52
- FileUtils.mkdir_p(Nesta::Config.page_path)
53
- FileUtils.mkdir_p(Nesta::Config.attachment_path)
54
- end
55
-
56
- def mock_file_stat(method, filename, time)
57
- stat = mock(:stat)
58
- stat.stub!(:mtime).and_return(Time.parse(time))
59
- File.send(method, :stat).with(filename).and_return(stat)
60
- end
61
-
62
- private
63
- def filename(directory, basename, extension = :mdown)
64
- File.join(directory, "#{basename}.#{extension}")
65
- end
66
-
67
- def heading(options)
68
- prefix = case options[:ext]
69
- when :haml
70
- "%div\n %h1"
71
- when :textile
72
- "<div>\nh1."
73
- else
74
- '# '
75
- end
76
- "#{prefix} #{options[:heading]}\n\n"
77
- end
78
-
79
- def create_file(path, options = {})
80
- create_content_directories
81
- metadata = options[:metadata] || {}
82
- metatext = metadata.map { |key, value| "#{key}: #{value}" }.join("\n")
83
- heading = options[:heading] ? heading(options) : ''
84
- contents =<<-EOF
85
- #{metatext}
86
-
87
- #{heading}#{options[:content]}
88
- EOF
89
- FileUtils.mkdir_p(File.dirname(path))
90
- File.open(path, 'w') { |file| file.write(contents) }
91
- end
92
- end
@@ -1,588 +0,0 @@
1
- require File.expand_path('spec_helper', File.dirname(__FILE__))
2
- require File.expand_path('model_factory', File.dirname(__FILE__))
3
-
4
- module ModelMatchers
5
- class HavePage
6
- def initialize(path)
7
- @category = path
8
- end
9
-
10
- def matches?(article)
11
- @article = article
12
- article.categories.map { |c| c.path }.include?(@category)
13
- end
14
-
15
- def failure_message
16
- "expected '#{@article.path}' to be assigned to #{@category}"
17
- end
18
-
19
- def negative_failure_message
20
- "'#{@article.path}' should not be assigned to #{@category}"
21
- end
22
- end
23
-
24
- def be_in_category(path)
25
- HavePage.new(path)
26
- end
27
- end
28
-
29
- describe "Page", :shared => true do
30
- include ModelFactory
31
- include ModelMatchers
32
-
33
- def create_page(options)
34
- super(options.merge(:ext => @extension))
35
- end
36
-
37
- before(:each) do
38
- stub_configuration
39
- end
40
-
41
- after(:each) do
42
- remove_temp_directory
43
- Nesta::FileModel.purge_cache
44
- end
45
-
46
- it "should be findable" do
47
- create_page(:heading => 'Apple', :path => 'the-apple')
48
- Nesta::Page.find_all.should have(1).item
49
- end
50
-
51
- it "should find by path" do
52
- create_page(:heading => 'Banana', :path => 'banana')
53
- Nesta::Page.find_by_path('banana').heading.should == 'Banana'
54
- end
55
-
56
- it "should find index page by path" do
57
- create_page(:heading => 'Banana', :path => 'banana/index')
58
- Nesta::Page.find_by_path('banana').heading.should == 'Banana'
59
- end
60
-
61
- describe "for home page" do
62
- it "should set title to heading and site title" do
63
- create_page(:heading => 'Home', :path => 'index')
64
- Nesta::Page.find_by_path('/').title.should == 'Home - My blog'
65
- end
66
-
67
- it "should respect title metadata" do
68
- create_page(:path => 'index', :metadata => { 'title' => 'Specific title' })
69
- Nesta::Page.find_by_path('/').title.should == 'Specific title'
70
- end
71
-
72
- it "should set title to site title by default" do
73
- create_page(:path => 'index')
74
- Nesta::Page.find_by_path('/').title.should == 'My blog'
75
- end
76
-
77
- it "should set permalink to empty string" do
78
- create_page(:path => 'index')
79
- Nesta::Page.find_by_path('/').permalink.should == ''
80
- end
81
-
82
- it "should set abspath to /" do
83
- create_page(:path => 'index')
84
- Nesta::Page.find_by_path('/').abspath.should == '/'
85
- end
86
- end
87
-
88
- it "should not find nonexistent page" do
89
- Nesta::Page.find_by_path("no-such-page").should be_nil
90
- end
91
-
92
- it "should ensure file exists on instantiation" do
93
- lambda {
94
- Nesta::Page.new("no-such-file")
95
- }.should raise_error(Sinatra::NotFound)
96
- end
97
-
98
- it "should reload cached files when modified" do
99
- create_page(:path => "a-page", :heading => "Version 1")
100
- File.stub!(:mtime).and_return(Time.new - 1)
101
- Nesta::Page.find_by_path("a-page")
102
- create_page(:path => "a-page", :heading => "Version 2")
103
- File.stub!(:mtime).and_return(Time.new)
104
- Nesta::Page.find_by_path("a-page").heading.should == "Version 2"
105
- end
106
-
107
- it "should have default priority of 0 in category" do
108
- page = create_page(:metadata => { 'categories' => 'some-page' })
109
- page.priority('some-page').should == 0
110
- page.priority('another-page').should be_nil
111
- end
112
-
113
- it "should read priority from category metadata" do
114
- page = create_page(:metadata => {
115
- 'categories' => ' some-page:1, another-page , and-another :-1 '
116
- })
117
- page.priority('some-page').should == 1
118
- page.priority('another-page').should == 0
119
- page.priority('and-another').should == -1
120
- end
121
-
122
- describe "with assigned pages" do
123
- before(:each) do
124
- @category = create_category
125
- create_article(:heading => 'Article 1', :path => 'article-1')
126
- create_article(
127
- :heading => 'Article 2',
128
- :path => 'article-2',
129
- :metadata => {
130
- 'date' => '30 December 2008',
131
- 'categories' => @category.path
132
- }
133
- )
134
- @article = create_article(
135
- :heading => 'Article 3',
136
- :path => 'article-3',
137
- :metadata => {
138
- 'date' => '31 December 2008',
139
- 'categories' => @category.path
140
- }
141
- )
142
- @category1 = create_category(
143
- :path => 'category-1',
144
- :heading => 'Category 1',
145
- :metadata => { 'categories' => @category.path }
146
- )
147
- @category2 = create_category(
148
- :path => 'category-2',
149
- :heading => 'Category 2',
150
- :metadata => { 'categories' => @category.path }
151
- )
152
- @category3 = create_category(
153
- :path => 'category-3',
154
- :heading => 'Category 3',
155
- :metadata => { 'categories' => "#{@category.path}:1" }
156
- )
157
- end
158
-
159
- it "should find articles" do
160
- @category.articles.should have(2).items
161
- end
162
-
163
- it "should order articles by reverse chronological order" do
164
- @category.articles.first.path.should == @article.path
165
- end
166
-
167
- it "should find pages" do
168
- @category.pages.should have(3).items
169
- end
170
-
171
- it "should sort pages by priority" do
172
- @category.pages.index(@category3).should == 0
173
- end
174
-
175
- it "should order pages by heading if priority not set" do
176
- pages = @category.pages
177
- pages.index(@category1).should < pages.index(@category2)
178
- end
179
-
180
- it "should not find pages scheduled in the future" do
181
- future_date = (Time.now + 86400).strftime("%d %B %Y")
182
- article = create_article(:heading => "Article 4",
183
- :path => "foo/article-4",
184
- :metadata => { "date" => future_date })
185
- Nesta::Page.find_articles.detect{|a| a == article}.should be_nil
186
- end
187
- end
188
-
189
- describe "with pages in draft" do
190
- before(:each) do
191
- @category = create_category
192
- @draft = create_page(:heading => 'Forthcoming content',
193
- :path => 'foo/in-draft',
194
- :metadata => {
195
- 'categories' => @category.path,
196
- 'flags' => 'draft'
197
- })
198
- Nesta::App.stub!(:production?).and_return(true)
199
- end
200
-
201
- it "should not find assigned drafts" do
202
- @category.pages.should_not include(@draft)
203
- end
204
-
205
- it "should not find drafts by path" do
206
- Nesta::Page.find_by_path('foo/in-draft').should be_nil
207
- end
208
- end
209
-
210
- describe "when finding articles" do
211
- before(:each) do
212
- create_article(:heading => "Article 1", :path => "article-1")
213
- create_article(:heading => "Article 2",
214
- :path => "article-2",
215
- :metadata => { "date" => "31 December 2008" })
216
- create_article(:heading => "Article 3",
217
- :path => "foo/article-3",
218
- :metadata => { "date" => "30 December 2008" })
219
- end
220
-
221
- it "should only find pages with dates" do
222
- articles = Nesta::Page.find_articles
223
- articles.size.should > 0
224
- Nesta::Page.find_articles.each { |page| page.date.should_not be_nil }
225
- end
226
-
227
- it "should return articles in reverse chronological order" do
228
- article1, article2 = Nesta::Page.find_articles[0..1]
229
- article1.date.should > article2.date
230
- end
231
- end
232
-
233
- it "should be able to find parent page" do
234
- category = create_category(:path => 'parent')
235
- article = create_article(:path => 'parent/child')
236
- article.parent.should == category
237
- end
238
-
239
- describe "(with deep index page)" do
240
- it "should be able to find index parent" do
241
- home = create_category(:path => 'index', :heading => 'Home')
242
- category = create_category(:path => 'parent')
243
- category.parent.should == home
244
- home.parent.should be_nil
245
- end
246
-
247
- it "should be able to find parent of index" do
248
- category = create_category(:path => "parent")
249
- index = create_category(:path => "parent/child/index")
250
- index.parent.should == category
251
- end
252
-
253
- it "should be able to find permalink of index" do
254
- index = create_category(:path => "parent/child/index")
255
- index.permalink.should == 'child'
256
- end
257
- end
258
-
259
- describe "(with missing nested page)" do
260
- it "should consider grandparent to be parent" do
261
- grandparent = create_category(:path => 'grandparent')
262
- child = create_category(:path => 'grandparent/parent/child')
263
- child.parent.should == grandparent
264
- end
265
-
266
- it "should consider grandparent home page to be parent" do
267
- home = create_category(:path => 'index')
268
- child = create_category(:path => 'parent/child')
269
- child.parent.should == home
270
- end
271
- end
272
-
273
- describe "when assigned to categories" do
274
- before(:each) do
275
- create_category(:heading => "Apple", :path => "the-apple")
276
- create_category(:heading => "Banana", :path => "banana")
277
- @article = create_article(
278
- :metadata => { "categories" => "banana, the-apple" })
279
- end
280
-
281
- it "should be possible to list the categories" do
282
- @article.categories.should have(2).items
283
- @article.should be_in_category("the-apple")
284
- @article.should be_in_category("banana")
285
- end
286
-
287
- it "should sort categories by heading" do
288
- @article.categories.first.heading.should == "Apple"
289
- end
290
-
291
- it "should not be assigned to non-existant category" do
292
- delete_page(:category, "banana", @extension)
293
- @article.should_not be_in_category("banana")
294
- end
295
- end
296
-
297
- it "should set parent to nil when at root" do
298
- create_category(:path => "top-level").parent.should be_nil
299
- end
300
-
301
- describe "when not assigned to category" do
302
- it "should have empty category list" do
303
- article = create_article
304
- Nesta::Page.find_by_path(article.path).categories.should be_empty
305
- end
306
- end
307
-
308
- describe "with no content" do
309
- it "should produce no HTML output" do
310
- create_article do |path|
311
- file = File.open(path, 'w')
312
- file.close
313
- end
314
- Nesta::Page.find_all.first.to_html.should match(/^\s*$/)
315
- end
316
- end
317
-
318
- describe "without metadata" do
319
- before(:each) do
320
- create_article
321
- @article = Nesta::Page.find_all.first
322
- end
323
-
324
- it "should use default layout" do
325
- @article.layout.should == :layout
326
- end
327
-
328
- it "should use default template" do
329
- @article.template.should == :page
330
- end
331
-
332
- it "should parse heading correctly" do
333
- @article.to_html.should have_tag("h1", "My article")
334
- end
335
-
336
- it "should have default read more link text" do
337
- @article.read_more.should == "Continue reading"
338
- end
339
-
340
- it "should not have description" do
341
- @article.description.should be_nil
342
- end
343
-
344
- it "should not have keywords" do
345
- @article.keywords.should be_nil
346
- end
347
- end
348
-
349
- describe "with metadata" do
350
- before(:each) do
351
- @layout = 'my_layout'
352
- @template = 'my_template'
353
- @date = '07 September 2009'
354
- @keywords = 'things, stuff'
355
- @description = 'Page about stuff'
356
- @summary = 'Multiline\n\nsummary'
357
- @read_more = 'Continue at your leisure'
358
- @skillz = 'ruby, guitar, bowstaff'
359
- @article = create_article(:metadata => {
360
- 'date' => @date.gsub('September', 'Sep'),
361
- 'description' => @description,
362
- 'flags' => 'draft, orange',
363
- 'keywords' => @keywords,
364
- 'layout' => @layout,
365
- 'read more' => @read_more,
366
- 'skillz' => @skillz,
367
- 'summary' => @summary,
368
- 'template' => @template
369
- })
370
- end
371
-
372
- it "should override default layout" do
373
- @article.layout.should == @layout.to_sym
374
- end
375
-
376
- it "should override default template" do
377
- @article.template.should == @template.to_sym
378
- end
379
-
380
- it "should set permalink to basename of filename" do
381
- @article.permalink.should == 'my-article'
382
- end
383
-
384
- it "should set path from filename" do
385
- @article.path.should == 'article-prefix/my-article'
386
- end
387
-
388
- it "should retrieve heading" do
389
- @article.heading.should == 'My article'
390
- end
391
-
392
- it "should be possible to convert an article to HTML" do
393
- @article.to_html.should have_tag("h1", "My article")
394
- end
395
-
396
- it "should not include metadata in the HTML" do
397
- @article.to_html.should_not have_tag("p", /^Date/)
398
- end
399
-
400
- it "should not include heading in body" do
401
- @article.body.should_not have_tag("h1", "My article")
402
- end
403
-
404
- it "should retrieve description from metadata" do
405
- @article.description.should == @description
406
- end
407
-
408
- it "should retrieve keywords from metadata" do
409
- @article.keywords.should == @keywords
410
- end
411
-
412
- it "should retrieve date published from metadata" do
413
- @article.date.strftime("%d %B %Y").should == @date
414
- end
415
-
416
- it "should retrieve read more link from metadata" do
417
- @article.read_more.should == @read_more
418
- end
419
-
420
- it "should retrieve summary text from metadata" do
421
- @article.summary.should match(/#{@summary.split('\n\n').first}/)
422
- end
423
-
424
- it "should treat double newline chars as paragraph break in summary" do
425
- @article.summary.should match(/#{@summary.split('\n\n').last}/)
426
- end
427
-
428
- it "should allow access to metadata" do
429
- @article.metadata('skillz').should == @skillz
430
- end
431
-
432
- it "should allow access to flags" do
433
- @article.should be_flagged_as('draft')
434
- @article.should be_flagged_as('orange')
435
- end
436
-
437
- it "should know whether or not it's a draft" do
438
- @article.should be_draft
439
- end
440
- end
441
-
442
- describe "when checking last modification time" do
443
- before(:each) do
444
- create_article
445
- @article = Nesta::Page.find_all.first
446
- end
447
-
448
- it "should check filesystem" do
449
- mock_file_stat(:should_receive, @article.filename, "3 January 2009")
450
- @article.last_modified.should == Time.parse("3 January 2009")
451
- end
452
- end
453
- end
454
-
455
- describe "All types of page" do
456
- include ModelFactory
457
-
458
- before(:each) do
459
- stub_configuration
460
- end
461
-
462
- after(:each) do
463
- remove_temp_directory
464
- Nesta::FileModel.purge_cache
465
- end
466
-
467
- it "should still return top level menu items" do
468
- # Page.menu_items is deprecated; we're keeping it for the moment so
469
- # that we don't break themes or code in a local app.rb (just yet).
470
- page1 = create_category(:path => "page-1")
471
- page2 = create_category(:path => "page-2")
472
- create_menu([page1.path, page2.path].join("\n"))
473
- Nesta::Page.menu_items.should == [page1, page2]
474
- end
475
- end
476
-
477
- describe "Markdown page" do
478
- before(:each) do
479
- @extension = :mdown
480
- end
481
-
482
- it_should_behave_like "Page"
483
-
484
- it "should set heading from first h1 tag" do
485
- page = create_page(
486
- :heading => "First heading", :content => "# Second heading")
487
- page.heading.should == "First heading"
488
- end
489
-
490
- it "should ignore trailing # characters in headings" do
491
- article = create_article(:heading => 'With trailing #')
492
- article.heading.should == 'With trailing'
493
- end
494
- end
495
-
496
- describe "Haml page" do
497
- before(:each) do
498
- @extension = :haml
499
- end
500
-
501
- it_should_behave_like "Page"
502
-
503
- it "should set heading from first h1 tag" do
504
- create_page(
505
- :path => "a-page",
506
- :heading => "First heading",
507
- :content => "%h1 Second heading"
508
- )
509
- Nesta::Page.find_by_path("a-page").heading.should == "First heading"
510
- end
511
- end
512
-
513
- describe "Textile page" do
514
- before(:each) do
515
- @extension = :textile
516
- end
517
-
518
- it_should_behave_like "Page"
519
-
520
- it "should set heading from first h1 tag" do
521
- create_page(
522
- :path => "a-page",
523
- :heading => "First heading",
524
- :content => "h1. Second heading"
525
- )
526
- Nesta::Page.find_by_path("a-page").heading.should == "First heading"
527
- end
528
- end
529
-
530
- describe "Menu" do
531
- include ModelFactory
532
-
533
- before(:each) do
534
- stub_configuration
535
- @page = create_page(:path => "page-1")
536
- end
537
-
538
- after(:each) do
539
- remove_temp_directory
540
- Nesta::FileModel.purge_cache
541
- end
542
-
543
- it "should find top level menu items" do
544
- text = [@page.path, "no-such-page"].join("\n")
545
- create_menu(text)
546
- Nesta::Menu.top_level.should == [@page]
547
- end
548
-
549
- it "should find all items in the menu" do
550
- create_menu(@page.path)
551
- Nesta::Menu.full_menu.should == [@page]
552
- Nesta::Menu.for_path('/').should == [@page]
553
- end
554
-
555
- describe "with nested sub menus" do
556
- before(:each) do
557
- (2..6).each do |i|
558
- instance_variable_set("@page#{i}", create_page(:path => "page-#{i}"))
559
- end
560
- text = <<-EOF
561
- #{@page.path}
562
- #{@page2.path}
563
- #{@page3.path}
564
- #{@page4.path}
565
- #{@page5.path}
566
- #{@page6.path}
567
- EOF
568
- create_menu(text)
569
- end
570
-
571
- it "should return top level menu items" do
572
- Nesta::Menu.top_level.should == [@page, @page5]
573
- end
574
-
575
- it "should return full tree of menu items" do
576
- Nesta::Menu.full_menu.should ==
577
- [@page, [@page2, [@page3, @page4]], @page5, [@page6]]
578
- end
579
-
580
- it "should return part of the tree of menu items" do
581
- Nesta::Menu.for_path(@page2.path).should == [@page2, [@page3, @page4]]
582
- end
583
-
584
- it "should deem menu for path that isn't in menu to be nil" do
585
- Nesta::Menu.for_path('wibble').should be_nil
586
- end
587
- end
588
- end