Class: Middleman::Cli::Entry

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/middleman-journal/commands/entry.rb

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootString

Template files are relative to this file

Returns:

  • (String)


23
24
25
# File 'lib/middleman-journal/commands/entry.rb', line 23

def self.source_root
  File.dirname( __FILE__ )
end

Instance Method Details

#entryObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/middleman-journal/commands/entry.rb', line 27

def entry

  @date    = Time.now
				@title   = @date.strftime('%F')
  @slug    = @date.strftime('%F')

  app = ::Middleman::Application.new do
    config[ :mode ]              = :config
    config[ :disable_sitemap ]   = true
    config[ :watcher_disable ]   = true
    config[ :exit_before_ready ] = true
  end

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

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

				entry_template = File.expand_path('entry.tt', File.dirname(__FILE__))

  template entry_template, absolute_entry_path

end