class WikiTipsPost::WikiPostHelper

Public Class Methods

new(title: title, tips: tips, tags: tags) click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 8
def initialize(title: title, tips: tips, tags: tags)
  @title = title
  @tips = tips
  @tags = tags
  @tmp_dir = Dir.mktmpdir("wiki")
  @kernel = KernelWrapper.new
end

Public Instance Methods

add_new_page() click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 21
def add_new_page
  File.write(tip_path, @tips)
end
create_post() click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 53
def create_post
  add_new_page
  @tags.each do |tg|
    if link_to_tag(tg)
      link_to_index(tg)
    end
  end
end
delete_local_repo_clone() click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 67
def delete_local_repo_clone
  delete_dir="sudo rm -r #{@tmp_dir}"
  @kernel.system(delete_dir)
end
prepare_repo() click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 16
def prepare_repo
  git_clone="git clone #{WIKI_REPO} #{@tmp_dir}"
  @kernel.system(git_clone)
end
push_to_repo() click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 62
def push_to_repo
  git_push="pushd #{@tmp_dir} && git add . && git commit -m'Added a tip' && git push origin head && popd"
  @kernel.system(git_push)
end

Private Instance Methods

sanitize_wiki_page_title(title) click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 78
def sanitize_wiki_page_title(title)
  title.strip.gsub(/\W+/, '-')
end
tip_path() click to toggle source
# File lib/wiki_tips_post/wiki_post_helper.rb, line 74
def tip_path
  File.join(@tmp_dir, sanitize_wiki_page_title(@title) + '.md')
end