Class: Middleman::Cli::Contentful

Inherits:
Thor
  • 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.

Constant Summary collapse

MIDDLEMAN_LOCAL_DATA_FOLDER =

Path where Middleman expects the local data to be stored

'data'

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)


35
36
37
# File 'lib/contentful_middleman/commands/contentful.rb', line 35

def self.exit_on_failure?
  true
end

.source_rootObject



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

def self.source_root
  ENV['MM_ROOT']
end

Instance Method Details

#contentfulObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/contentful_middleman/commands/contentful.rb', line 39

def contentful
  if shared_instance.respond_to? :contentful_instances
    ContentfulMiddleman::VersionHash.source_root    = self.class.source_root
    ContentfulMiddleman::LocalData::Store.base_path = MIDDLEMAN_LOCAL_DATA_FOLDER
    ContentfulMiddleman::LocalData::File.thor       = self

    hash_local_data_changed = contentful_instances.reduce(false) do |changes, instance|
      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]
    shared_instance.logger.info 'Contentful Import: Done!'
  else
    raise Thor::Error.new "You need to activate the contentful extension in config.rb before you can import data from Contentful"
  end
end