Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Jagua
- class Engine
- def initialize(res_path)
- $RES_PATH = res_path
- require 'rubygems'; require 'activerecord'; require 'erb'
- ActiveRecord::Base.establish_connection(YAML.load_file('db/conf.yml'))
- Dir['db/models/*'].each do |model|; require model; end
- end
- def republish_blog(blog)
- # copiar todo excepto los templates
- system("cp #{File.join(blog.theme.path, '*.css')} #{blog.local_path} -Rf")
- # paginas individuales
- blog.posts.each do |post|
- open(post.local_path, 'w') do |f|
- f.print publish_post(post, :complete)
- end
- end
- # archivos mensuales
- # portada + feed rss
- s = ""
- latest_posts = blog.posts.find( :all, :order => 'created_at DESC', :limit => 20 )
- latest_posts.each do |post|
- s += publish_post(post, :partial)
- end
- open(File.join(blog.local_path, 'index.html'), 'w') do |f|
- f.print(blog.theme.render_with(s, blog))
- end
- # RSS...
- open(File.join(blog.local_path, 'feed.xml'), 'w') do |f|
- f.print generate_rss_feed(latest_posts)
- end
- end
- def publish_post(post, action)
- @post = post.render_attributes
- rendered_post = ERB.new(File.read(File.join(post.blog.theme.path, 'post.html'))).result(binding)
- if action == :complete
- # layout + post
- return post.blog.theme.render_with(rendered_post, post.blog)
- else
- # post (partial)
- return rendered_post
- end
- end
- def generate_rss_feed(posts)
- require 'rss/maker'
- content = RSS::Maker.make('2.0') do |s|
- s.channel.title = posts[0].blog.title
- s.channel.link = posts[0].blog.public_path
- s.channel.description = posts[0].blog.description
- s.items.do_sort = true
- posts.each do |post|
- p = s.items.new_item
- p.title = post.title
- p.description = post.content[0,250]
- p.link = post.public_path
- p.date = post.created_at
- end
- end
- return content.to_s
- end
- end
- end
Add Comment
Please, Sign In to add comment