Class: Middleman::Cli::Contentful

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

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Tell Thor to exit with a nonzero exit code on failure

Returns:

  • (Boolean)


29
30
31
# File 'lib/contentful_middleman/commands/contentful.rb', line 29

def self.exit_on_failure?
  true
end

.source_rootObject



24
25
26
# File 'lib/contentful_middleman/commands/contentful.rb', line 24

def self.source_root
  ENV['MM_ROOT']
end

Instance Method Details

#contentfulObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/contentful_middleman/commands/contentful.rb', line 33

def contentful
  raise Thor::Error.new "You need to activate the contentful extension in config.rb before you can import data from Contentful" if contentful_instances.empty?

  ContentfulMiddleman::VersionHash.source_root    = self.class.source_root
  ContentfulMiddleman::LocalData::File.thor       = self

  hash_local_data_changed = contentful_instances.reduce(false) do |changes, instance|
    ContentfulMiddleman::LocalData::Store.base_path = File.join(
      instance.options.base_path,
      instance.options.destination
    )
    import_task = create_import_task(instance)
    import_task.run

    changes || import_task.changed_local_data?
  end

  Middleman::Cli::Build.new.build if hash_local_data_changed && options[:rebuild]
  logger.info 'Contentful Import: Done!'
end