Sha256: 51e36435884020858c509b35d3c9d24f0217e1a2f4f50a09414b95ed85f370dc

Contents?: true

Size: 862 Bytes

Versions: 15

Compression:

Stored size: 862 Bytes

Contents

# frozen_string_literal: true

require 'alchemy/upgrader'

module Alchemy::Upgrader::Tasks
  class ElementViewsUpdater < Thor
    include Thor::Actions

    no_tasks do
      def rename_element_views
        puts "-- Removing '_view' suffix from element views"

        Dir.glob("#{elements_view_folder}/*_view.*").each do |file|
          FileUtils.mv(file, file.to_s.sub(/_view/, ''))
        end
      end

      def update_local_variable
        puts "-- Updating element views local variable to element name"

        Alchemy::Element.definitions.map { |e| e['name'] }.each do |name|
          view = Dir.glob("#{elements_view_folder}/_#{name}.*").last
          gsub_file(view, /\b#{name}_view\b/, name)
        end
      end
    end

    private

    def elements_view_folder
      Rails.root.join('app', 'views', 'alchemy', 'elements')
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.6 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.5 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.5.1 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.4.5 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.4 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.3 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.2 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.1 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.6.0 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.5.0 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.4.4 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.4.3 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.4.2 lib/alchemy/upgrader/tasks/element_views_updater.rb
alchemy_cms-4.4.1 lib/alchemy/upgrader/tasks/element_views_updater.rb