Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not $project_creation
- require 'buzz/template'
- require 'buzz/html'
- require 'buzz/conf'
- require 'buzz/db'
- require 'net/ftp'
- end
- require 'date'
- class Buzz
- def self.Log(str)
- puts str
- log_str = "[" + Date.today.to_s + "] " + str
- File.open("buzz.log", "a").puts log_str
- end
- def self.create(arg, args)
- ret = 0
- if arg == "project"
- ret = self.project(args)
- elsif arg == "index"
- ret = self.index()
- elsif arg == "page"
- ret = self.page(args)
- #elsif arg == "rss"
- # ret = self.rss(ARGV)
- end
- return ret
- end
- def self.upload
- ftp == Net::FTP.new($conf['ftpsite'])
- ftp.login($conf['ftpuser'], $conf['ftppasswd'])
- ftp.chdir($conf['ftpdir'])
- files = Hash.new
- Page.find.each do |page|
- self.Log "Uploading " + page.location + " to " + $conf['ftpsite'] + page.ftplocation + "..."
- ftp.puttextfile(page.location, page.ftplocation)
- end
- ftp.close
- return 0
- end
- def self.project(arg)
- project_name = arg[0]
- Dir.mkdir(project_name)
- Dir.chdir(project_name)
- Dir.mkdir("themes")
- Dir.mkdir("static-html")
- Dir.mkdir("templates")
- buzzConf = File.open("buzz.yaml", "w")
- buzzConf.puts "conf:"
- buzzConf.puts " project_name: #{project_name}"
- buzzConf.puts " site_title: Example"
- buzzConf.puts " index_size: 10"
- buzzConf.puts " themename: default"
- buzzConf.puts " ftpsite: ftp.example.com"
- buzzConf.puts " ftpuser: Jim"
- buzzConf.puts " ftppasswd: MySuperSecretAwesomePassword"
- buzzConf.puts " ftppagedir: /The/DirectoryWhere/IWant/TheHTML/"
- buzzConf.puts " ftppostdir: /The/DirectoryWhere/IWant/TheHTML/"
- buzzConf.puts " "
- buzzConf.puts "database:"
- buzzConf.puts " adapter: mysql"
- buzzConf.puts " host: localhost"
- buzzConf.puts " username: root"
- buzzConf.puts " password: "
- buzzConf.puts " database: #{project_name}"
- buzzConf.close
- buzzLog = File.open("buzz.log", "w")
- buzzLog.close
- self.Log "Created project: " + project_name + "."
- return 0
- end
- def self.index
- files = 0
- body = Array.new
- authors = Array.new
- pages = Page.find(:all, :conditions => [ "kind = ?", "post" ])
- pages.reverse.each do |page|
- if files == $conf['index_size'].to_i
- break
- end
- files += 1
- body.concat( [
- "<h2><a href=\"#{page.ftplocation}\">#{page.title}</a></h2>\n",
- "<small><i>Created On #{page.date} by #{page.author}</i></small>",
- "<p>\n#{page.body}\n</p>\n" ] )
- authors.concat( [ "#{page.author}" ] )
- end
- theme = File.open("themes/#{$conf['themename']}/#{$conf['themename']}.html").readlines
- html = HTML.create(authors.uniq.join(" "), $conf['site_title'], body, theme)
- index = File.open("static-html/index.html", "w")
- index.puts html
- self.Log "Generated index.html"
- return 0
- end
- def self.page(arg)
- file = File.basename(arg[0], ".buzz") + ".html"
- if File.exists?("static-html/#{file}")
- print "#{file} already exists. Would you like to overwrite it? [y/N] "
- ans = STDIN.gets
- ans.strip!
- if ans == "y" or ans == "Y"
- File.delete("static-html/#{file}")
- page = Page.find(:first, :conditions => [ "location = ?", "static-html/#{file}"] )
- page.destroy
- else
- return 1
- end
- end
- theme = File.open("themes/#{$conf['themename']}/#{$conf['themename']}.html").readlines
- template = Template.new(arg[0])
- template.parse
- html = HTML.create(template.author, template.title, template.body, theme)
- static_local = "static-html/"+ file
- f = File.open(static_local, "w")
- f.puts html
- f.close
- ftpL = ''
- if template.kind == "page"
- ftpL = "#{$ftppagedir}/#{file}"
- elsif template.kind == "post"
- ftpL = "#{$ftppostdir}/#{file}"
- end
- Page.create( :title => template.title, :date => Date.today.to_s, :author => template.author, :body => template.body, :location => static_local, :ftplocation => ftpL, :kind => template.kind)
- self.Log "Generated " + static_local + " from " + arg[0] + "."
- self.Log "Written by " + template.author + "."
- return 0
- end
- end
Add Comment
Please, Sign In to add comment