nesta 0.9.2 → 0.9.3

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/spec/models_spec.rb CHANGED
@@ -45,13 +45,45 @@ describe "Page", :shared => true do
45
45
  end
46
46
 
47
47
  it "should be findable" do
48
- create_page(:heading => "Apple", :path => "the-apple")
48
+ create_page(:heading => 'Apple', :path => 'the-apple')
49
49
  Nesta::Page.find_all.should have(1).item
50
50
  end
51
51
 
52
52
  it "should find by path" do
53
- create_page(:heading => "Banana", :path => "banana")
54
- Nesta::Page.find_by_path("banana").heading.should == "Banana"
53
+ create_page(:heading => 'Banana', :path => 'banana')
54
+ Nesta::Page.find_by_path('banana').heading.should == 'Banana'
55
+ end
56
+
57
+ it "should find index page by path" do
58
+ create_page(:heading => 'Banana', :path => 'banana/index')
59
+ Nesta::Page.find_by_path('banana').heading.should == 'Banana'
60
+ end
61
+
62
+ describe "for home page" do
63
+ it "should set title to heading and site title" do
64
+ create_page(:heading => 'Home', :path => 'index')
65
+ Nesta::Page.find_by_path('/').title.should == 'Home - My blog'
66
+ end
67
+
68
+ it "should respect title metadata" do
69
+ create_page(:path => 'index', :metadata => { 'title' => 'Specific title' })
70
+ Nesta::Page.find_by_path('/').title.should == 'Specific title'
71
+ end
72
+
73
+ it "should set title to site title by default" do
74
+ create_page(:path => 'index')
75
+ Nesta::Page.find_by_path('/').title.should == 'My blog'
76
+ end
77
+
78
+ it "should set permalink to empty string" do
79
+ create_page(:path => 'index')
80
+ Nesta::Page.find_by_path('/').permalink.should == ''
81
+ end
82
+
83
+ it "should set abspath to /" do
84
+ create_page(:path => 'index')
85
+ Nesta::Page.find_by_path('/').abspath.should == '/'
86
+ end
55
87
  end
56
88
 
57
89
  it "should not find nonexistent page" do
@@ -72,43 +104,80 @@ describe "Page", :shared => true do
72
104
  File.stub!(:mtime).and_return(Time.new)
73
105
  Nesta::Page.find_by_path("a-page").heading.should == "Version 2"
74
106
  end
107
+
108
+ it "should have default priority of 0 in category" do
109
+ page = create_page(:metadata => { 'categories' => 'some-page' })
110
+ page.priority('some-page').should == 0
111
+ page.priority('another-page').should be_nil
112
+ end
113
+
114
+ it "should read priority from category metadata" do
115
+ page = create_page(:metadata => {
116
+ 'categories' => ' some-page:1, another-page , and-another :-1 '
117
+ })
118
+ page.priority('some-page').should == 1
119
+ page.priority('another-page').should == 0
120
+ page.priority('and-another').should == -1
121
+ end
75
122
 
76
123
  describe "with assigned pages" do
77
124
  before(:each) do
78
125
  @category = create_category
79
- create_article(:heading => "Article 1", :path => "article-1")
126
+ create_article(:heading => 'Article 1', :path => 'article-1')
80
127
  create_article(
81
- :heading => "Article 2",
82
- :path => "article-2",
128
+ :heading => 'Article 2',
129
+ :path => 'article-2',
83
130
  :metadata => {
84
- "date" => "30 December 2008",
85
- "categories" => @category.path
131
+ 'date' => '30 December 2008',
132
+ 'categories' => @category.path
86
133
  }
87
134
  )
88
135
  @article = create_article(
89
- :heading => "Article 3",
90
- :path => "article-3",
136
+ :heading => 'Article 3',
137
+ :path => 'article-3',
91
138
  :metadata => {
92
- "date" => "31 December 2008",
93
- "categories" => @category.path
139
+ 'date' => '31 December 2008',
140
+ 'categories' => @category.path
94
141
  }
95
142
  )
