Sha256: 0f29354ca637baae361d739f8df0974f42ecdc7d7839af34fa5bd0342cd8a825

Contents?: true

Size: 787 Bytes

Versions: 16

Compression:

Stored size: 787 Bytes

Contents

module Locomotive::Wagon

  class SyncSiteCommand < PullSiteCommand

    include Locomotive::Wagon::BaseConcern

    def _sync
      attributes = current_site.attributes.slice('metafields')

      # convert to hash + download assets and use the asset local version
      decode_metafields(attributes)

      # modify the config/site.yml file accordingly
      replace_metafields_in_file(attributes['metafields'])
    end

    protected

    def replace_metafields_in_file(metafields)
      return if metafields.blank?

      content = File.read(File.join(path, 'config', 'site.yml'))

      content.gsub!(/^metafields:\n.+\n\s+.*?\n/m, { 'metafields' => metafields }.to_yaml.to_s.gsub(/\A---\n/, ''))

      File.write(File.join(path, 'config', 'site.yml'), content)
    end

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
locomotivecms_wagon-2.4.1 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.4.0 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.4.0.rc2 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.4.0.rc1 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.3.0 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.3.0.rc1 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.2.0 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.2.0.rc3 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.2.0.rc2 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.2.0.rc1 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.2.0.beta1 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.1.1 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.1.0 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.1.0.rc5 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.1.0.rc4 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb
locomotivecms_wagon-2.1.0.rc3 lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb