Sha256: be54690dba6abdc4d4c2a45e244f07df6c48852c0007a608ca55c8f89f555bf9

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

require 'rails/generators/base'

module Storytime
  module Generators
    module ViewPathTemplates
      extend ActiveSupport::Concern

      included do
        argument :scope, :required => false, :default => nil,
                         :desc => "The scope to copy views to"

        class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (application, blogs, comments, dashboard, pages, posts, sites, snippets, subscription_mailer, subscriptions)"

        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 :application
          view_directory :blogs
          view_directory :comments
          view_directory :pages
          view_directory :posts
          view_directory :sites
          view_directory :snippets
          view_directory :subscription_mailer
          view_directory :subscriptions
        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/#{scope || :storytime}"
      end
    end

    class ViewsGenerator < Rails::Generators::Base
      include ViewPathTemplates
      source_root File.expand_path("../../../../app/views/storytime/", __FILE__)

      desc "Copies Storytime views to your application."

      argument :scope, :required => false, :default => nil,
                       :desc => "The scope to copy views to"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
storytime-2.1.6 lib/generators/storytime/views_generator.rb
storytime-2.1.5 lib/generators/storytime/views_generator.rb
storytime-2.1.4 lib/generators/storytime/views_generator.rb
storytime-2.1.3 lib/generators/storytime/views_generator.rb
storytime-2.1.2 lib/generators/storytime/views_generator.rb
storytime-2.1.1 lib/generators/storytime/views_generator.rb
storytime-2.1.0 lib/generators/storytime/views_generator.rb