rog 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/lib/rog/blog.rb +111 -127
  3. data/lib/rog/post.rb +1 -14
  4. metadata +2 -2
data/Rakefile CHANGED
@@ -87,7 +87,7 @@ spec = Gem::Specification.new do |s|
87
87
  s.platform = Gem::Platform::RUBY
88
88
  s.summary = "Static Ruby Blog Engine."
89
89
  s.name = 'rog'
90
- s.version = '0.1.3'
90
+ s.version = '0.1.4'
91
91
 
92
92
  s.add_dependency('rote', '>= 0.3.2.2')
93
93
  s.add_dependency('rake')
data/lib/rog/blog.rb CHANGED
@@ -17,32 +17,38 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
  =begin
20
- La classe Blog ha il compito di raccogliere tutte quelle informazioni globali da cui generare
21
- la pagina di index e gli archivi mensili e annuali.
22
-
23
- Esempio:
24
- * raccolta tags
25
- * collegamento tag -> pagine
26
- * raccolta date dei post
27
- * collegamento date dei post -> pagine
28
-
29
- == Raccolta Tags ==
30
-
31
- Allo scopo di raccogliere i tag si potrebbe caricare tutti i file .rb dei post
32
- e riempire un'hash tag->pagine.
33
-
34
- == Date ==
35
-
36
- La data di un post potrebbere essere contenuta nel nome stesso del file.
37
- Questa scelta implementativa permetterebbe di:
38
- * differenziare immediatamente post del blog dalle pagine statiche
39
- * ordinare i post sulla base del nome
20
+ The Blog class has the task of gathering all required global
21
+ informations nedeed to generate the index page and the yearly and
22
+ monthly archives.
23
+
24
+ Examples:
25
+ * tags gathering
26
+ * linking between tags and pages
27
+ * posts' date gathering
28
+ * linking between posts' date and pages
29
+
30
+ == Tags Gathering ==
31
+
32
+ In order to gather all tags we could proceed loading all .rb file of
33
+ the post, so we can obtain an hash tag->pages.
34
+
35
+ == Dates ==
36
+
37
+ We can choose to put the post's date in the same filename, by this way
38
+ we are able to easily:
39
+
40
+ * discriminate between blog's posts and static pages;
41
+ * order posts by name.
40
42
  =end
41
43
 
44
+ require 'yaml'
45
+ require 'erb'
46
+
42
47
  module Rog
43
48
 
44
49
  class Blog
45
- attr_reader :blog_title, :blog_subtitle
50
+ attr_reader :blog_title, :blog_subtitle, :links, :pages, :buttons,
51
+ :projects, :url, :publish_url
46
52
 
