lib/generators/rodauth/oauth/views_generator.rb in rodauth-oauth-0.7.2 vs lib/generators/rodauth/oauth/views_generator.rb in rodauth-oauth-0.7.3

- old
+ new

@@ -1,15 +1,16 @@ # frozen_string_literal: true -require "rails/generators/base" +require "rails/generators" module Rodauth::OAuth module Rails module Generators class ViewsGenerator < ::Rails::Generators::Base source_root "#{__dir__}/templates" namespace "rodauth:oauth:views" + desc "Generate db migrations for rodauth-oauth in your application." DEFAULT = %w[authorize].freeze VIEWS = { oauth_authorize: DEFAULT, oauth_applications: %w[oauth_applications oauth_application new_oauth_application] @@ -29,19 +30,23 @@ 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) + features = options[:all] ? VIEWS.keys : (%i[oauth_authorize] + options[:features]).map(&:to_sym).uniq views = features.inject([]) do |list, feature| list |= VIEWS[feature] || [] list |= VIEWS[DEPENDENCIES[feature]] || [] end + directory = options[:directory].underscore views.each do |view| - template "app/views/rodauth/#{view}.html.erb", - "app/views/#{options[:directory].underscore}/#{view}.html.erb" + copy_file "app/views/rodauth/#{view}.html.erb", + "app/views/#{directory}/#{view}.html.erb" do |content| + content = content.gsub("rodauth/", "#{directory}/") + content + end end end end end end