rtlog 0.1.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.
- data/ChangeLog +4 -0
- data/README.mdown +72 -0
- data/Rakefile +127 -0
- data/bin/rtlog-create +116 -0
- data/lib/rtlog/archives.rb +387 -0
- data/lib/rtlog/example/config/config.yml +22 -0
- data/lib/rtlog/example/config/day.html.erb +21 -0
- data/lib/rtlog/example/config/index.html.erb +19 -0
- data/lib/rtlog/example/config/layout.html.erb +229 -0
- data/lib/rtlog/example/config/month.html.erb +70 -0
- data/lib/rtlog/example/config/rss.xml.erb +50 -0
- data/lib/rtlog/example/public/styles/site.css +82 -0
- data/lib/rtlog/pages.rb +276 -0
- data/lib/rtlog.rb +15 -0
- metadata +109 -0
data/lib/rtlog/pages.rb
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
require 'rtlog'
|
2
|
+
require 'erb'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Rtlog
|
6
|
+
|
7
|
+
class Page
|
8
|
+
include ERB::Util
|
9
|
+
|
10
|
+
attr_reader :config
|
11
|
+
attr_reader :log
|
12
|
+
attr_writer :logger
|
13
|
+
|
14
|
+
def initialize config, log
|
15
|
+
@config = config
|
16
|
+
@log = log
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
defined?(@logger) ? @logger : Rtlog.logger
|
21
|
+
end
|
22
|
+
|
23
|
+
def config_dir
|
24
|
+
File.expand_path( config['config_dir'] )
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse file_name
|
28
|
+
# logger.debug("Template parsing: #{file_name}")
|
29
|
+
open(file_name) { |io| ERB.new( io.read ) }.result(binding)
|
30
|
+
rescue => ex
|
31
|
+
"<p>#{h(ex.to_s)}</p><pre class='error'>#{ex.backtrace.map{|m| h(m) }.join('<br />')}</pre>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate options={}
|
35
|
+
options = { :layout => 'layout.html.erb' }.merge(options)
|
36
|
+
|
37
|
+
template = nil
|
38
|
+
if options[:layout]
|
39
|
+
template = File.join( config_dir, options[:layout] )
|
40
|
+
template = File.join( Rtlog.root, 'lib', 'rtlog', 'example', 'config', 'layout.html.erb' ) unless File.exist?(template)
|
41
|
+
end
|
42
|
+
template = template_path unless template
|
43
|
+
FileUtils.mkdir_p( File.dirname(file_path) ) unless File.exist?( File.dirname(file_path) )
|
44
|
+
open(file_path, "w") do |io|
|
45
|
+
io.write(parse(template))
|
46
|
+
end
|
47
|
+
logger.debug("#{self.class} is generated: #{file_path}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def size
|
51
|
+
config['pages'][page_name]['size'] || 7
|
52
|
+
rescue
|
53
|
+
7
|
54
|
+
end
|
55
|
+
|
56
|
+
def template_path
|
57
|
+
unless defined?(@template_path)
|
58
|
+
@template_path = nil
|
59
|
+
if config['pages'] && config['pages'][page_name] && config['pages'][page_name]['template']
|
60
|
+
@template_path = ::File.join(config_dir, config['pages'][page_name]['template'])
|
61
|
+
end
|
62
|
+
unless @template_path && File.exist?(@template_path)
|
63
|
+
@template_path = File.join( Rtlog.root, 'lib', 'rtlog', 'example', 'config', template_file_name )
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@template_path
|
67
|
+
end
|
68
|
+
|
69
|
+
def template_file_name
|
70
|
+
class_name = self.class.name.split('::').last.gsub('Page', '').downcase
|
71
|
+
"#{class_name}.html.erb"
|
72
|
+
end
|
73
|
+
|
74
|
+
def month_pages
|
75
|
+
@month_pages = []
|
76
|
+
log.year_entries.each do |y|
|
77
|
+
y.month_entries.each do |m|
|
78
|
+
@month_pages << MonthPage.new(config, log, m)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@month_pages
|
82
|
+
end
|
83
|
+
|
84
|
+
def index_url
|
85
|
+
config['url_prefix']
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class IndexPage < Page
|
90
|
+
|
91
|
+
def title
|
92
|
+
'Index'
|
93
|
+
end
|
94
|
+
|
95
|
+
def file_path
|
96
|
+
File.expand_path( File.join(config['target_dir'], 'index.html') )
|
97
|
+
end
|
98
|
+
|
99
|
+
def url
|
100
|
+
config['url_prefix']
|
101
|
+
end
|
102
|
+
|
103
|
+
def page_name
|
104
|
+
'index'
|
105
|
+
end
|
106
|
+
|
107
|
+
def recent_day_pages size
|
108
|
+
recent_day_pages = []
|
109
|
+
log.recent_day_entries(size).each do |d|
|
110
|
+
recent_day_pages << DayPage.new( config, log, d )
|
111
|
+
end
|
112
|
+
recent_day_pages
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class RssPage < IndexPage
|
117
|
+
def url
|
118
|
+
config['url_prefix'] + '/feed/rss'
|
119
|
+
end
|
120
|
+
|
121
|
+
def file_path
|
122
|
+
File.expand_path( File.join(config['target_dir'], 'feed', 'rss.xml') )
|
123
|
+
end
|
124
|
+
|
125
|
+
def page_name
|
126
|
+
'rss'
|
127
|
+
end
|
128
|
+
|
129
|
+
def generate
|
130
|
+
super(:layout => nil)
|
131
|
+
end
|
132
|
+
|
133
|
+
def template_file_name
|
134
|
+
'rss.xml.erb'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class MonthPage < Page
|
139
|
+
attr_reader :month_entry
|
140
|
+
attr_accessor :current_page
|
141
|
+
|
142
|
+
def initialize config, log, month_entry
|
143
|
+
@config = config
|
144
|
+
@log = log
|
145
|
+
@month_entry = month_entry
|
146
|
+
@current_page = 1
|
147
|
+
end
|
148
|
+
|
149
|
+
def title
|
150
|
+
date.strftime('%Y-%m')
|
151
|
+
end
|
152
|
+
|
153
|
+
def date
|
154
|
+
@month_entry.date
|
155
|
+
end
|
156
|
+
|
157
|
+
def current_day_pages
|
158
|
+
current_day_pages = []
|
159
|
+
month_entry.day_entries[(current_page - 1) * per_page, per_page].each do |d|
|
160
|
+
current_day_pages << DayPage.new( config, log, d )
|
161
|
+
end
|
162
|
+
current_day_pages
|
163
|
+
end
|
164
|
+
|
165
|
+
def per_page
|
166
|
+
size
|
167
|
+
end
|
168
|
+
|
169
|
+
def total_entries
|
170
|
+
@total_entries ||= month_entry.day_entries.size
|
171
|
+
@total_entries
|
172
|
+
end
|
173
|
+
|
174
|
+
def total_tweets
|
175
|
+
month_entry.size
|
176
|
+
end
|
177
|
+
|
178
|
+
def total_pages
|
179
|
+
(Float.induced_from(total_entries)/Float.induced_from(per_page)).ceil
|
180
|
+
end
|
181
|
+
|
182
|
+
def previous
|
183
|
+
return false if current_page == 1
|
184
|
+
previous_page = self.clone
|
185
|
+
previous_page.current_page -= 1
|
186
|
+
previous_page
|
187
|
+
end
|
188
|
+
|
189
|
+
def next
|
190
|
+
return false if current_page == total_pages
|
191
|
+
next_page = self.clone
|
192
|
+
next_page.current_page += 1
|
193
|
+
next_page
|
194
|
+
end
|
195
|
+
|
196
|
+
def next_month_page
|
197
|
+
unless defined?(@next_month_page)
|
198
|
+
month = log.next_month_entry(self.month_entry)
|
199
|
+
return nil unless month
|
200
|
+
@next_month_page = MonthPage.new(config, log, month)
|
201
|
+
end
|
202
|
+
@next_month_page
|
203
|
+
end
|
204
|
+
|
205
|
+
def previous_month_page
|
206
|
+
unless defined?(@previous_month_page)
|
207
|
+
month = log.previous_month_entry(self.month_entry)
|
208
|
+
return nil unless month
|
209
|
+
@previous_month_page = MonthPage.new(config, log, month)
|
210
|
+
end
|
211
|
+
@previous_month_page
|
212
|
+
end
|
213
|
+
|
214
|
+
def file_path
|
215
|
+
page = current_page == 1 ? '' : "_#{current_page}"
|
216
|
+
File.expand_path( File.join(config['target_dir'], path, "index#{page}.html") )
|
217
|
+
end
|
218
|
+
|
219
|
+
def url(page=current_page)
|
220
|
+
page = page == 1 ? '' : "index_#{page}"
|
221
|
+
config['url_prefix'] + '/' + path + '/' + page
|
222
|
+
end
|
223
|
+
|
224
|
+
protected
|
225
|
+
def page_name
|
226
|
+
'month'
|
227
|
+
end
|
228
|
+
|
229
|
+
def path
|
230
|
+
month_entry.date.strftime('%Y/%m')
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
class DayPage < Page
|
235
|
+
attr_reader :day_entry
|
236
|
+
|
237
|
+
def initialize config, log, day_entry
|
238
|
+
@config = config
|
239
|
+
@log = log
|
240
|
+
@day_entry = day_entry
|
241
|
+
end
|
242
|
+
|
243
|
+
def title
|
244
|
+
date.strftime('%Y-%m-%d')
|
245
|
+
end
|
246
|
+
|
247
|
+
def date
|
248
|
+
@day_entry.date
|
249
|
+
end
|
250
|
+
|
251
|
+
def tweets
|
252
|
+
@day_entry.tweets do |tw|
|
253
|
+
yield tw
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def file_path
|
258
|
+
File.expand_path( File.join(config['target_dir'], path, 'index.html') )
|
259
|
+
end
|
260
|
+
|
261
|
+
def url
|
262
|
+
config['url_prefix'] + '/' + path
|
263
|
+
end
|
264
|
+
|
265
|
+
protected
|
266
|
+
def page_name
|
267
|
+
'day'
|
268
|
+
end
|
269
|
+
|
270
|
+
def path
|
271
|
+
day_entry.date.strftime('%Y/%m/%d')
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
data/lib/rtlog.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yuanying
|
8
|
+
autorequire: ""
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-08-30 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.4
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json_pure
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.9
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rubytter
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.8.0
|
44
|
+
version:
|
45
|
+
description: ""
|
46
|
+
email: yuanying at fraction dot jp
|
47
|
+
executables:
|
48
|
+
- rtlog-create
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.mdown
|
53
|
+
- ChangeLog
|
54
|
+
files:
|
55
|
+
- README.mdown
|
56
|
+
- ChangeLog
|
57
|
+
- Rakefile
|
58
|
+
- bin/rtlog-create
|
59
|
+
- lib/rtlog/archives.rb
|
60
|
+
- lib/rtlog/example/config/config.yml
|
61
|
+
- lib/rtlog/example/config/day.html.erb
|
62
|
+
- lib/rtlog/example/config/index.html.erb
|
63
|
+
- lib/rtlog/example/config/layout.html.erb
|
64
|
+
- lib/rtlog/example/config/month.html.erb
|
65
|
+
- lib/rtlog/example/config/rss.xml.erb
|
66
|
+
- lib/rtlog/example/public/styles/site.css
|
67
|
+
- lib/rtlog/pages.rb
|
68
|
+
- lib/rtlog.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://rtlog.rubyforge.org
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --title
|
76
|
+
- rtlog documentation
|
77
|
+
- --charset
|
78
|
+
- utf-8
|
79
|
+
- --opname
|
80
|
+
- index.html
|
81
|
+
- --line-numbers
|
82
|
+
- --main
|
83
|
+
- README.mdown
|
84
|
+
- --inline-source
|
85
|
+
- --exclude
|
86
|
+
- ^(examples|extras)/
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: rtlog
|
104
|
+
rubygems_version: 1.3.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: ""
|
108
|
+
test_files: []
|
109
|
+
|