class Middleman::Cli::Entry

This class provides an “entry” command for the middleman CLI.

@usage bundle exec middleman entry –help @usage bundle exec middleman entry @usage bundle exec middleman entry -d yesterday

Public Class Methods

source_root() click to toggle source

Template files are relative to this file @return [String]

# File lib/middleman-journal/commands/entry.rb, line 23
def self.source_root
  File.dirname(__FILE__)
end

Public Instance Methods

entry() click to toggle source
# File lib/middleman-journal/commands/entry.rb, line 31
def entry
  @date = options[:date] ? Chronic.parse(options[:date]) : Date.today
  @title = @date.strftime('%F')
  @slug = @date.strftime('%F')

  template template_path, destination_path
end

Private Instance Methods

destination_path() click to toggle source
# File lib/middleman-journal/commands/entry.rb, line 45
def destination_path
  app = ::Middleman::Application.new do
    config[:mode]              = :config
    config[:disable_sitemap]   = true
    config[:watcher_disable]   = true
    config[:exit_before_ready] = true
  end

  path = File.join(app.source_dir, 'journal', "#{@title}.html.markdown")

  if File.exist?(path)
    throw "An entry for #{@title} already exists: #{path}"
  end

  path
end
template_path() click to toggle source
# File lib/middleman-journal/commands/entry.rb, line 41
def template_path
  File.expand_path('entry.tt', File.dirname(__FILE__))
end