orthorings 0.3.1 → 0.4.0

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.
@@ -8,24 +8,24 @@ module Sinatra
8
8
  @name = resource.name
9
9
  @meta_keywords = resource.keywords
10
10
  @meta_description = resource.description
11
- @orthor_feeds = resource.respond_to?(:feeds) ? resource.feeds : []
11
+ @orthor_feeds = resource.respond_to?(:feeds) ? resource.feeds : []
12
12
  end
13
13
  end
14
-
14
+
15
15
  module Orthor
16
16
  def self.registered(app)
17
17
  app.helpers ::OrthorHelper
18
18
  app.helpers Sinatra::OrthorRequestHelpers
19
-
19
+
20
20
  ::Orthor::Site.resources.each do |resource|
21
21
  if resource.is_a?(::Orthor::Category) && !resource.page_path.nil?
22
22
  get resource.page_path do |id|
23
- @orthor_content = orthor_content(id)
23
+ @orthor_content = orthor_content(id, (resource.page_template || resource.template))
24
24
  handle_request(resource)
25
25
  erb (resource.view || "orthor_content").to_sym, { :layout => ::Orthor::Site.layout }
26
26
  end
27
27
  end
28
-
28
+
29
29
  get resource.path do
30
30
  if resource.is_a?(::Orthor::Feed)
31
31
  headers['Cache-Control'] = "public, max-age=#{resource.cache_for}"
@@ -41,7 +41,7 @@ module Sinatra
41
41
  end
42
42
  end
43
43
  end
44
- end
44
+ end
45
45
  register Orthor
46
46
  end
47
47
 
