Class: Plugins::InitPlugin

Inherits:
Plugin
  • Object
show all
Defined in:
lib/bujo/plugins/init_plugin.rb

Instance Attribute Summary

Attributes inherited from Plugin

#name, #options

Instance Method Summary collapse

Methods inherited from Plugin

#==, #directory, #shortcuts

Constructor Details

#initialize(dependencies = []) ⇒ InitPlugin

Returns a new instance of InitPlugin.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bujo/plugins/init_plugin.rb', line 14

def initialize(dependencies = [])
  super("init", [
      Options::Option.builder
          .with_name("i", "init")
          .with_description("Init the structure of the journal")
          .with_action(-> { init_journal })
          .build
  ])

  @template_renderer = dependencies[:template_renderer]
end

Instance Method Details

#init_journalObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bujo/plugins/init_plugin.rb', line 26

def init_journal
  puts "Initializing a new BuJo..."
  FileUtils.copy(Configuration::Structure.global_asset_path("bujo/bujo.yaml"), Configuration::Structure.local_path("bujo.yaml"))
  Dir.mkdir(Configuration::Structure.sources_path)

  rendered_template = @template_renderer.render("init/template.adoc", {})
  index_source_path = Configuration::Structure.source_path("index.adoc")
  Utils::Files.write(index_source_path, rendered_template)

  configuration = Configuration::Configuration.load
  plugin_repository = PluginRepository.new(configuration, @template_renderer)
  plugin_repository.find_all
      .map { |plugin| plugin.directory }
      .select { |directory| not directory.nil? }
      .uniq
      .each { |directory| Configuration::Structure.create_source_directory(directory)}
end