Class: Middleman::Presentation::Cli::ChangeSlide

Inherits:
BaseGroup
  • Object
show all
Defined in:
lib/middleman-presentation-core/cli/change_slide.rb

Overview

Create slide

Instance Method Summary collapse

Methods included from Shared

#assets_loader, #bower_path, #enable_debug_mode, included, #open_in_editor

Instance Method Details

#change_slideObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/middleman-presentation-core/cli/change_slide.rb', line 19

def change_slide
  enable_debug_mode

  fail ArgumentError, Middleman::Presentation.t('errors.too_many_arguments', count: 1) if names.count > 1 && options.key?('base_name')

  existing_slides = SlideList.new(
    Dir.glob(File.join(@environment.slides_directory, '**', '*')),
    slide_builder: ExistingSlide,
    base_path: @environment.sources_directory
  ) do |l|
    l.transform_with Transformers::FileKeeper.new
  end

  found_slides = existing_slides.select do |s|
    if names.blank?
      true
    else
      if options[:regex]
        names.any? { |n| s.base_name =~ /#{n}/ }
      else
        names.any? { |n| s.base_name == n }
      end
    end
  end

  if found_slides.blank?
    Middleman::Presentation.logger.warn Middleman::Presentation.t('errors.slide_not_found', patterns: names.to_list)
    return
  end

  move_jobs = found_slides.sort.map do |old_slide|
    new_slide_file_name = SlideName.new(
      old_slide,
      base_name: options[:base_name],
      type: options[:type]
    )

    new_slide = NewSlide.new(
      File.join(@environment.slides_directory, new_slide_file_name.to_s),
      base_path: @environment.slides_directory
    )

    OpenStruct.new(
      source: old_slide,
      destination: new_slide
    )
  end

  move_jobs.each do |j|
    if j.source == j.destination
      $stderr.puts format('%-20s %-s -> %-s', 'ignore'.colorize(color: :yellow, mode: :bold), j.source.relative_path, j.destination.relative_path)
      next
    end

    $stderr.puts format('%-20s %-s -> %-s', 'rename '.colorize(color: :green, mode: :bold), j.source.relative_path, j.destination.relative_path)
    FileUtils.mv j.source.path, j.destination.path, force: true
  end

  invoke 'middleman:presentation:cli:edit_slide', move_jobs.map(&:destination).map(&:base_name), options.extract!('editor_command') if options['edit']
end

#make_middleman_environment_availableObject



15
16
17
# File 'lib/middleman-presentation-core/cli/change_slide.rb', line 15

def make_middleman_environment_available
  @environment = MiddlemanEnvironment.new
end