module AutoPilot::TemplateHelper

Public Instance Methods

file_name(post_title) click to toggle source
# File lib/auto_pilot/template_helper.rb, line 3
def file_name(post_title)
  prefix = Time.now.to_s.split(' ').first # TODO: simplify
  suffix = post_title.gsub(' ', '-').downcase.strip
  "#{prefix}-#{suffix}"
end
make_folder_if_doesnt_exist() click to toggle source
# File lib/auto_pilot/template_helper.rb, line 24
def make_folder_if_doesnt_exist
  system 'mkdir', '-p', AutoPilot.configuration.folder
end
parameterize(string, sep = '-') click to toggle source
# File lib/auto_pilot/template_helper.rb, line 9
def parameterize(string, sep = '-')
  # replace accented chars with their ascii equivalents
  # parameterized_string = transliterate(string)
  # Turn unwanted chars into the separator
  string.gsub!(/[^a-z0-9\-_]+/i, sep)
  unless sep.nil? || sep.empty?
    re_sep = Regexp.escape(sep)
    # No more than one of the separator in a row.
    string.gsub!(/#{re_sep}{2,}/, sep)
    # Remove leading/trailing separator.
    string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
  end
  string.downcase
end
write_file_to_disk(folder = AutoPilot.configuration.folder, type) click to toggle source
# File lib/auto_pilot/template_helper.rb, line 28
def write_file_to_disk(folder = AutoPilot.configuration.folder, type)
  new_file =  file_name(h1_tag)
  sanitized_file_name = parameterize(new_file)
  File.open("#{folder}/#{sanitized_file_name}.#{type}", 'w') do |file|
    method = "#{type}_template"
    file.write(send(method))
    Log.green "- added file ./#{folder}/#{sanitized_file_name}.#{type}"
  end
end