47
53
  def initialize(blog_path='blog', pages_path="#{blog_path}/pages",
48
54
  archives_path = "#{pages_path}/archives",
@@ -66,30 +72,6 @@ module Rog
66
72
  @blog_posts
67
73
  end
68
74
 
69
- def links
70
- @links
71
- end
72
-
73
- def buttons
74
- @buttons
75
- end
76
-
77
- def pages
78
- @pages
79
- end
80
-
81
- def projects
82
- @projects
83
- end
84
-
85
- def url
86
- @url
87
- end
88
-
89
- def publish_url
90
- @publish_url
91
- end
92
-
93
75
  def posts?
94
76
  @blog_posts.length >= 1
95
77
  end
@@ -148,13 +130,13 @@ module Rog
148
130
  # ex. 20060607-prova123.thtml
149
131
 
150
132
  if filename =~ /(\d\d\d\d)(\d\d)(\d\d)[-].*\.thtml$/ then
151
- curr_blog = Post.new(filename, @blog_path, @pages_path, @posts_path)
133
+ curr_post = Post.new(filename, @blog_path, @pages_path, @posts_path)
152
134
 
153
- @blog_posts.push curr_blog
135
+ @blog_posts.push curr_post
154
136
 
155
- curr_blog.tags.each do |tag|
137
+ curr_post.tags.each do |tag|
156
138
  @tags_hash[tag] = Array.new if @tags_hash[tag].nil?
157
- @tags_hash[tag].push curr_blog
139
+ @tags_hash[tag].push curr_post
158
140
  end
159
141
  end
160
142
  end
@@ -163,50 +145,47 @@ module Rog
163
145
  end
164
146
 
165
147
  def load_config
166
- require 'yaml'
167
-
168
- begin
169
- @config = YAML::load( File.open("#{@blog_path}/blog.yaml") )
148
+ @config = YAML::load( File.open("#{@blog_path}/blog.yaml") )
170
149
 
171
- @links = Hash.new
172
- @pages = Hash.new
173
- @buttons = Hash.new
174
- @projects = Hash.new
150
+ @links = Hash.new
151
+ @pages = Hash.new
152
+ @buttons = Hash.new
153
+ @projects = Hash.new
175
154
 
176
- @config["links"].each do |link|
177
- link.each do |key,value|
178
- @links[key] = value
179
- end
155
+ @config["links"].each do |link|
156
+ link.each do |key,value|
157
+ @links[key] = value
180
158
  end
159
+ end
181
160
 
182
- @config["pages"].each do |link|
183
- link.each do |key,value|
184
- @pages[key] = value
185
- end
161
+ @config["pages"].each do |link|
162
+ link.each do |key,value|
163
+ @pages[key] = value
186
164
  end
165
+ end
187
166
 
188
- @config["buttons"].each do |button|
189
- button.each do |key,value|
190
- @buttons[key] = value
191
- end
167
+ @config["buttons"].each do |button|
168
+ button.each do |key,value|
169
+ @buttons[key] = value
192
170
  end
171
+ end
193
172
 
194
- @config["projects"].each do |project|
195
- project.each do |key,value|
196
- @projects[key] = value
197
- end
173
+ @config["projects"].each do |project|
174
+ project.each do |key,value|
175
+ @projects[key] = value
198
176
  end
177
+ end
199
178
 
200
- @url = @config["blogurl"]
201
- @publish_url = @config["publish_url"]
202
- @blog_title = @config["blog_title"]
203
- @blog_subtitle = @config["blog_subtitle"]
179
+ @url = @config["blogurl"]
180
+ @publish_url = @config["publish_url"]
181
+ @blog_title = @config["blog_title"]
182
+ @blog_subtitle = @config["blog_subtitle"]
204
183
 
205
- rescue Errno::ENOENT
206
- STDERR.puts "Unable to open blog.yaml"
207
- exit 1
208
- end
184
+ rescue Errno::ENOENT
185
+ STDERR.puts "Unable to open blog.yaml"
186
+ exit 1
209
187
  end
188
+
210
189
  end
211
190
 
212
191
  class BlogUtils
@@ -219,74 +198,79 @@ module Rog
219
198
  end
220
199
 
221
200
  def self.generate_post(postname,tags)
222
- require 'eruby'
201
+ @postname = postname
202
+ @tags = tags.split
223
203
 
224
- ark_rb = open("blog/templates/post.rb.tpl")
225
- ark_thtml = open("blog/templates/post.thtml.tpl")
226
-
227
- compiler = ERuby::Compiler.new
228
-
229
- data_rb = compiler.compile_file(ark_rb)
230
- data_thtml = compiler.compile_file(ark_thtml)
204
+ open("blog/templates/post.rb.tpl") do |f|
205
+ ark_rb = f.gets
206
+ end
207
+
208
+ open("blog/templates/post.thtml.tpl") do |f|
209
+ ark_thtml = f.gets
210
+ end
231
211
 
232
212
  date = `date +%Y%m%d`.chomp
233
213
 
234
- out_rb = File.open("blog/pages/posts/#{date}-#{postname}.rb", 'w')
235
- out_thtml = File.open("blog/pages/posts/#{date}-#{postname}.thtml", 'w')
236
-
237
- @postname = postname
238
- @tags = tags.split
214
+ data_rb = ERB.new(ark_rb).result(binding)
215
+ data_thtml = ERB.new(ark_thtml).result(binding)
239
216
 
240
- stdout_redirect_to(out_rb) { eval data_rb }
241
- stdout_redirect_to(out_thtml) { eval data_thtml }
217
+ open("blog/pages/posts/#{date}-#{postname}.rb", 'w') do |f|
218
+ f.puts data_rb
219
+ end
242
220
 
243
- ark_rb.close; ark_thtml.close; out_rb.close; out_thtml.close
221
+ open("blog/pages/posts/#{date}-#{postname}.thtml", 'w') do |f|
222
+ f.puts data_thtml
223
+ end
244
224
  end
245
225
 
246
226
  def self.generate_tag_archive(tag)
247
- require 'eruby'
248
-
249
- ark_rb = open("blog/templates/archive-tag.rb.tpl")
250
- ark_thtml = open("blog/templates/archive-tag.thtml.tpl")
251
-
252
- compiler = ERuby::Compiler.new
227
+ @tag = tag
253
228
 
254
- data_rb = compiler.compile_file(ark_rb)
255
- data_thtml = compiler.compile_file(ark_thtml)
229
+ open("blog/templates/archive-tag.rb.tpl") do |f|
230
+ ark_rb = f.gets
231
+ end
256
232
 
257
- out_rb = File.open("blog/pages/archives/archive-"+tag+".rb", 'w')
258
- out_thtml = File.open("blog/pages/archives/archive-"+tag+".thtml", 'w')
259
-
260
- @tag = tag
233
+ open("blog/templates/archive-tag.thtml.tpl") do |f|
234
+ ark_thtml = f.gets
235
+ end
236
+
237
+ data_rb = ERB.new(ark_rb).result(binding)
238
+ data_thtml = ERB.new(ark_thtml).result(binding)
261
239
 
262
- stdout_redirect_to(out_rb) { eval data_rb }
263
- stdout_redirect_to(out_thtml) { eval data_thtml }
240
+ open("blog/pages/archives/archive-"+tag+".rb", 'w') do |f|
241
+ f.puts data_rb
242
+ end
264
243
 
265
- ark_rb.close; ark_thtml.close; out_rb.close; out_thtml.close
244
+ open("blog/pages/archives/archive-"+tag+".thtml", 'w') do |f|
245
+ f.puts data_thtml
246
+ end
266
247
  end
267
248
 
268
249
  def self.generate_month_archive(year,month)
269
- require 'eruby'
250
+ @year = year
251
+ @month = month
270
252
 
271
- ark_rb = open("blog/templates/archive-month.rb.tpl")
272
- ark_thtml = open("blog/templates/archive-month.thtml.tpl")
273
-
274
- compiler = ERuby::Compiler.new
275
253
 
276
- data_rb = compiler.compile_file(ark_rb)
277
- data_thtml = compiler.compile_file(ark_thtml)
254
+ open("blog/templates/archive-month.rb.tpl") do |f|
255
+ ark_rb = f.gets
256
+ end
278
257
 
279
- out_rb = File.open("blog/pages/archives/archive-"+year+month+".rb", 'w')
280
- out_thtml = File.open("blog/pages/archives/archive-"+year+month+".thtml", 'w')
281
-
282
- @year = year
283
- @month = month
258
+ open("blog/templates/archive-month.thtml.tpl") do |f|
259
+ ark_thtml = f.gets
260
+ end
261
+
262
+ data_rb = ERB.new(ark_rb).result(binding)
263
+ data_thtml = ERB.new(ark_thtml).result(binding)
284
264
 
285
- stdout_redirect_to(out_rb) { eval data_rb }
286
- stdout_redirect_to(out_thtml) { eval data_thtml }
265
+ open("blog/pages/archives/archive-"+year+month+".rb", 'w') do |f|
266
+ f.puts data_rb
267
+ end
287
268
 
288
- ark_rb.close; ark_thtml.close; out_rb.close; out_thtml.close
269
+ open("blog/pages/archives/archive-"+year+month+".thtml", 'w') do |f|
270
+ f.puts data_thtml
271
+ end
289
272
  end
273
+
290
274
  end
291
275
 
292
276
  end
data/lib/rog/post.rb CHANGED
@@ -59,20 +59,7 @@ module Rog
59
59
  end
60
60
 
61
61
  def <=>(other)
62
- if (year_compare = @year <=> other.year) != 0 then
63
- year_compare
64
- end
65
-
66
-
67
- if (month_compare = @month <=> other.month) != 0 then
68
- month_compare
69
- end
70
-
71
- if (day_compare = @day <=> other.day) != 0 then
72
- day_compare
73
- end
74
-
75
- return 0
62
+ [@year, @month, @day] <=> [other.year, other.month, other.day]
76
63
  end
77
64
 
78
65
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rog
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2006-05-17 00:00:00 +02:00
6
+ version: 0.1.4
7
+ date: 2006-05-22 00:00:00 +02:00
8
8
  summary: Static Ruby Blog Engine.
9
9
  require_paths:
10
10
  - lib