Sha256: 3576ab49787534d0d82f535eee37ab7f46e86bfb2ac452e0252e6d1246b5a8c6

Contents?: true

Size: 1018 Bytes

Versions: 18

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

require 'alchemy/upgrader'

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

    no_tasks do
      def update_element_views
        puts "-- Update element views local variable to partial name"
        Dir.glob("#{elements_view_folder}/*_view.*").each do |view|
          variable_name = File.basename(view).gsub(/^_([\w-]*)\..*$/, '\1')
          gsub_file(view, /cache\(?element([,\s\w:\-,=>'"\?\/]*)\)?/, "cache(#{variable_name}\\1)")
          gsub_file(view, /render_essence_view_by_name\(?element([,\s\w:\-,=>'"\?\/]*)\)?/, "render_essence_view_by_name(#{variable_name}\\1)")
          gsub_file(view, /element_view_for\(?element([,\s\w:\-,=>'"\?\/]*)\)?/, "element_view_for(#{variable_name}\\1)")
          gsub_file(view, /element\.([\w\?]+)/, "#{variable_name}.\\1")
        end
      end
    end

    private

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
alchemy_cms-4.6.3 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.6.2 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.6.1 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.6.0 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.5.0 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.4.4 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.4.3 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.4.2 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.4.1 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.4.0 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.3.2 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.2.4 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.3.1 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.2.3 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.3.0 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.2.2 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.2.1 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb
alchemy_cms-4.2.0 lib/alchemy/upgrader/tasks/element_partial_name_variable_updater.rb