class Middleman::Cli::Contentful
This class provides an “contentful” command for the middleman CLI.
Public Class Methods
exit_on_failure?()
click to toggle source
Tell Thor to exit with a nonzero exit code on failure
# File lib/contentful_middleman/commands/contentful.rb, line 29 def self.exit_on_failure? true end
source_root()
click to toggle source
# File lib/contentful_middleman/commands/contentful.rb, line 24 def self.source_root ENV['MM_ROOT'] end
Public Instance Methods
contentful()
click to toggle source
# 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
Private Instance Methods
app()
click to toggle source
# File lib/contentful_middleman/commands/contentful.rb, line 63 def app @app ||= ::Middleman::Application.new do config[:mode] = :contentful end end
contentful_instances()
click to toggle source
# File lib/contentful_middleman/commands/contentful.rb, line 59 def contentful_instances app.contentful_instances end
create_import_task(instance)
click to toggle source
# File lib/contentful_middleman/commands/contentful.rb, line 69 def create_import_task(instance) space_name = instance.space_name.to_s content_type_names = instance.content_types_ids_to_names content_type_mappers = instance.content_types_ids_to_mappers ContentfulMiddleman::ImportTask.new(space_name, content_type_names, content_type_mappers, instance) end
logger()
click to toggle source
# File lib/contentful_middleman/commands/contentful.rb, line 55 def logger ::Middleman::Logger.singleton end