Class: Jekylljournal::Journalhandler
- Inherits:
-
Object
- Object
- Jekylljournal::Journalhandler
- Defined in:
- lib/jekylljournal/journalhandler.rb
Overview
This class is used to handle Jekyll Journals. It is generally called from the command line wrapper.
Instance Method Summary collapse
-
#initialize ⇒ Journalhandler
constructor
Loads the config dotfile from the default directory and sets the application options.
-
#open ⇒ Object
Opens today’s post if it exists, otherwise it creates a new post, populates it with the default yaml frontmatter, then opens this newly created file.
-
#preview ⇒ Object
Runs a preview jekyll server locally.
-
#save ⇒ Object
Adds and commits all new posts and assets to git, then pushes to the default repositories.
Constructor Details
#initialize ⇒ Journalhandler
Loads the config dotfile from the default directory and sets the application options
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jekylljournal/journalhandler.rb', line 7 def initialize @options = { } config_file = File.join(ENV['HOME'],'.jekylljournal.yaml') if File.exists? config_file = YAML.load_file(config_file) if ! puts 'Config file empty, please see the readme.' else @options.merge!() end else puts 'Config file not found, please create one.' end end |
Instance Method Details
#open ⇒ Object
Opens today’s post if it exists, otherwise it creates a new post, populates it with the default yaml frontmatter, then opens this newly created file.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jekylljournal/journalhandler.rb', line 27 def open today = Date.today.strftime '%Y-%m-%d' file_name = "#{@options[:blog_location]}/_posts/#{today}-#{today}.md" # create the file if it doesn't exist frontmatter = <<eol --- layout: post title: #{today} tags: [] --- eol File.write file_name, frontmatter unless File.file? file_name puts "Opening #{file_name}" system 'vim', file_name end |
#preview ⇒ Object
Runs a preview jekyll server locally
62 63 64 65 |
# File 'lib/jekylljournal/journalhandler.rb', line 62 def preview puts 'Starting preview server at localhost:4000' `cd #{@options[:blog_location]};jekyll serve;` end |
#save ⇒ Object
Adds and commits all new posts and assets to git, then pushes to the default repositories. TODO
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jekylljournal/journalhandler.rb', line 49 def save puts 'Saving...' run_git_cmd 'add _posts/*' run_git_cmd 'add assets/*' # TODO: this should use more flexible values. # Date format should be a dotfile option # Message format should be a dotfile option run_git_cmd "commit -m \"Save: #{Date.today.strftime '%Y-%m-%d'}\"" run_git_cmd 'push' puts 'done.' end |