Class: Vivlio::Starter::CLI::DeleteCommands::ChapterDeletion

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/delete.rb

Overview

章ファイルと関連リソースの削除処理を担う

削除対象:

- contents/XX-slug.md(章 Markdown)
- images/XX-slug/(章画像ディレクトリ)
- config/catalog.yml 内の該当エントリ

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ChapterDeletion

Returns a new instance of ChapterDeletion.

Parameters:

  • options (DeleteOptions)

    削除オプション(force 判定などに使用)



194
195
196
# File 'lib/vivlio/starter/cli/delete.rb', line 194

def initialize(options)
  @options = options
end

Instance Method Details

#preview(basename) ⇒ void

This method returns an undefined value.

dry-run モード用: 削除予定を表示する(実際の削除は行わない)

Parameters:

  • basename (String)

    章ファイル名(例: “11-install.md”)



202
203
204
205
206
207
208
209
# File 'lib/vivlio/starter/cli/delete.rb', line 202

def preview(basename)
  base = basename.sub(/\.md\z/, '')
  md_file = File.join(Common::CONTENTS_DIR, basename)
  img_dir = File.join(Common::IMAGES_DIR, base)
  Common.log_always "[DRY-RUN] #{base} の削除予定:"
  Common.log_always "  - 文書:       #{md_file} #{File.exist?(md_file) ? '(exists)' : '(not found)'}"
  Common.log_always "  - 画像Dir:    #{img_dir} #{Dir.exist?(img_dir) ? '(exists)' : '(not found)'}"
end

#remove(basename) ⇒ void

This method returns an undefined value.

章ファイルと関連リソースを削除する

副作用:

- contents/XX-slug.md を削除
- images/XX-slug/ ディレクトリを削除
- config/catalog.yml から該当エントリを削除

Parameters:

  • basename (String)

    章ファイル名(例: “11-install.md”)



220
221
222
223
224
225
226
227
# File 'lib/vivlio/starter/cli/delete.rb', line 220

def remove(basename)
  delete_markdown_file(basename)
  delete_image_directory(basename)

  # catalog.yml からも削除することで build 時に含まれなくなる
  base = basename.sub(/\.md\z/, '')
  Build::CatalogUpdater.remove_chapter(base)
end