baron 1.0.12 → 1.0.13
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/VERSION +1 -1
- data/baron.gemspec +2 -1
- data/lib/baron.rb +9 -10
- data/lib/baron/blog_engine.rb +9 -14
- data/lib/baron/config.rb +2 -1
- data/lib/baron/models/article.rb +32 -6
- data/lib/baron/models/theme.rb +7 -2
- data/lib/baron/page_controller.rb +1 -1
- data/lib/baron/utils.rb +0 -8
- data/spec/baron_article_spec.rb +24 -23
- data/spec/baron_blog_engine_spec.rb +1 -1
- data/spec/baron_spec.rb +16 -6
- data/spec/sample_data/resources/feed.atom +23 -0
- data/spec/sample_data/resources/robots.txt +4 -2
- data/spec/sample_data/themes/typography/templates/layout.rhtml +1 -1
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.13
|
data/baron.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "baron"
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nathan Buggia"]
|
@@ -47,6 +47,7 @@ Gem::Specification.new do |s|
|
|
47
47
|
"spec/sample_data/images/robert-frost.png",
|
48
48
|
"spec/sample_data/pages/about.rhtml",
|
49
49
|
"spec/sample_data/pages/test.rhtml",
|
50
|
+
"spec/sample_data/resources/feed.atom",
|
50
51
|
"spec/sample_data/resources/redirects.txt",
|
51
52
|
"spec/sample_data/resources/robots.txt",
|
52
53
|
"spec/sample_data/supplemental-files/theme_config.yml",
|
data/lib/baron.rb
CHANGED
@@ -4,6 +4,7 @@ $:.unshift File.dirname(__FILE__)
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'date'
|
6
6
|
require 'erb'
|
7
|
+
require 'time'
|
7
8
|
|
8
9
|
# 3rd party
|
9
10
|
require 'rack'
|
@@ -41,24 +42,22 @@ module Baron
|
|
41
42
|
return [400, {}, []] unless @request.get?
|
42
43
|
|
43
44
|
@response = Rack::Response.new
|
44
|
-
|
45
|
-
|
45
|
+
|
46
|
+
path, ext = @request.path_info.split('.')
|
47
|
+
extension = ext.to_s.empty? ? '.html' : ".#{ext}"
|
48
|
+
|
49
|
+
redirected_url, status = @blog_engine.process_redirects(@request.path_info)
|
46
50
|
|
47
51
|
if status
|
48
52
|
@response.status = status
|
49
53
|
@response['Location'] = redirected_url
|
50
54
|
else
|
51
|
-
baron_response = @blog_engine.process_request(
|
55
|
+
baron_response = @blog_engine.process_request(@request.path_info, env)
|
52
56
|
@response.body = [baron_response[:body]]
|
53
57
|
@response.status = baron_response[:status]
|
54
58
|
@response['Content-Length'] = baron_response[:body].bytesize.to_s unless baron_response[:body].empty?
|
55
|
-
@response['Content-Type'] = Rack::Mime.mime_type(
|
56
|
-
@response['Cache-Control'] =
|
57
|
-
"public, max-age=#{@config[:cache]}"
|
58
|
-
else
|
59
|
-
"no-cache, must-revalidate"
|
60
|
-
end
|
61
|
-
|
59
|
+
@response['Content-Type'] = Rack::Mime.mime_type(extension)
|
60
|
+
@response['Cache-Control'] = (Baron.env == 'production') ? "public, max-age=#{@config[:cache]}" : "no-cache, must-revalidate"
|
62
61
|
@response['ETag'] = %("#{Digest::SHA1.hexdigest(baron_response[:body])}")
|
63
62
|
end
|
64
63
|
|
data/lib/baron/blog_engine.rb
CHANGED
@@ -16,27 +16,26 @@ module Baron
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def process_request path, env = {}
|
19
|
+
def process_request path, env = {}
|
20
20
|
route = (path || '/').split('/').reject { |i| i.empty? }
|
21
21
|
route << @config[:root] if route.empty?
|
22
|
-
mime_type = (mime_type =~ /txt|rss|json/) ? mime_type.to_sym : :html
|
23
22
|
categories = get_all_categories
|
24
|
-
params = {:page_name => route.first, :
|
23
|
+
params = {:page_name => route.first, :feed_permalink => @config.get_feed_permalink}
|
25
24
|
params[:page_title] = (route.first == @config[:root] ? '' : "#{route.first.capitalize} #{@config[:title_delimiter]} ") + "#{@config[:title]}"
|
26
25
|
theme = Theme.new(@config)
|
27
26
|
theme.load_config
|
28
27
|
|
29
28
|
begin
|
30
29
|
|
31
|
-
#
|
32
|
-
body = if
|
30
|
+
# Atom feed... /feed.atom
|
31
|
+
body = if route.first == 'feed.atom'
|
33
32
|
PageController.new(get_all_articles, categories, @config[:article_max], params, theme, @config) .
|
34
|
-
|
33
|
+
render(get_system_resource('feed.atom'))
|
35
34
|
|
36
35
|
# Robots... /robots.txt
|
37
|
-
elsif route.first == 'robots'
|
36
|
+
elsif route.first == 'robots.txt'
|
38
37
|
PageController.new(get_all_articles, categories, @config[:article_max], params, theme, @config) .
|
39
|
-
|
38
|
+
render(get_system_resource('robots.txt'))
|
40
39
|
|
41
40
|
# Home page... /
|
42
41
|
elsif route.first == @config[:root]
|
@@ -89,7 +88,7 @@ module Baron
|
|
89
88
|
render_html(theme.get_template('article'), theme.get_template('layout'))
|
90
89
|
end
|
91
90
|
|
92
|
-
return :body => body, :
|
91
|
+
return :body => body, :status => 200
|
93
92
|
|
94
93
|
rescue Errno::ENOENT => e
|
95
94
|
|
@@ -99,7 +98,7 @@ module Baron
|
|
99
98
|
body = PageController.new([], categories, 0, params, theme, @config) .
|
100
99
|
render_html(theme.get_template('error'), theme.get_template('layout'))
|
101
100
|
|
102
|
-
return :body => body, :
|
101
|
+
return :body => body, :status => 404
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
@@ -176,10 +175,6 @@ module Baron
|
|
176
175
|
def get_system_resource name
|
177
176
|
"#{@config[:sample_data_path]}resources/#{name}".squeeze('/')
|
178
177
|
end
|
179
|
-
|
180
|
-
def get_feed_path
|
181
|
-
"#{@config[:url]}/feed.rss"
|
182
|
-
end
|
183
178
|
end
|
184
179
|
|
185
180
|
end
|
data/lib/baron/config.rb
CHANGED
data/lib/baron/models/article.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Baron
|
2
|
+
|
2
3
|
class Article < Hash
|
4
|
+
|
3
5
|
def initialize file_parts, config = {}
|
4
6
|
@config = config
|
5
7
|
self[:filename_and_path] = file_parts[:filename_and_path]
|
@@ -36,12 +38,34 @@ module Baron
|
|
36
38
|
"/#{permalink_prefix}/#{self[:category]}#{date_path}/#{slug}/".squeeze('/')
|
37
39
|
end
|
38
40
|
|
39
|
-
def title
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def
|
44
|
-
|
41
|
+
def title
|
42
|
+
self[:title] || 'Untitled'
|
43
|
+
end
|
44
|
+
|
45
|
+
def date
|
46
|
+
@config[:date].call(self[:date])
|
47
|
+
end
|
48
|
+
|
49
|
+
def date_iso8601
|
50
|
+
# "2009-10-26T04:47:09Z"
|
51
|
+
self[:date].strftime("%FT%T%:z")
|
52
|
+
end
|
53
|
+
|
54
|
+
def author
|
55
|
+
self[:author] || @config[:author]
|
56
|
+
end
|
57
|
+
|
58
|
+
def category
|
59
|
+
self[:category]
|
60
|
+
end
|
61
|
+
|
62
|
+
def permalink
|
63
|
+
"http://#{(@config[:url].sub("http://", '') + self.path).squeeze('/')}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def slug
|
67
|
+
self[:slug]
|
68
|
+
end
|
45
69
|
|
46
70
|
protected
|
47
71
|
|
@@ -57,5 +81,7 @@ module Baron
|
|
57
81
|
text.strip
|
58
82
|
end
|
59
83
|
end
|
84
|
+
|
60
85
|
end
|
86
|
+
|
61
87
|
end
|
data/lib/baron/models/theme.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Baron
|
2
|
+
|
2
3
|
class Theme < Hash
|
4
|
+
|
3
5
|
def initialize config
|
4
6
|
@config = config
|
5
7
|
self[:root] = "/themes/#{config[:theme]}"
|
@@ -13,13 +15,16 @@ module Baron
|
|
13
15
|
params = YAML.load(File.read(filename_and_path))
|
14
16
|
params.each_pair { |key, value| self[key.downcase.to_sym] = value } unless !params
|
15
17
|
rescue Errno::ENOENT => e
|
16
|
-
puts "Warning: unable to load config file : " + filename_and_path
|
18
|
+
# puts "Warning: unable to load config file : " + filename_and_path
|
17
19
|
end
|
18
20
|
|
19
|
-
def root
|
21
|
+
def root
|
22
|
+
self[:root]
|
23
|
+
end
|
20
24
|
|
21
25
|
def get_template name
|
22
26
|
"#{self[:file_root]}/templates/#{name}.rhtml".squeeze('/')
|
23
27
|
end
|
24
28
|
end
|
29
|
+
|
25
30
|
end
|
data/lib/baron/utils.rb
CHANGED
@@ -15,14 +15,6 @@ class Fixnum
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Avoid a collision with ActiveSupport
|
18
|
-
class Date
|
19
|
-
unless respond_to? :iso8601
|
20
|
-
# Return the date as a String formatted according to ISO 8601.
|
21
|
-
def iso8601
|
22
|
-
::Time.utc(year, month, day, 0, 0, 0, 0).iso8601
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
18
|
|
27
19
|
class String
|
28
20
|
# Support String::bytesize in old versions of Ruby
|
data/spec/baron_article_spec.rb
CHANGED
@@ -17,37 +17,38 @@ describe "Baron::Article" do
|
|
17
17
|
|
18
18
|
describe "Provides access to properties" do
|
19
19
|
it "should return input parameters" do
|
20
|
-
@article[:filename_and_path].should
|
20
|
+
@article[:filename_and_path].should == @article_parts[:filename_and_path]
|
21
21
|
@article[:date].should be_instance_of(Date)
|
22
|
-
@article[:category].should
|
22
|
+
@article[:category].should == @article_parts[:category]
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should return article data correctly" do
|
26
|
-
@article[:title].should
|
27
|
-
@article.title.should
|
28
|
-
@article
|
29
|
-
@article.
|
26
|
+
@article[:title].should == 'The Road Not Taken'
|
27
|
+
@article.title.should == 'The Road Not Taken'
|
28
|
+
@article.date.should == '01/01/1916'
|
29
|
+
@article.date_iso8601.should == '1916-01-01T00:00:00+00:00'
|
30
|
+
@article[:author].should == 'Robert Frost'
|
31
|
+
@article.author.should == 'Robert Frost'
|
30
32
|
@article[:body].length.should > 0
|
31
|
-
@article[:category].should
|
32
|
-
@article.category.should
|
33
|
-
@article[:slug].should
|
34
|
-
@article.slug.should
|
33
|
+
@article[:category].should == 'poems'
|
34
|
+
@article.category.should == 'poems'
|
35
|
+
@article[:slug].should == 'the-road-not-taken'
|
36
|
+
@article.slug.should == 'the-road-not-taken'
|
35
37
|
end
|
36
38
|
|
37
39
|
it "should handle different path configuations" do
|
38
|
-
@article.path('', :no_date).should
|
39
|
-
@article.path('', :year_month_day_date).should
|
40
|
-
@article.path('', :year_month_date).should
|
41
|
-
@article.path('', :year_date).should
|
42
|
-
@article.path('posts', :no_date).should
|
43
|
-
@article.path('posts', :year_month_day_date).should
|
44
|
-
@article.path('posts', :year_month_date).should
|
45
|
-
@article.path('posts', :year_date).should
|
46
|
-
@article.path('/foo/bar/', :no_date).should
|
47
|
-
@article.path('/foo/bar/', :
|
48
|
-
@article.path('/foo/bar/', :
|
49
|
-
@article.path('/foo/bar/', :
|
50
|
-
@article.path('/foo/bar/', :year_date).should eq('/foo/bar/poems/1916/the-road-not-taken/')
|
40
|
+
@article.path('', :no_date).should == '/poems/the-road-not-taken/'
|
41
|
+
@article.path('', :year_month_day_date).should == '/poems/1916/01/01/the-road-not-taken/'
|
42
|
+
@article.path('', :year_month_date).should == '/poems/1916/01/the-road-not-taken/'
|
43
|
+
@article.path('', :year_date).should == '/poems/1916/the-road-not-taken/'
|
44
|
+
@article.path('posts', :no_date).should == '/posts/poems/the-road-not-taken/'
|
45
|
+
@article.path('posts', :year_month_day_date).should == '/posts/poems/1916/01/01/the-road-not-taken/'
|
46
|
+
@article.path('posts', :year_month_date).should == '/posts/poems/1916/01/the-road-not-taken/'
|
47
|
+
@article.path('posts', :year_date).should == '/posts/poems/1916/the-road-not-taken/'
|
48
|
+
@article.path('/foo/bar/', :no_date).should == '/foo/bar/poems/the-road-not-taken/'
|
49
|
+
@article.path('/foo/bar/', :year_month_day_date).should == '/foo/bar/poems/1916/01/01/the-road-not-taken/'
|
50
|
+
@article.path('/foo/bar/', :year_month_date).should == '/foo/bar/poems/1916/01/the-road-not-taken/'
|
51
|
+
@article.path('/foo/bar/', :year_date).should == '/foo/bar/poems/1916/the-road-not-taken/'
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -19,7 +19,7 @@ describe "Baron::BlogEngine" do
|
|
19
19
|
@blog_engine.get_page_template('about').should == SAMPLE_DATA_PATH + 'pages/about.rhtml'
|
20
20
|
@blog_engine.get_system_resource('redirects.txt').should == SAMPLE_DATA_PATH + 'resources/redirects.txt'
|
21
21
|
@blog_engine.get_system_resource('robots.txt').should == SAMPLE_DATA_PATH + 'resources/robots.txt'
|
22
|
-
@blog_engine.get_system_resource('feeds.
|
22
|
+
@blog_engine.get_system_resource('feeds.atom').should == SAMPLE_DATA_PATH + 'resources/feeds.atom'
|
23
23
|
end
|
24
24
|
|
25
25
|
it "finds all categories" do
|
data/spec/baron_spec.rb
CHANGED
@@ -15,6 +15,10 @@ shared_examples_for "Server HTML Response" do
|
|
15
15
|
it "should be instrumented" do
|
16
16
|
@response.body.should include(GOOGLE_ANALYTICS) unless GOOGLE_ANALYTICS.empty?
|
17
17
|
end
|
18
|
+
|
19
|
+
it "returns HTML content type" do
|
20
|
+
@response['Content-Type'].should == 'text/html'
|
21
|
+
end
|
18
22
|
|
19
23
|
it "should generate valid HTML" do
|
20
24
|
@response.body.scan(/<html/).count.should == 1
|
@@ -117,24 +121,24 @@ describe "Baron" do
|
|
117
121
|
|
118
122
|
end
|
119
123
|
|
120
|
-
describe "GET /feed.
|
124
|
+
describe "GET /feed.atom" do
|
121
125
|
before :all do
|
122
|
-
@response = @baron.get('/feed.
|
126
|
+
@response = @baron.get('/feed.atom')
|
123
127
|
end
|
124
128
|
|
125
129
|
it_behaves_like "Server Response"
|
126
130
|
|
127
131
|
it "returns expected content" do
|
128
132
|
@response.body.should include(@config[:title])
|
129
|
-
@response.body.should include("
|
133
|
+
@response.body.should include("http://localhost:3000/feed.atom")
|
130
134
|
@response.body.scan(/<entry>/).count.should == 5
|
131
135
|
@response.body.scan(/<\/entry>/).count.should == 5
|
132
136
|
@response.body.should include('<feed')
|
133
137
|
@response.body.should include('</feed>')
|
134
138
|
end
|
135
139
|
|
136
|
-
it "returns
|
137
|
-
@response['Content-Type'].should == 'application/
|
140
|
+
it "returns atom content type" do
|
141
|
+
@response['Content-Type'].should == 'application/atom+xml'
|
138
142
|
end
|
139
143
|
end
|
140
144
|
|
@@ -146,7 +150,11 @@ describe "Baron" do
|
|
146
150
|
it_behaves_like "Server Response"
|
147
151
|
|
148
152
|
it "renders expected parameters" do
|
149
|
-
@response.body.should include("
|
153
|
+
@response.body.should include("http://localhost:3000/feed.atom")
|
154
|
+
end
|
155
|
+
|
156
|
+
it "returns text content type" do
|
157
|
+
@response['Content-Type'].should == 'text/plain'
|
150
158
|
end
|
151
159
|
end
|
152
160
|
|
@@ -161,6 +169,8 @@ describe "Baron" do
|
|
161
169
|
end
|
162
170
|
end
|
163
171
|
|
172
|
+
# add a method to test CSS, and a downloaded file, like a ppt
|
173
|
+
|
164
174
|
describe "Helper Functions" do
|
165
175
|
it "should return a titleized string" do
|
166
176
|
"the quick red fox".titleize.should == "The Quick Red Fox"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom">
|
3
|
+
<title><%= @config[:title] %></title>
|
4
|
+
<subtitle></subtitle>
|
5
|
+
<link href="<%= @config.get_feed_permalink %>" />
|
6
|
+
<updated><%= @articles.first[:date].iso8601 %></updated>
|
7
|
+
<id><%= @config.get_feed_permalink %></id>
|
8
|
+
|
9
|
+
<% for @article in @articles %>
|
10
|
+
<entry>
|
11
|
+
<title><%= @article.title %></title>
|
12
|
+
<link href="<%= @article.permalink %>" />
|
13
|
+
<category><%= @article.category %></category>
|
14
|
+
<author>
|
15
|
+
<name><%= @article.author %></name>
|
16
|
+
</author>
|
17
|
+
<id><%= @article.permalink %></id>
|
18
|
+
<updated></updated>
|
19
|
+
<summary><%= @article.summary %></summary>
|
20
|
+
</entry>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
</feed>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- spec/sample_data/images/robert-frost.png
|
85
85
|
- spec/sample_data/pages/about.rhtml
|
86
86
|
- spec/sample_data/pages/test.rhtml
|
87
|
+
- spec/sample_data/resources/feed.atom
|
87
88
|
- spec/sample_data/resources/redirects.txt
|
88
89
|
- spec/sample_data/resources/robots.txt
|
89
90
|
- spec/sample_data/supplemental-files/theme_config.yml
|