Sha256: 0367fbd6360bf7b0bc54877f3e8ee928a35bfe9eaa88f413afecc9428222bdb4

Contents?: true

Size: 1.24 KB

Versions: 20

Compression:

Stored size: 1.24 KB

Contents

require 'rails/generators/base'

module Phcscriptcdn

	module Generators

		module ViewPathTemplates
			extend ActiveSupport::Concern

			included do
				class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (layouts, phcscriptcdn)"

				public_task :copy_views
			end

			# module ClassMethods
			#   def hide!
			#     Rails::Generators.hide_namespace self.namespace
			#   end
			# end

			def copy_views
				if options[:views]
					options[:views].each do |directory|
						view_directory directory.to_sym
					end
				else
					view_directory :layouts
					view_directory :phcscriptcdn
				end
			end

			protected

			def view_directory(name, _target_path = nil)
				directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
					content
				end
			end

			def target_path
				@target_path ||= "app/views"
			end
		end

		class SharedViewsGenerator < Rails::Generators::Base
			include ViewPathTemplates
			source_root File.expand_path("../../../../app/views", __FILE__)
			desc "Copies phcscriptcdn views to your application."
			hide!
		end

		class ViewsGenerator < Rails::Generators::Base
			desc "Copies phcscriptcdn views to your application."
			invoke SharedViewsGenerator
		end
	end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
phcscriptcdn-1.2.0 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-1.1.0 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-1.0.3 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-1.0.2 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-1.0.1 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-1.0.0 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.10 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.9 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.8 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.7 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.6 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.5 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.3 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.2 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.9.1 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.7.0 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.6.0 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.5.7 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.5.6 lib/generators/phcscriptcdn/views_generator.rb
phcscriptcdn-0.5.5 lib/generators/phcscriptcdn/views_generator.rb