96
- create_category(:path => "category-2",
97
- :metadata => { "categories" => @category.path })
143
+ @category1 = create_category(
144
+ :path => 'category-1',
145
+ :heading => 'Category 1',
146
+ :metadata => { 'categories' => @category.path }
147
+ )
148
+ @category2 = create_category(
149
+ :path => 'category-2',
150
+ :heading => 'Category 2',
151
+ :metadata => { 'categories' => @category.path }
152
+ )
153
+ @category3 = create_category(
154
+ :path => 'category-3',
155
+ :heading => 'Category 3',
156
+ :metadata => { 'categories' => "#{@category.path}:1" }
157
+ )
98
158
  end
99
159
 
100
160
  it "should find articles" do
101
161
  @category.articles.should have(2).items
102
162
  end
103
163
 
104
- it "should list most recent articles first" do
164
+ it "should order articles by reverse chronological order" do
105
165
  @category.articles.first.path.should == @article.path
106
166
  end
107
167
 
108
168
  it "should find pages" do
109
- @category.pages.should have(1).item
169
+ @category.pages.should have(3).items
170
+ end
171
+
172
+ it "should sort pages by priority" do
173
+ @category.pages.index(@category3).should == 0
110
174
  end
111
175
 
176
+ it "should order pages by heading if priority not set" do
177
+ pages = @category.pages
178
+ pages.index(@category1).should < pages.index(@category2)
179
+ end
180
+
112
181
  it "should not find pages scheduled in the future" do
113
182
  future_date = (Time.now + 86400).strftime("%d %B %Y")
