Class: Rodauth::OAuth::Rails::Generators::ViewsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rodauth/oauth/views_generator.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#create_viewsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/rodauth/oauth/views_generator.rb', line 34

def create_views
  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|
    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