Class: CarmineContraption::Writer
- Inherits:
-
Object
- Object
- CarmineContraption::Writer
show all
- Defined in:
- lib/carmine_contraption/writer.rb
Instance Method Summary
collapse
Constructor Details
#initialize(the_index, override) ⇒ Writer
Returns a new instance of Writer.
5
6
7
8
9
10
|
# File 'lib/carmine_contraption/writer.rb', line 5
def initialize the_index, override
@index = the_index
@templater = Formatter.new(the_index.base + "templates")
@formatter = Formatter.new(the_index.base + "formats")
@override = override
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
73
74
75
76
|
# File 'lib/carmine_contraption/writer.rb', line 73
def method_missing method, *args, &block
return @index.send method, *args, &block if @index.respond_to? method
super
end
|
Instance Method Details
#write_individual_posts ⇒ Object
19
20
21
22
23
24
|
# File 'lib/carmine_contraption/writer.rb', line 19
def write_individual_posts
all_posts.each do |the_post|
path = post_path the_post
write_file path, the_post.formatted_output(@formatter) unless ( path.exist? and !@override )
end
end
|
#write_main_page ⇒ Object
26
27
28
29
30
31
|
# File 'lib/carmine_contraption/writer.rb', line 26
def write_main_page
content = ""
content << format_post_collection(all_posts[-8..-1].reverse)
content << create_archive_links
write_file destination + "recent.html", content
end
|
#write_monthly_archives ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/carmine_contraption/writer.rb', line 33
def write_monthly_archives
monthly_archives.each_key do |k|
d = build_date_from_key k
path = destination + d.year.to_s + d.month.to_s
path.mkpath
content = format_archive_for_month d, k
write_file path+"index.html", content, true
end
end
|
12
13
14
15
16
17
|
# File 'lib/carmine_contraption/writer.rb', line 12
def
puts "Updating RSS feed".blue
content = format_post_collection all_posts.reverse, :rss
feed_path = destination + "rss.xml"
write_file feed_path, content, false, :rss
end
|
#write_tag_archives ⇒ Object
43
44
45
46
47
48
|
# File 'lib/carmine_contraption/writer.rb', line 43
def write_tag_archives
path = destination + "tags"
path.mkpath
tag_archives.keys.each { |k| write_tag_archive k, path }
write_tag_feeds
end
|
#write_tag_cloud ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/carmine_contraption/writer.rb', line 60
def write_tag_cloud
path = destination + "tags" + "index.html"
content = archive_heading "TAG_CLOUD"
content += "<section class=\"tag_cloud \">\n"
max = longest_tag
tag_archives.sort_by{|k,v| k}.each do |k, v|
content << scale_tag(k, v.length, max)
end
content += "</section>\n"
write_file path, content
end
|
#write_yearly_archives ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/carmine_contraption/writer.rb', line 50
def write_yearly_archives
yearly_archives.keys.each do |k|
path = destination + k
path.mkpath
content = archive_heading "ARCHIVE FOR '<emph>#{k}</emph>'"
content << format_post_collection(yearly_archives[k])
write_file path+"index.html", content, true
end
end
|