georgi-shinmun 0.3.9 → 0.3.10

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.
@@ -14,7 +14,7 @@
14
14
  <% if @post.category %>
15
15
  Posted in category <%= link_to @post.category, "/categories/#{urlify @post.category}" %> by <%= @blog.author %>.
16
16
  <% end %>
17
- Tagged with <%= @post.tag_list.map {|tag| link_to tag, "/tags/#{urlify tag}" }.join(', ') %>.
17
+ Tagged with <%= @post.tag_list.map {|tag| link_to tag, "/tags/#{tag}" }.join(', ') %>.
18
18
  </div>
19
19
 
20
20
  <h6>Similar Posts</h6>
data/lib/shinmun/blog.rb CHANGED
@@ -6,9 +6,9 @@ module Shinmun
6
6
 
7
7
  include Helpers
8
8
 
9
- attr_reader :aggregations, :categories, :comments, :repo
9
+ attr_reader :aggregations, :categories, :comments, :repo, :store
10
10
 
11
- %w[ assets comments config posts pages ].each do |name|
11
+ %w[ assets comments config posts pages templates ].each do |name|
12
12
  define_method(name) { store.root.tree(name) }
13
13
  end
14
14
 
@@ -22,6 +22,14 @@ module Shinmun
22
22
 
23
23
  @aggregations = {}
24
24
 
25
+ if ENV['RACK_ENV'] == 'production'
26
+ @store = GitStore.new(path)
27
+ else
28
+ @store = GitStore::FileStore.new(path)
29
+ end
30
+
31
+ @store.load
32
+
25
33
  @repo = Grit::Repo.new(path) if defined?(Grit)
26
34
 
27
35
  Thread.start do
@@ -41,6 +49,19 @@ module Shinmun
41
49
  `git commit -m 'init'`
42
50
  end
43
51
 
52
+ def load_template(file)
53
+ templates[file] or raise "template #{file} not found"
54
+ end
55
+
56
+ def render(name, vars = {})
57
+ super(name, vars.merge(:blog => self))
58
+ end
59
+
60
+ def call(env)
61
+ store.refresh!
62
+ super
63
+ end
64
+
44
65
  def load_aggregations
45
66
  config['aggregations.yml'].to_a.each do |c|
46
67
  aggregations[c['name']] = Object.const_get(c['class']).new(c['url'])
@@ -144,15 +165,6 @@ module Shinmun
144
165
  io << render(template, vars)
145
166
  end
146
167
  end
147
-
148
- def render(name, vars = {})
149
- super(name, vars.merge(:blog => self))
150
- end
151
-
152
- def call(env)
153
- templates['helpers.rb']
154
- super
155
- end
156
168
 
157
169
  end
158
170
 
@@ -10,7 +10,7 @@ class BlueCloth
10
10
  # Generate the codeblock
11
11
  if codeblock =~ /^(?:[ ]{4}|\t)@@(.*?)\n\n(.*)\n\n/m
12
12
  "\n\n<pre class='highlight'>%s</pre>\n\n%s" %
13
- [CodeRay.scan(outdent($2), $1).html(:css => :class, :line_numbers => :list).delete("\n"), remainder]
13
+ [CodeRay.scan(outdent($2), $1).html(:css => :style, :line_numbers => :list).delete("\n"), remainder]
14
14
  else
15
15
  "\n\n<pre><code>%s\n</code></pre>\n\n%s" %
16
16
  [encode_code(outdent(codeblock), rs).rstrip, remainder]
@@ -60,6 +60,16 @@ module Shinmun
60
60
  def rfc822(time)
61
61
  time.strftime("%a, %d %b %Y %H:%M:%S %z")
62
62
  end
63
+
64
+ # Render a link for the navigation bar. If the text of the link
65
+ # matches the @header variable, the css class will be set to acitve.
66
+ def navi_link(text, path)
67
+ link_to text, path, :class => (request.path_info == path) ? 'active' : nil
68
+ end
69
+
70
+ def html_escape(s)
71
+ s.to_s.gsub(/>/, '&gt;').gsub(/</n, '&lt;')
72
+ end
63
73
 
64
74
  def diff_line_class(line)
65
75
  case line[0, 1]
data/lib/shinmun/post.rb CHANGED
@@ -84,11 +84,11 @@ module Shinmun
84
84
  # Split up the source into header and body. Load the header as
85
85
  # yaml document if present.
86
86
  def parse(src)
87
- if src =~ /\A(---.*?)---(.*)/m
87
+ if src =~ /\A---(.*?)---(.*)/m
88
88
  @head = YAML.load($1)
89
89
  @body = $2
90
90
  else
91
- @body = src
91
+ raise ArgumentError, "yaml header not found in src"
92
92
  end
93
93
 
94
94
  @body_html = transform(@body)
@@ -101,7 +101,7 @@ module Shinmun
101
101
 
102
102
  # Convert to string representation
103
103
  def dump
104
- (head.empty? ? '' : head.to_yaml + "---") + body
104
+ head.to_yaml + "---" + body
105
105
  end
106
106
 
107
107
  # Transform the body of this post. Defaults to Markdown.
@@ -1,7 +1,7 @@
1
1
  Shinmun::Blog.map do
2
2
 
3
3
  get '/categories/(.*)\.rss' do |category|
4
- render 'category.rxml', find_category(category)
4
+ render 'category.rxml', find_category(category).merge(:layout => false)
5
5
  end
6
6
 
7
7
  get '/categories/(.*)' do |category|
@@ -22,7 +22,7 @@ Shinmun::Blog.map do
22
22
  end
23
23
 
24
24
  get '/index\.rss' do
25
- render 'index.rxml'
25
+ render 'index.rxml', :layout => false
26
26
  end
27
27
 
28
28
  post '/comments' do
data/test/blog_spec.rb CHANGED
@@ -156,7 +156,7 @@ describe Shinmun::Blog do
156
156
  @blog.posts_for_month(2008, 10).should_not be_empty
157
157
  @blog.posts_for_month(2008, 11).should_not be_empty
158
158
 
159
- assert_listing(get('/2008/10').body, [['New post', 'Body1'], ['And this', 'Body2']])
159
+ assert_listing(get('/2008/10').body, [['And this', 'Body2'], ['New post', 'Body1']])
160
160
  assert_listing(get('/').body, [['Again', 'Body3'], ['And this', 'Body2'], ['New post', 'Body1']])
161
161
  end
162
162
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: georgi-shinmun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Georgi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-17 00:00:00 -08:00
12
+ date: 2008-04-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency