Class: GrapeSwaggerRailsThemes::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/grape_swagger_rails_themes/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_grape_swagger_rails_templatesObject



16
17
18
19
20
21
22
# File 'lib/generators/grape_swagger_rails_themes/install_generator.rb', line 16

def copy_grape_swagger_rails_templates
  download = open('https://raw.githubusercontent.com/ruby-grape/grape-swagger-rails/master/app/views/grape_swagger_rails/application/index.html.erb')
  create_file "app/views/grape_swagger_rails/application/index.html.erb", download.read
  insert_into_file "app/views/grape_swagger_rails/application/index.html.erb", '<%= stylesheet_link_tag "swagger-ui-themes/themes/#{GrapeSwaggerRails.options.theme_version}/theme-#{::GrapeSwaggerRails.options.theme}.css" unless ::GrapeSwaggerRails.options.theme == "default"  %>', after: "<%= stylesheet_link_tag 'grape_swagger_rails/application.css' %>"

  insert_into_file "config/initializers/assets.rb", "\nRails.application.config.assets.precompile += %w( swagger-ui-themes/themes/2.x/*.css swagger-ui-themes/themes/3.x/*.css )", after: "Rails.application.config.assets.paths << Rails.root.join('node_modules')"
end

#copy_initializerObject



8
9
10
# File 'lib/generators/grape_swagger_rails_themes/install_generator.rb', line 8

def copy_initializer
  template "grape_swagger_rails_themes.rb", "config/initializers/grape_swagger_rails_themes.rb"
end

#install_dependenciesObject



12
13
14
# File 'lib/generators/grape_swagger_rails_themes/install_generator.rb', line 12

def install_dependencies
  run 'yarn add swagger-ui-themes'
end