Class: Middleman::Cli::Release

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/releases/commands/release.rb

Overview

This class provides an “release” 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)


22
23
24
# File 'lib/releases/commands/release.rb', line 22

def self.source_root
  File.dirname( __FILE__ )
end

Instance Method Details

#releaseObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/releases/commands/release.rb', line 38

def release
  @tag   = tag
  @date  = options[:date] ? ::Time.zone.parse(options[:date]) : Time.zone.now

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

  releases_manager = app.extensions[:releases]

  release_dir_name       = @tag
  absolute_release_path = File.join( app.source_dir, releases_manager.options.releases_dir, release_dir_name, "index.html.markdown" )

  template releases_manager.options.new_release_template, absolute_release_path

  # Edit option process
  if options[ :edit ]
    editor = ENV.fetch('MM_EDITOR', ENV.fetch('EDITOR', nil ))

    if editor
      system( "#{ editor } #{ absolute_release_path }" )
    else
      throw "Could not find a suitable editor. Try setting the environment variable MM_EDITOR."
    end
  end
end