Module: AutoPilot::TemplateHelper
- Included in:
- HtmlConverter, MarkdownConverter
- Defined in:
- lib/auto_pilot/template_helper.rb
Instance Method Summary collapse
- #file_name(post_title) ⇒ Object
- #make_folder_if_doesnt_exist ⇒ Object
- #parameterize(string, sep = '-') ⇒ Object
- #write_file_to_disk(folder = AutoPilot.configuration.folder, type) ⇒ Object
Instance Method Details
#file_name(post_title) ⇒ Object
3 4 5 6 7 |
# 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 ⇒ Object
24 25 26 |
# 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 = '-') ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# 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 |