Sha256: 56db61a7ad262fa0585ddbe9c7f1c2724ac9cf8e12fd0527c8cd67ae296c663f

Contents?: true

Size: 1.6 KB

Versions: 14

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "rails/generators/base"

module Rodauth::OAuth
  module Rails
    module Generators
      class ViewsGenerator < ::Rails::Generators::Base
        source_root "#{__dir__}/templates"
        namespace "rodauth:oauth:views"

        DEFAULT = %w[oauth_authorize].freeze
        VIEWS = {
          oauth_authorize: DEFAULT,
          oauth_applications: %w[oauth_applications oauth_application new_oauth_application]
        }.freeze

        DEPENDENCIES = {
        }.freeze

        class_option :features, type: :array,
                                desc: "Roda OAuth features to generate views for (oauth_applications etc.)",
                                default: DEFAULT

        class_option :all, aliases: "-a", type: :boolean,
                           desc: "Generates views for all Roda OAuth features",
                           default: false

        class_option :directory, aliases: "-d", type: :string,
                                 desc: "The directory under app/views/* into which to create views",
                                 default: "rodauth"

        def create_views
          features = options[:all] ? VIEWS.keys : (DEFAULT + options[:features]).map(&:to_sym)

          views = features.inject([]) do |list, feature|
            list |= VIEWS[feature] || []
            list |= VIEWS[DEPENDENCIES[feature]] || []
          end

          views.each do |view|
            template "app/views/rodauth/#{view}.html.erb",
                     "app/views/#{options[:directory].underscore}/#{view}.html.erb"
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rodauth-oauth-0.6.0 lib/generators/rodauth/oauth/views_generator.rb
rodauth-oauth-0.5.1 lib/generators/rodauth/oauth/views_generator.rb
rodauth-oauth-0.5.0 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.4.3 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.4.2 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.4.1 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.4.0 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.3.0 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.2.0 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.1.0 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.0.6 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.0.5 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.0.4 lib/generators/roda/oauth/views_generator.rb
rodauth-oauth-0.0.3 lib/generators/roda/oauth/views_generator.rb