114
183
  article = create_article(:heading => "Article 4",
@@ -141,6 +210,46 @@ describe "Page", :shared => true do
141
210
  end
142
211
  end
143
212
 
213
+ it "should be able to find parent page" do
214
+ category = create_category(:path => 'parent')
215
+ article = create_article(:path => 'parent/child')
216
+ article.parent.should == category
217
+ end
218
+
219
+ describe "(with deep index page)" do
220
+ it "should be able to find index parent" do
221
+ home = create_category(:path => 'index', :heading => 'Home')
222
+ category = create_category(:path => 'parent')
223
+ category.parent.should == home
224
+ home.parent.should be_nil
225
+ end
226
+
227
+ it "should be able to find parent of index" do
228
+ category = create_category(:path => "parent")
229
+ index = create_category(:path => "parent/child/index")
230
+ index.parent.should == category
231
+ end
232
+
233
+ it "should be able to find permalink of index" do
234
+ index = create_category(:path => "parent/child/index")
235
+ index.permalink.should == 'child'
236
+ end
237
+ end
238
+
239
+ describe "(with missing nested page)" do
240
+ it "should consider grandparent to be parent" do
241
+ grandparent = create_category(:path => 'grandparent')
242
+ child = create_category(:path => 'grandparent/parent/child')
243
+ child.parent.should == grandparent
244
+ end
245
+
246
+ it "should consider grandparent home page to be parent" do
247
+ home = create_category(:path => 'index')
248
+ child = create_category(:path => 'parent/child')
249
+ child.parent.should == home
250
+ end
251
+ end
252
+
144
253
  describe "when assigned to categories" do
145
254
  before(:each) do
146
255
  create_category(:heading => "Apple", :path => "the-apple")
@@ -154,7 +263,7 @@ describe "Page", :shared => true do
154
263
  @article.should be_in_category("the-apple")
155
264
  @article.should be_in_category("banana")
156
265
  end
157
-
266
+
158
267
  it "should sort categories by heading" do
159
268
  @article.categories.first.heading.should == "Apple"
160
269
  end
@@ -165,12 +274,6 @@ describe "Page", :shared => true do
165
274
  end
166
275
  end
167
276
 
168
- it "should be able to find parent page" do
169
- category = create_category(:path => "parent")
170
- article = create_article(:path => "parent/child")
171
- article.parent.should == category
172
- end
173
-
174
277
  it "should set parent to nil when at root" do
175
278
  create_category(:path => "top-level").parent.should be_nil
176
279
  end
@@ -215,23 +318,23 @@ describe "Page", :shared => true do
215
318
 
216
319
  describe "with metadata" do
217
320
  before(:each) do
218
- @layout = "my_layout"
219
- @template = "my_template"
220
- @date = "07 September 2009"
221
- @keywords = "things, stuff"
222
- @description = "Page about stuff"
321
+ @layout = 'my_layout'
322
+ @template = 'my_template'
323
+ @date = '07 September 2009'
324
+ @keywords = 'things, stuff'
325
+ @description = 'Page about stuff'
223
326
  @summary = 'Multiline\n\nsummary'
224
- @read_more = "Continue at your leisure"
225
- @skillz = "ruby, guitar, bowstaff"
327
+ @read_more = 'Continue at your leisure'
328
+ @skillz = 'ruby, guitar, bowstaff'
226
329
  @article = create_article(:metadata => {
227
- "layout" => @layout,
228
- "template" => @template,
229
- "date" => @date.gsub("September", "Sep"),
230
- "description" => @description,
231
- "keywords" => @keywords,
232
- "summary" => @summary,
233
- "read more" => @read_more,
234
- "skillz" => @skillz
330
+ 'layout' => @layout,
331
+ 'template' => @template,
332
+ 'date' => @date.gsub('September', 'Sep'),
333
+ 'description' => @description,
334
+ 'keywords' => @keywords,
335
+ 'summary' => @summary,
336
+ 'read more' => @read_more,
337
+ 'skillz' => @skillz
235
338
  })
236
339
  end
237
340
 
@@ -243,16 +346,16 @@ describe "Page", :shared => true do
243
346
  @article.template.should == @template.to_sym
244
347
  end
245
348
 
246
- it "should set permalink from filename" do
247
- @article.permalink.should == "my-article"
349
+ it "should set permalink to basename of filename" do
350
+ @article.permalink.should == 'my-article'
248
351
  end
249
352
 
250
353
  it "should set path from filename" do
251
- @article.path.should == "article-prefix/my-article"
354
+ @article.path.should == 'article-prefix/my-article'
252
355
  end
253
356
 
254
357
  it "should retrieve heading" do
255
- @article.heading.should == "My article"
358
+ @article.heading.should == 'My article'
256
359
  end
257
360
 
258
361
  it "should be possible to convert an article to HTML" do
data/spec/page_spec.rb CHANGED
@@ -81,6 +81,14 @@ describe "The home page" do
81
81
 
82
82
  before(:each) do
83
83
  stub_configuration
84
+ template_path = File.expand_path(
85
+ 'templates', File.dirname(File.dirname(__FILE__)))
86
+ create_category(
87
+ :path => 'index',
88
+ :ext => :haml,
89
+ :heading => 'Home',
90
+ :content => File.read(File.join(template_path, 'index.haml'))
91
+ )
84
92
  create_category
85
93
  end
86
94
 
@@ -106,32 +114,17 @@ describe "The home page" do
106
114
  last_response.should be_ok
107
115
  end
108
116
 
109
- it "should display title and subtitle in title tag" do
110
- do_get
111
- body.should have_tag("title", "My blog - about stuff")
112
- end
113
-
114
- it "should display site title in h1 tag" do
117
+ it "should display site title in hgroup tag" do
115
118
  pending "Hpricot doesn't support HTML5"
116
119
  body.should have_tag('hgroup h1', /My blog/)
117
120
  end
118
121
 
119
- it "should display site subtitle in heading tag" do
122
+ it "should display site subtitle in hgroup tag" do
120
123
  pending "Hpricot doesn't support HTML5"
121
124
  do_get
122
125
  body.should have_tag('hgroup h2', /about stuff/)
123
126
  end
124
127
 
125
- it "should set description meta tag" do
126
- do_get
127
- body.should have_tag("meta[@name=description][@content='great web site']")
128
- end
129
-
130
- it "should set keywords meta tag" do
131
- do_get
132
- body.should have_tag("meta[@name=keywords][@content='home, page']")
133
- end
134
-
135
128
  describe "when articles have no summary" do
136
129
  before(:each) do
137
130
  create_article
@@ -164,7 +157,7 @@ describe "The home page" do
164
157
  end
165
158
 
166
159
  it "should display article summary if available" do
167
- body.should have_tag("p", @summary.split('\n\n').first)
160
+ body.should have_tag('p', @summary.split('\n\n').first)
168
161
  end
169
162
 
170
163
  it "should display read more link" do
@@ -180,15 +173,15 @@ describe "An article" do
180
173
 
181
174
  before(:each) do
182
175
  stub_configuration
183
- @date = "07 September 2009"
184
- @keywords = "things, stuff"
185
- @description = "Page about stuff"
176
+ @date = '07 September 2009'
177
+ @keywords = 'things, stuff'
178
+ @description = 'Page about stuff'
186
179
  @summary = 'Multiline\n\nsummary'
187
180
  @article = create_article(:metadata => {
188
- "date" => @date.gsub("September", "Sep"),
189
- "description" => @description,
190
- "keywords" => @keywords,
191
- "summary" => @summary,
181
+ 'date' => @date.gsub('September', 'Sep'),
182
+ 'description' => @description,
183
+ 'keywords' => @keywords,
184
+ 'summary' => @summary
192
185
  })
193
186
  end
194
187
 
@@ -218,31 +211,31 @@ describe "An article" do
218
211
 
219
212
  it "should display the heading" do
220
213
  do_get
221
- body.should have_tag("h1", "My article")
214
+ body.should have_tag('h1', 'My article')
222
215
  end
223
216
 
224
- it "should not display category links" do
217
+ it "should use heading for title tag" do
225
218
  do_get
226
- body.should_not have_tag("div.breadcrumb div.categories", /filed in/)
219
+ body.should have_tag('title', 'My article - My blog')
227
220
  end
228
221
 
229
222
  it "should display the date" do
230
223
  do_get
231
- body.should have_tag("time", @date)
224
+ body.should have_tag('time', @date)
232
225
  end
233
226
 
234
227
  it "should display the content" do
235
228
  do_get
236
- body.should have_tag("p", "Content goes here")
229
+ body.should have_tag('p', 'Content goes here')
237
230
  end
238
231
 
239
232
  describe "that is assigned to categories" do
240
233
  before(:each) do
241
- create_category(:heading => "Apple", :path => "the-apple")
242
- @category = create_category(:heading => "Banana", :path => "banana")
234
+ create_category(:heading => 'Apple', :path => 'the-apple')
235
+ @category = create_category(:heading => 'Banana', :path => 'banana')
243
236
  @article = create_article(
244
237
  :path => "#{@category.path}/article",
245
- :metadata => { "categories" => "banana, the-apple" }
238
+ :metadata => { 'categories' => 'banana, the-apple' }
246
239
  )
247
240
  end
248
241
 
@@ -302,12 +295,17 @@ describe "A page" do
302
295
 
303
296
  describe "that has meta data" do
304
297
  before(:each) do
298
+ @title = 'Different title'
305
299
  @content = "Page content"
306
300
  @description = "Page about stuff"
307
301
  @keywords = "things, stuff"
308
302
  @category = create_category(
309
303
  :content => "# My category\n\n#{@content}",
310
- :metadata => { "description" => @description, "keywords" => @keywords }
304
+ :metadata => {
305
+ 'title' => @title,
306
+ 'description' => @description,
307
+ 'keywords' => @keywords
308
+ }
311
309
  )
312
310
  end
313
311
 
@@ -321,7 +319,12 @@ describe "A page" do
321
319
 
322
320
  it "should display the heading" do
323
321
  do_get
324
- body.should have_tag("h1", @category.heading)
322
+ body.should have_tag('h1', @category.heading)
323
+ end
324
+
325
+ it "should use title metadata to set heading" do
326
+ do_get
327
+ body.should have_tag('title', @title)
325
328
  end
326
329
 
327
330
  it "should display the content" do
@@ -329,6 +332,31 @@ describe "A page" do
329
332
  body.should have_tag("p", @content)
330
333
  end
331
334
 
335
+ describe "with associated pages" do
336
+ before(:each) do
337
+ @category1 = create_category(
338
+ :path => 'category1',
339
+ :heading => 'Category 1',
340
+ :metadata => {
341
+ 'categories' => 'category-prefix/my-category:-1'
342
+ }
343
+ )
344
+ @category2 = create_category(
345
+ :path => 'category2',
346
+ :heading => 'Category 2',
347
+ :metadata => {
348
+ 'categories' => 'category-prefix/my-category:1'
349
+ }
350
+ )
351
+ end
352
+
353
+ it "should list highest priority pages at the top" do
354
+ do_get
355
+ body.should have_tag('li:nth-child(1) h1 a', 'Category 2')
356
+ body.should have_tag('li:nth-child(2) h1 a', 'Category 1')
357
+ end
358
+ end
359
+
332
360
  describe "with associated articles" do
333
361
  before(:each) do
334
362
  @article = create_article(
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
- require "rubygems"
2
- require "spec"
3
- require "spec/interop/test"
4
- require "rack/test"
5
- require "rspec_hpricot_matchers"
6
- require "sinatra"
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'spec/interop/test'
4
+ require 'rack/test'
5
+ require 'rspec_hpricot_matchers'
6
+ require 'sinatra'
7
7
 
8
8
  Test::Unit::TestCase.send :include, Rack::Test::Methods
9
9
 
@@ -18,10 +18,10 @@ module Nesta
18
18
  end
19
19
  end
20
20
 
21
- require File.expand_path("../lib/nesta/app", File.dirname(__FILE__))
21
+ require File.expand_path('../lib/nesta/app', File.dirname(__FILE__))
22
22
 
23
23
  module FixtureHelper
24
- FIXTURE_DIR = File.expand_path("fixtures", File.dirname(__FILE__))
24
+ FIXTURE_DIR = File.expand_path('fixtures', File.dirname(__FILE__))
25
25
 
26
26
  def create_fixtures_directory
27
27
  FileUtils.mkdir_p(FixtureHelper::FIXTURE_DIR)
@@ -62,11 +62,9 @@ module ConfigSpecHelper
62
62
  end
63
63
 
64
64
  def stub_configuration(options = {})
65
- stub_config_key("title", "My blog", options)
66
- stub_config_key("subtitle", "about stuff", options)
67
- stub_config_key("description", "great web site", options)
68
- stub_config_key("keywords", "home, page", options)
69
- content_path = File.join(FixtureHelper::FIXTURE_DIR, "content")
70
- stub_config_key("content", content_path, options.merge(:rack_env => true))
65
+ stub_config_key('title', 'My blog', options)
66
+ stub_config_key('subtitle', 'about stuff', options)
67
+ content_path = File.join(FixtureHelper::FIXTURE_DIR, 'content')
68
+ stub_config_key('content', content_path, options.merge(:rack_env => true))
71
69
  end
72
70
  end
data/templates/Rakefile CHANGED
@@ -9,27 +9,3 @@ begin
9
9
  Vlad.load(:scm => :git, :app => nil, :web => nil)
10
10
  rescue LoadError
11
11
  end<% end %>
12
- <% if @options['heroku'] %>
13
- require 'nesta/config'
14
- require 'nesta/models'
15
-
16
- namespace :heroku do
17
- desc "Set Heroku config vars from config.yml"
18
- task :config do
19
- Nesta::App.environment = ENV['RACK_ENV'] || 'production'
20
- settings = {}
21
- Nesta::Config.settings.map do |variable|
22
- value = Nesta::Config.send(variable)
23
- value && settings["NESTA_#{variable.upcase}"] = value
24
- end
25
- if Nesta::Config.author
26
- Nesta::Config.author_settings.map do |author_var|
27
- value = Nesta::Config.author[author_var]
28
- if value
29
- value && settings["NESTA_AUTHOR__#{author_var.upcase}"] = value
30
- end
31
- end
32
- params = settings.map { |k, v| %Q{#{k}="#{v}"} }.join(" ")
33
- system("heroku config:add #{params}")
34
- end
35
- end<% end %>
@@ -4,12 +4,6 @@
4
4
  title: "My Site"
5
5
  subtitle: "(change this text in config/config.yml)"
6
6
 
7
- # If you want to set the descrition or keywords meta tags on your site's
8
- # home page, do it here.
9
- #
10
- # description: "Set this to something that describes your home page"
11
- # keywords: "enter 3 or 4, comma separated, keywords"
12
-
13
7
  # You should really specify your content's author when generating an
14
8
  # Atom feed. Specify at least one of name, uri or email, and Nesta will
15
9
  # include it in your feed. See the Atom spec for more info:
@@ -0,0 +1 @@
1
+ %section.articles= article_summaries(latest_articles)
data/views/atom.haml ADDED
@@ -0,0 +1,28 @@
1
+ !!! XML
2
+ %feed(xmlns='http://www.w3.org/2005/Atom')
3
+ %title(type='text')= @title
4
+ %generator(uri='http://effectif.com/nesta') Nesta
5
+ %id= atom_id
6
+ %link(href="#{base_url}/articles.xml" rel='self')
7
+ %link(href=base_url rel='alternate')
8
+ %subtitle(type='text')= @subtitle
9
+ - if @articles[0]
10
+ %updated= @articles[0].date(:xmlschema)
11
+ - if @author
12
+ %author
13
+ - if @author['name']
14
+ %name= @author['name']
15
+ - if @author['uri']
16
+ %uri= @author['uri']
17
+ - if @author['email']
18
+ %email= @author['email']
19
+ - @articles.each do |article|
20
+ %entry
21
+ %title= article.heading
22
+ %link{ :href => url_for(article), :type => 'text/html', :rel => 'alternate' }
23
+ %id= atom_id(article)
24
+ %content(type='html')&= find_and_preserve(absolute_urls(article.body))
25
+ %published= article.date(:xmlschema)
26
+ %updated= article.date(:xmlschema)
27
+ - article.categories.each do |category|
28
+ %category{ :term => category.permalink }
data/views/master.sass CHANGED
@@ -84,6 +84,13 @@ pre
84
84
  img
85
85
  border: none
86
86
 
87
+ nav.breadcrumb
88
+ margin-top: $vertical-rhythm
89
+ color: $meta-color
90
+ padding: 0.5em 0
91
+
92
+ font-size: 0.909em
93
+
87
94
  // Layout
88
95
 
89
96
  article, aside, footer, header, nav, section
@@ -94,13 +101,6 @@ div#container
94
101
  margin: 0 auto
95
102
  padding: 1em 1em 0 1em
96
103
 
97
- nav.breadcrumb
98
- margin-top: $vertical-rhythm
99
- color: $meta-color
100
- padding: 0.5em 0
101
-
102
- font-size: 0.909em
103
-
104
104
  div#content
105
105
  position: relative
106
106
  width: $content-width
@@ -138,17 +138,34 @@ a
138
138
  color: $active-link-color
139
139
  border-bottom-color: $active-link-color
140
140
 
141
+ nav.breadcrumb
142
+ ul
143
+ margin: 0
144
+ li
145
+ display: inline
146
+ list-style: none
147
+ &::after
148
+ content: " > "
149
+ &:last-child::after
150
+ content: ""
151
+
152
+ nav.breadcrumb,
141
153
  nav.categories,
142
154
  div.feed,
143
155
  article p.meta
144
156
  a
145
157
  color: $nav-link-color
146
- border-bottom-color: $background-color
147
158
  &:hover a
148
159
  color: $link-color
149
160
  a:hover
150
161
  color: $hover-link-color
151
162
 
163
+ nav.categories,
164
+ div.feed,
165
+ article p.meta
166
+ a
167
+ border-bottom-color: $background-color
168
+
152
169
  article p.meta
153
170
  a
154
171
  @include transition(border-bottom-color 0.5s 0 ease)
data/views/page.haml CHANGED
@@ -1,10 +1,5 @@
1
1
  %nav.breadcrumb
2
- %a(href="/") Home
3
- &gt;
4
- - if @page.parent
5
- %a(href="#{@page.parent.abspath}")= @page.parent.heading
6
- &gt;
7
- = @page.heading
2
+ - display_breadcrumbs
8
3
 
9
4
  #content
10
5
  %article(role="main")
@@ -0,0 +1,11 @@
1
+ !!! XML
2
+ %urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
3
+ %url
4
+ %loc= base_url
5
+ %changefreq daily
6
+ %priority 1.0
7
+ %lastmod= @last.xmlschema
8
+ - @pages.each do |page|
9
+ %url
10
+ %loc= url_for(page)
11
+ %lastmod= page.last_modified.xmlschema