Sha256: 1a282a85d179a20091951213d4418c6cf3c1bfae4d03299b5172742e3777ab66

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'open-uri'
require 'rails/generators'

module GrapeSwaggerRailsThemes
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path("../../templates", __FILE__)

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

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

    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" %>', 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
    

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-swagger-rails-themes-0.1.2 lib/generators/grape_swagger_rails_themes/install_generator.rb