module Simb
Constants
- ROOTDIR
- VERSION
Public Class Methods
add_file(file, blog)
click to toggle source
# File lib/simb.rb, line 112 def self.add_file(file, blog) FileUtils.copy(file, "#{ROOTDIR}/#{blog}/_posts/#{post_filename file.gsub(/\..*/, '')}") end
add_header(file, post_name)
click to toggle source
# File lib/simb.rb, line 12 def self.add_header file, post_name File.open(file, 'a') do |f| f.puts "---" f.puts "layout: post" f.puts "title: #{post_name}" f.puts "date: #{Time.now}" f.puts "categories:" f.puts "---" end end
blog_initted?(blog)
click to toggle source
# File lib/simb.rb, line 74 def self.blog_initted?(blog) # is that even a word? pffffttt... Dir.exists?("#{ROOTDIR}#{blog}/.git/") end
commit(blog)
click to toggle source
# File lib/simb.rb, line 78 def self.commit(blog) Dir.chdir("#{ROOTDIR}#{blog}") do `git pull origin gh-pages` # do any merges `git add --all && git commit -m "new posts (#{Time.now})"` `git push --force origin gh-pages` end end
config_remote(blog, user)
click to toggle source
# File lib/simb.rb, line 102 def self.config_remote(blog, user) Dir.chdir("#{ROOTDIR}#{blog}") do `git init .` `git remote add origin git@github.com:#{user}/#{blog}.git` `git checkout -b gh-pages` `git pull` # get code if repo already exists commit(blog) # go back and publish now end end
create_repo(blog, user, pass)
click to toggle source
# File lib/simb.rb, line 86 def self.create_repo(blog, user, pass) github = Github.new basic_auth: "#{user}:#{pass}" if repo_exists? user, blog if (ask "A repo named '#{blog}' already exists! Commit? (y/n)") !~ /^[yY].*/ abort "Aborting!" end else github.repos.create name: "#{blog}", description: "Blog for #{blog}", private: false, has_issues: false, has_wiki: false, has_downloads: false end end
edit_config(blog)
click to toggle source
# File lib/simb.rb, line 68 def self.edit_config(blog) Dir.chdir("#{ROOTDIR}#{blog}") do editor "_config.yml" end end
editor(file)
click to toggle source
# File lib/simb.rb, line 8 def self.editor file system("#{ENV['EDITOR']} #{file}") end
init_blog(name)
click to toggle source
# File lib/simb.rb, line 32 def self.init_blog(name) `jekyll new #{ROOTDIR}#{name}` end
list_blogs()
click to toggle source
# File lib/simb.rb, line 61 def self.list_blogs Dir.chdir("#{ROOTDIR}") do Dir.glob("*/").map{|a|a[0..-2]}.join("\n") end end
list_posts(blog)
click to toggle source
# File lib/simb.rb, line 47 def self.list_posts(blog) Dir.chdir("#{ROOTDIR}#{blog}/_posts") do Dir.glob("*").map do |a| if a.split('-').size < 4 [a.gsub('.markdown', ''), a] else f = "[#{a.split('-')[0..2].join('-')}]" f += " #{a.split('-')[3..-1].join(' ').gsub('.markdown', '')}" [f, a] end end end end
new_post(post_name, blog)
click to toggle source
# File lib/simb.rb, line 36 def self.new_post(post_name, blog) file = "#{ROOTDIR}#{blog}/_posts/#{post_filename post_name}" if File.exists? file editor file return end `touch #{file}` add_header file, post_name editor file end
post_filename(post_name)
click to toggle source
# File lib/simb.rb, line 28 def self.post_filename(post_name) return "#{Time.now.strftime("%F")}-#{post_name.gsub(" ", "-")}.markdown" end
repo_exists?(user, repo)
click to toggle source
# File lib/simb.rb, line 23 def self.repo_exists? (user, repo) repos = Github::Client::Repos.new not repos.list(user: user).select{|e| e.name == repo}.first.nil? end