Sha256: ec4a255929611af512a83f2963c6f22f63e0c9bc55ccf09341c3a4c035f43559

Contents?: true

Size: 1.3 KB

Versions: 57

Compression:

Stored size: 1.3 KB

Contents

require 'erb'

module LicenseFinder
  class ErbReport < Report
    TEMPLATE_PATH = ROOT_PATH.join('reports', 'templates')

    def to_s(filename = TEMPLATE_PATH.join("#{template_name}.erb"))
      template = ERB.new(filename.read, nil, '-')
      template.result(binding)
    end

    private

    def unapproved_dependencies
      dependencies.reject(&:approved?)
    end

    def grouped_dependencies
      dependencies
        .group_by { |dep| license_names(dep) }
        .sort_by { |_, group| -group.size }
    end

    def link_to_license(license)
      link_to_maybe license.name, license.url
    end

    def link_to_dependency(dependency)
      link_to_maybe dependency.name, dependency.homepage
    end

    def link_to_maybe(text, link)
      if link && !link.empty?
        link_to(text, link)
      else
        text
      end
    end

    def link_to(text, link = "##{text}")
      %(<a href="#{link}">#{text}</a>)
    end

    def license_names(dependency)
      dependency.licenses.map(&:name).sort.join ', '
    end

    def license_links(dependency)
      dependency.licenses.map { |l| link_to_license(l) }.join(', ')
    end

    def version_groups(dependency)
      result = "v#{dependency.version}"
      result << " (#{dependency.groups.join(', ')})" if dependency.groups.any?
      result
    end
  end
end

Version data entries

57 entries across 57 versions & 2 rubygems

Version Path
license_finder-6.15.0 lib/license_finder/reports/erb_report.rb
gitlab-license_finder-6.14.2.1 lib/license_finder/reports/erb_report.rb
license_finder-6.14.2 lib/license_finder/reports/erb_report.rb
license_finder-6.14.1 lib/license_finder/reports/erb_report.rb
license_finder-6.13.0 lib/license_finder/reports/erb_report.rb
license_finder-6.12.2 lib/license_finder/reports/erb_report.rb
license_finder-6.12.1 lib/license_finder/reports/erb_report.rb
license_finder-6.12.0 lib/license_finder/reports/erb_report.rb
license_finder-6.11.0 lib/license_finder/reports/erb_report.rb
license_finder-6.10.1 lib/license_finder/reports/erb_report.rb
license_finder-6.10.0 lib/license_finder/reports/erb_report.rb
license_finder-6.9.0 lib/license_finder/reports/erb_report.rb
license_finder-6.8.2 lib/license_finder/reports/erb_report.rb
license_finder-6.8.1 lib/license_finder/reports/erb_report.rb
license_finder-6.8.0 lib/license_finder/reports/erb_report.rb
license_finder-6.7.0 lib/license_finder/reports/erb_report.rb
license_finder-6.6.2 lib/license_finder/reports/erb_report.rb
license_finder-6.6.1 lib/license_finder/reports/erb_report.rb
license_finder-6.6.0 lib/license_finder/reports/erb_report.rb
license_finder-6.5.0 lib/license_finder/reports/erb_report.rb