data/orthorings.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{orthorings}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anthony Langhorne"]
12
- s.date = %q{2010-04-25}
12
+ s.date = %q{2010-06-06}
13
13
  s.email = %q{anthony@orthor.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -35,16 +35,18 @@ Gem::Specification.new do |s|
35
35
  "lib/orthor/query.rb",
36
36
  "lib/orthor/site.rb",
37
37
  "lib/orthor/static_page.rb",
38
+ "lib/orthor/templates.rb",
38
39
  "lib/orthor_helper.rb",
39
40
  "lib/orthorings.rb",
40
41
  "lib/sinatra/orthor.rb",
41
42
  "orthorings.gemspec",
42
43
  "spec/orthor/dsl_spec.rb",
44
+ "spec/orthor/templates_spec.rb",
43
45
  "spec/orthor_helper_spec.rb",
44
46
  "spec/orthorings_spec.rb",
45
- "spec/resources/homepage.html",
46
- "spec/resources/latest-news-items.html",
47
- "spec/resources/news.html",
47
+ "spec/resources/homepage.json",
48
+ "spec/resources/latest-news-items.json",
49
+ "spec/resources/news.json",
48
50
  "spec/sinatra/orthor_spec.rb",
49
51
  "spec/spec.opts",
50
52
  "spec/spec_helper.rb"
@@ -52,10 +54,11 @@ Gem::Specification.new do |s|
52
54
  s.homepage = %q{http://github.com/anthony/orthorings}
53
55
  s.rdoc_options = ["--charset=UTF-8"]
54
56
  s.require_paths = ["lib"]
55
- s.rubygems_version = %q{1.3.5}
56
- s.summary = %q{Orthorings is a gem for displaying content from orthor.com}
57
+ s.rubygems_version = %q{1.3.6}
58
+ s.summary = %q{A gem for displaying content from orthor.com}
57
59
  s.test_files = [
58
60
  "spec/orthor/dsl_spec.rb",
61
+ "spec/orthor/templates_spec.rb",
59
62
  "spec/orthor_helper_spec.rb",
60
63
  "spec/orthorings_spec.rb",
61
64
  "spec/sinatra/orthor_spec.rb",
@@ -68,10 +71,14 @@ Gem::Specification.new do |s|
68
71
 
69
72
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
73
  s.add_runtime_dependency(%q<moneta>, ["= 0.6.0"])
74
+ s.add_runtime_dependency(%q<json>, [">= 0"])
71
75
  else
72
76
  s.add_dependency(%q<moneta>, ["= 0.6.0"])
77
+ s.add_dependency(%q<json>, [">= 0"])
73
78
  end
74
79
  else
75
80
  s.add_dependency(%q<moneta>, ["= 0.6.0"])
81
+ s.add_dependency(%q<json>, [">= 0"])
76
82
  end
77
83
  end
84
+
@@ -8,63 +8,54 @@ describe Orthor::Site, "orthor site dsl" do
8
8
  layout :application
9
9
  end
10
10
  end
11
-
11
+
12
12
  it 'should allow a http cache time to be set' do
13
13
  Orthor::Site.cache_for.should == 7200
14
14
  end
15
-
15
+
16
16
  it 'should allow setting of a layout' do
17
17
  Orthor::Site.layout.should == :application
18
18
  end
19
-
19
+
20
20
  [ :categories, :feeds, :pages, :static_pages, :queries ].each do |collection|
21
21
  it "should have a #{collection} array" do
22
22
  Orthor::Site.send(collection).should == []
23
23
  end
24
24
  end
25
25
  end
26
-
26
+
27
27
  describe "default values" do
28
28
  before(:all) do
29
29
  Orthor::Site.define do
30
30
  end
31
31
  end
32
-
32
+
33
33
  it 'should set a default cache for time' do
34
34
  Orthor::Site.cache_for.should == 0
35
35
  end
36
-
36
+
37
37
  it 'should set a default layout' do
38
38
  Orthor::Site.layout.should == :orthor_layout
39
39
  end
40
40
  end
41
-
41
+
42
42
  describe "children" do
43
43
  before(:all) do
44
44
  Orthor::Site.define do
45
- page "/", "Home"
45
+ page "/", :id => "home"
46
46
 
47
- query "/news" do
48
- id "latest-news"
49
- end
50
-
51
- category "/writings" do
52
- page "/writings/why", "Why we write"
47
+ query "/news", :id => "latest-news"
53
48
 
54
- feed "/writings.rss" do
55
- id "our-writings"
56
- name "Our Writings"
57
- end
58
-
59
- query "/latest" do
60
- id "latest-article"
61
- end
49
+ category "/writings" do
50
+ page "/writings/why"
51
+ feed "/writings.rss", :id => "our-writings"
52
+ query "/latest", :id => "latest-article"
62
53
 
63
54
  category "/writings/announcements" do
64
- page "/3rd-level", "3rd level"
55
+ page "/3rd-level"
65
56
  end
66
57
  end
67
- end
58
+ end
68
59
  @category_1 = Orthor::Site.categories.first
69
60
  @category_2 = @category_1.categories.first
70
61
  @feed = @category_1.feeds.first
@@ -74,163 +65,146 @@ describe Orthor::Site, "orthor site dsl" do
74
65
  @query = Orthor::Site.queries.first
75
66
  @query_1 = @category_1.queries.first
76
67
  end
77
-
68
+
78
69
  it 'should return all resources defined in the dsl' do
79
70
  Orthor::Site.resources.length.should == 8
80
-
71
+
81
72
  Orthor::Site.resources.should include(@category_1)
82
73
  Orthor::Site.resources.should include(@category_2)
83
74
  Orthor::Site.resources.should include(@feed)
84
75
  Orthor::Site.resources.should include(@page_1)
85
76
  Orthor::Site.resources.should include(@page_2)
86
- Orthor::Site.resources.should include(@page_3)
77
+ Orthor::Site.resources.should include(@page_3)
87
78
  Orthor::Site.resources.should include(@query)
88
79
  Orthor::Site.resources.should include(@query_1)
89
80
  end
90
81
  end
91
-
82
+
92
83
  describe "categories" do
93
84
  before(:all) do
94
85
  Orthor::Site.define do
95
- category "/writings" do
96
- page_path "/writings/:id"
97
- name "Writings"
98
- id "blog-writings"
99
- cache_for 900
100
- view "writings/index"
101
-
102
- page "/writings/why" do
103
- name "Why we write"
104
- end
86
+ category "/writings", :id => "blog-writings",
87
+ :template => :writing,
88
+ :cache_for => 900,
89
+ :view => "writings/index",
90
+ :page_path => "/writings/:id" do
91
+ page "/writings/why"
92
+ feed "/writings.rss", :id => "our-writings", :name => "Our Writings"
105
93
 
106
- feed "/writings.rss" do
107
- id "our-writings"
108
- name "Our Writings"
109
- end
110
-
111
- category "/writings/announcements" do
112
- page_path "/writings/announcements/:id"
113
- name "Announcements"
114
- cache_for 300
115
-
116
- page "/3rd-level" do
117
- name "3rd level"
118
- end
94
+ category "/writings/announcements", :page_path => "/writings/announcements/:id",
95
+ :cache_for => 300,
96
+ :template => :announcement do
97
+ page "/3rd-level"
119
98
  end
120
99
  end
121
100
  end
122
101
  @category = Orthor::Site.categories.first
123
102
  @category_2 = Orthor::Site.categories.first.categories.first
124
103
  end
125
-
104
+
126
105
  it "should have one category at the top level" do
127
106
  Orthor::Site.categories.length.should == 1
128
- @category.name.should == "Writings"
129
107
  end
130
-
108
+
131
109
  it "should allow you to set a custom view file" do
132
110
  @category.view.should == "writings/index"
133
111
  end
134
-
112
+
113
+ it "should allow setting of a template" do
114
+ @category.template.should == :writing
115
+ @category_2.template.should == :announcement
116
+ end
117
+
135
118
  it "should support categories in categories" do
136
119
  @category.categories.length.should == 1
137
- @category_2.name.should == "Announcements"
138
120
  end
139
-
121
+
140
122
  it "should support pages in categories" do
141
123
  @category.pages.length.should == 1
142
- @category.pages.first.name.should == "Why we write"
143
124
  end
144
-
125
+
145
126
  it "id should be inferred from the path if none is given" do
146
127
  @category_2.id.should == "announcements"
147
128
  end
148
-
129
+
149
130
  it "should support pages in categories in categories" do
150
131
  @category_2.pages.length.should == 1
151
- @category_2.pages.first.name.should == "3rd level"
152
132
  end
153
-
133
+
154
134
  it "should support a child page path attribute" do
155
135
  @category.page_path.should == "/writings/:id"
156
136
  end
157
-
137
+
158
138
  it "should support setting the orthor id" do
159
139
  @category.id.should == "blog-writings"
160
140
  end
161
-
141
+
162
142
  it "should support specifying http cache time" do
163
143
  @category.cache_for.should == 900
164
144
  @category_2.cache_for.should == 300
165
145
  end
166
-
146
+
167
147
  it "should support feeds specific to categories" do
168
148
  @category.feeds.length.should == 1
169
- @category.feeds.first.name.should == "Our Writings"
170
149
  end
171
150
  end
172
-
151
+
173
152
  describe "pages" do
174
153
  before(:all) do
175
154
  Orthor::Site.define do
176
- page "/about-us", "about" do
177
- name "About us"
178
- end
155
+ page "/about-us", :id => "about"
156
+ page "/history", :id => "our-history", :template => :basic
179
157
  page "/contact"
180
- page "/" do
181
- name "Home"
182
- cache_for 3600
183
- id "homepage"
184
- view "public/home"
185
- end
158
+ page "/", :cache_for => 3600, :id => "homepage",
159
+ :view => "public/home", :template => :brief
186
160
  end
187
161
  @page_1 = Orthor::Site.pages[0]
188
162
  @page_2 = Orthor::Site.pages[1]
189
163
  @page_3 = Orthor::Site.pages[2]
164
+ @page_4 = Orthor::Site.pages[3]
190
165
  end
191
-
166
+
192
167
  it 'should support multiple pages' do
193
- Orthor::Site.pages.length.should == 3
168
+ Orthor::Site.pages.length.should == 4
194
169
  end
195
-
196
- it 'should support specifying pages with or without a block' do
197
- @page_1.name.should == "About us"
170
+
171
+ it 'should support storing a page path' do
198
172
  @page_1.path.should == "/about-us"
199
-
200
- @page_3.name.should == "Home"
201
- @page_3.path.should == "/"
173
+ @page_4.path.should == "/"
202
174
  end
203
-
175
+
176
+ it "should allow setting of template" do
177
+ @page_2.template.should == :basic
178
+ @page_4.template.should == :brief
179
+ end
180
+
204
181
  it "should be able to specify a view to render" do
205
- @page_3.view.should == "public/home"
182
+ @page_4.view.should == "public/home"
206
183
  @page_1.view.should be_nil
207
184
  end
208
-
185
+
209
186
  it "id should be inferred from the path if none is given" do
210
- @page_2.id.should == "contact"
187
+ @page_3.id.should == "contact"
211
188
  end
212
189
 
213
190
  it "id should be 2nd argument if any is given" do
214
191
  @page_1.id.should == "about"
215
192
  end
216
-
193
+
217
194
  it 'should allow setting specific http cache lengths' do
218
195
  @page_1.cache_for.should == 0 # sites default
219
- @page_3.cache_for.should == 3600
196
+ @page_4.cache_for.should == 3600
220
197
  end
221
-
198
+
222
199
  it 'should support setting an id' do
223
- @page_3.id.should == "homepage"
200
+ @page_4.id.should == "homepage"
224
201
  end
225
202
  end
226
203
 
227
204
  describe "queries" do
228
205
  before(:all) do
229
206
  Orthor::Site.define do
230
- query "/news" do
231
- id "news"
232
- end
233
-
207
+ query "/news", :id => "news", :template => :query
234
208
  query "/latest-release"
235
209
  end
236
210
  @query_1 = Orthor::Site.queries.first
@@ -241,6 +215,10 @@ describe Orthor::Site, "orthor site dsl" do
241
215
  Orthor::Site.queries.length.should == 2
242
216
  end
243
217
 
218
+ it "should support setting a template" do
219
+ @query_1.template.should == :query
220
+ end
221
+
244
222
  it "should support setting a query id" do
245
223
  @query_1.id.should == "news"
246
224
  end
@@ -249,64 +227,86 @@ describe Orthor::Site, "orthor site dsl" do
249
227
  @query_2.id.should == "latest-release"
250
228
  end
251
229
  end
252
-
253
- describe "feeds" do
230
+
231
+ describe "with layout" do
254
232
  before(:all) do
255
233
  Orthor::Site.define do
256
- feed "/blog.rss" do
257
- id "orthor-blog"
258
- name "Our blag"
234
+ with_template :spike do
235
+ page "/"
236
+ category "/news" do
237
+ template :spike_v2
238
+ end
259
239
  end
260
-
261
- feed "/bookmarks.rss" do
262
- name "Our bookmarks"
240
+
241
+ with_template :jet do
242
+ query "/latest-news"
243
+ page "/about"
263
244
  end
264
245
  end
265
-
246
+ @page_1 = Orthor::Site.pages[0]
247
+ @page_2 = Orthor::Site.pages[1]
248
+ @query = Orthor::Site.queries[0]
249
+ @category = Orthor::Site.categories[0]
250
+ end
251
+
252
+ it "should respect with_template" do
253
+ @page_1.template.should == :spike
254
+ @page_2.template.should == :jet
255
+ @query.template.should == :jet
256
+ end
257
+
258
+ it "should allow with_template to be overriden" do
259
+ @category.template.should == :spike_v2
260
+ end
261
+ end
262
+
263
+ describe "feeds" do
264
+ before(:all) do
265
+ Orthor::Site.define do
266
+ feed "/blog.rss", :id => "orthor-blog",
267
+ :name => "Our blag"
268
+ feed "/bookmarks.rss", :name => "Our bookmarks"
269
+ end
270
+
266
271
  @feed_1 = Orthor::Site.feeds.first
267
272
  @feed_2 = Orthor::Site.feeds.last
268
273
  end
269
-
274
+
270
275
  it "should support multiple feeds" do
271
276
  Orthor::Site.feeds.length.should == 2
272
277
  end
273
-
278
+
274
279
  it "should support setting a feeds id" do
275
280
  @feed_1.id.should == "orthor-blog"
276
281
  end
277
-
282
+
278
283
  it "id should be inferred from the path if none is given" do
279
284
  @feed_2.id.should == "bookmarks.rss"
280
285
  end
281
-
286
+
282
287
  it 'should support setting a feeds name' do
283
288
  @feed_1.name.should == "Our blag"
284
289
  @feed_2.name.should == "Our bookmarks"
285
290
  end
286
-
291
+
287
292
  it 'should store the given path' do
288
293
  @feed_1.path.should == "/blog.rss"
289
294
  @feed_2.path.should == "/bookmarks.rss"
290
295
  end
291
296
  end
292
-
297
+
293
298
  describe 'static pages' do
294
299
  before(:all) do
295
300
  Orthor::Site.define do
296
- static_page "/about-us", "About us"
297
- static_page "/contact", "Contact Us"
298
- static_page "/" do
299
- name "Home"
300
- cache_for 3600
301
- view :blah
302
- controller :asdf
303
- end
301
+ static_page "/about-us"
302
+ static_page "/contact"
303
+ static_page "/", :cache_for => 3600, :view => :blah, :controller => :asdf
304
304
  end
305
305
  @page_1 = Orthor::Site.static_pages[0]
306
306
  @page_2 = Orthor::Site.static_pages[1]
307
307
  @page_3 = Orthor::Site.static_pages[2]
308
308
  end
309
-
309
+
310
310
  it 'should support multiple pages' do
311
311
  Orthor::Site.static_pages.length.should == 3
312
312
  end
@@ -318,37 +318,29 @@ describe Orthor::Site, "orthor site dsl" do
318
318
  it 'should support setting controller' do
319
319
  @page_3.controller.should == :asdf
320
320
  end
321
-
322
- it 'should support specifying pages with or without a block' do
323
- @page_1.name.should == "About us"
321
+
322
+ it 'should support storing page path' do
324
323
  @page_1.path.should == "/about-us"
325
-
326
- @page_3.name.should == "Home"
327
324
  @page_3.path.should == "/"
328
325
  end
329
-
326
+
330
327
  it 'should allow setting specific http cache lengths' do
331
328
  @page_3.cache_for.should == 3600
332
329
  end
333
330
  end
334
-
331
+
335
332
  describe 'finding by path' do
336
333
  before(:all) do
337
334
  Orthor::Site.define do
338
- page "/", "Home"
339
-
340
- category "/writings" do
341
- page_path "/writings/:id"
342
- page "/writings/why", "Why we write"
335
+ page "/"
343
336
 
344
- feed "/writings.rss" do
345
- id "our-writings"
346
- name "Our Writings"
347
- end
337
+ category "/writings", :page_path => "/writings/:id" do
338
+ page "/writings/why"
339
+ feed "/writings.rss", :id => "our-writings",
340
+ :name => "Our Writings"
348
341
 
349
- category "/writings/announcements" do
350
- page_path "/writings/announcements/:id"
351
- page "/3rd-level", "3rd level"
342
+ category "/writings/announcements", :page_path => "/writings/announcements/:id" do
343
+ page "/3rd-level"
352
344
  end
353
345
  end
354
346
  end
@@ -358,66 +350,60 @@ describe Orthor::Site, "orthor site dsl" do
358
350
  @announcements = @writings.categories.first
359
351
  @third_level = @announcements.pages.first
360
352
  end
361
-
353
+
362
354
  it 'should be able to find pages by path' do
363
355
  Orthor::Site.find_resource_by_path("/").should == @home
364
356
  Orthor::Site.find_resource_by_path("/3rd-level").should == @third_level
365
357
  end
366
-
358
+
367
359
  it 'should be able to find feeds by path' do
368
360
  Orthor::Site.find_resource_by_path("/writings.rss").should == @feed
369
361
  end
370
-
362
+
371
363
  it 'should be able to find categories by path' do
372
364
  Orthor::Site.find_resource_by_path("/writings").should == @writings
373
365
  Orthor::Site.find_resource_by_path("/writings/announcements").should == @announcements
374
366
  end
375
-
367
+
376
368
  it 'should find the parent category by page path' do
377
369
  Orthor::Site.find_resource_by_page_path("/writings/announcements/first-entry", "first-entry").should == @announcements
378
370
  Orthor::Site.find_resource_by_page_path("/writings/first-writing", "first-writing").should == @writings
379
371
  end
380
372
  end
381
-
373
+
382
374
  describe 'meta data' do
383
375
  before(:all) do
384
376
  Orthor::Site.define do
385
377
  keywords "asdf, bob, frank"
386
378
  description "a site being defined"
387
-
388
- page "/features", "Features" do
389
- keywords "features"
390
- description "feature page description"
391
- end
392
-
393
- category "/news", "News" do
394
- keywords "category"
395
- description "category description"
396
- end
397
-
379
+
380
+ page "/features", :keywords => "features",
381
+ :description => "feature page description"
382
+ category "/news", :keywords => "category",
383
+ :description => "category description"
398
384
  page "/ihavenothing"
399
385
  end
400
-
386
+
401
387
  @page_with_meta = Orthor::Site.pages.first
402
388
  @category = Orthor::Site.categories.first
403
389
  @page_no_meta = Orthor::Site.pages.last
404
390
  end
405
-
391
+
406
392
  it 'should allow setting of meta data at a site level' do
407
393
  Orthor::Site.keywords.should == "asdf, bob, frank"
408
394
  Orthor::Site.description.should == "a site being defined"
409
395
  end
410
-
396
+
411
397
  it 'should allow setting of meta data at a page level' do
412
398
  @page_with_meta.keywords.should == "features"
413
399
  @page_with_meta.description.should == "feature page description"
414
400
  end
415
-
401
+
416
402
  it 'should allow setting of meta data at a category level' do
417
403
  @category.keywords.should == "category"
418
404
  @category.description.should == "category description"
419
405
  end
420
-
406
+
421
407
  it 'should default to sites meta data if none given' do
422
408
  @page_no_meta.keywords.should == "asdf, bob, frank"
423
409
  @page_no_meta.description.should == "a site being defined"