Class: Pipin::Builder
- Inherits:
-
Object
- Object
- Pipin::Builder
- Defined in:
- lib/pipin.rb,
lib/pipin/templates/plugins/genarate_rss.rb
Instance Method Summary collapse
- #create_dist_file(filename, text) ⇒ Object
- #generate_rss(entries, options = {}) ⇒ Object
-
#initialize(dist_dir) ⇒ Builder
constructor
A new instance of Builder.
- #render(template, b = binding) ⇒ Object
- #render_archives ⇒ Object
- #render_index ⇒ Object
- #render_list(name, pattern, options = {}) ⇒ Object
- #render_month(year, month) ⇒ Object
- #render_post(label) ⇒ Object
- #render_rss(options = {}) ⇒ Object
- #render_sitemap ⇒ Object
- #render_with_layout(template, b = binding) ⇒ Object
- #write_html(label, html) ⇒ Object
Constructor Details
#initialize(dist_dir) ⇒ Builder
Returns a new instance of Builder.
34 35 36 |
# File 'lib/pipin.rb', line 34 def initialize(dist_dir) @dist_dir = dist_dir end |
Instance Method Details
#create_dist_file(filename, text) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/pipin.rb', line 72 def create_dist_file(filename, text) Dir.mkdir @dist_dir unless File.exist?(@dist_dir) filename = File.join(@dist_dir, filename) File.open(filename, 'w') {|f| f.write text } puts ' create ' + filename end |
#generate_rss(entries, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pipin/templates/plugins/genarate_rss.rb', line 13 def generate_rss(entries, = {}) top = config[:base_url].sub(/\/\z/, '') RSS::Maker.make("1.0") do |maker| entries.each do |entry| item = maker.items.new_item item.link = "#{top}/permalink/#{entry.label + html_extname}" item.description = entry.rss_description item.title = entry.rss_tile item.content_encoded = entry.rss_body item.date = entry.time end maker.channel.link = top maker.channel.about = [:about] || "abaout" maker.channel.title = [:title] || config[:title] maker.channel.description = [:description] || config[:description] || 'Please set config[:description] in pipinrc' end.to_s end |
#render(template, b = binding) ⇒ Object
83 84 85 86 |
# File 'lib/pipin.rb', line 83 def render(template, b = binding) haml = File.read(File.join(rootdir, "views/#{template}.haml")) Haml::Engine.new(haml).render(b) end |
#render_archives ⇒ Object
43 44 45 46 |
# File 'lib/pipin.rb', line 43 def render_archives years = Post.year_months write_html 'archives', render_with_layout(:archives, binding) end |
#render_index ⇒ Object
58 59 60 |
# File 'lib/pipin.rb', line 58 def render_index render_list('index', Diary_pattern, :limit => 3) end |
#render_list(name, pattern, options = {}) ⇒ Object
62 63 64 65 |
# File 'lib/pipin.rb', line 62 def render_list(name, pattern, = {}) posts = Post.find(pattern, ) write_html name, render_with_layout(:list, binding) end |
#render_month(year, month) ⇒ Object
48 49 50 51 |
# File 'lib/pipin.rb', line 48 def render_month(year, month) name = year + month render_list(name, name + '*') end |
#render_post(label) ⇒ Object
53 54 55 56 |
# File 'lib/pipin.rb', line 53 def render_post(label) post = Post.find(label).first write_html label, render_with_layout(:post, binding) end |
#render_rss(options = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/pipin/templates/plugins/genarate_rss.rb', line 6 def render_rss( = {}) [:limit] ||= 20 posts = Post.find(Diary_pattern, :limit => [:limit]) rss = generate_rss(posts, ) create_dist_file('rss', rss) end |
#render_sitemap ⇒ Object
38 39 40 41 |
# File 'lib/pipin.rb', line 38 def render_sitemap posts = Post.find(Sitemap_pattern) write_html 'sitemap', render_with_layout(:sitemap, binding) end |
#render_with_layout(template, b = binding) ⇒ Object
79 80 81 |
# File 'lib/pipin.rb', line 79 def render_with_layout(template, b = binding) render(:layout) { render(template, b) } end |
#write_html(label, html) ⇒ Object
67 68 69 70 |
# File 'lib/pipin.rb', line 67 def write_html(label, html) filename = label + '.html' create_dist_file(filename, html) end |