PkgTemplates.jl/src/plugins
2019-12-17 07:35:16 +07:00
..
ci.jl Fix broken GH Actions badge (#121) 2019-12-17 07:35:16 +07:00
citation.jl Remove interactive stuff (for now) 2019-10-06 14:43:17 +07:00
coverage.jl Reduce line length of docstrings 2019-10-06 16:55:32 +07:00
develop.jl Reduce line length of docstrings 2019-10-06 16:55:32 +07:00
documenter.jl Add GitHubActions plugin for CI and docs 2019-11-10 11:15:55 +07:00
git.jl Fix a gitignore bug 2019-11-10 11:15:56 +07:00
license.jl Reduce line length of docstrings 2019-10-06 16:55:32 +07:00
project_file.jl Add version option to ProjectFile plugin to set initial version 2019-11-04 15:58:32 +07:00
readme.jl Add GitHubActions plugin for CI and docs 2019-11-10 11:15:55 +07:00
src_dir.jl Remove interactive stuff (for now) 2019-10-06 14:43:17 +07:00
tests.jl Add a test for the test/Project.toml warning 2019-10-06 16:55:54 +07:00

"""
    Readme(;
        file="$(contractuser(default_file("README.md")))",
        destination="README.md",
        inline_badges=false,
    )

Creates a `README` file that contains badges for other included plugins.

## Keyword Arguments
- `file::AbstractString`: Template file for the `README`.
- `destination::AbstractString`: File destination, relative to the repository root.
  For example, values of `"README"` or `"README.rst"` might be desired.
- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name.
"""
@with_kw_noshow struct Readme <: BasicPlugin
    file::String = default_file("README.md")
    destination::String = "README.md"
    inline_badges::Bool = false
end

source(p::Readme) = p.file
destination(p::Readme) = p.destination

function view(p::Readme, t::Template, pkg::AbstractString)
    # Explicitly ordered badges go first.
    strings = String[]
    done = DataType[]
    foreach(badge_order()) do T
        if hasplugin(t, T)
            append!(strings, badges(getplugin(t, T), t, pkg))
            push!(done, T)
        end
    end
    # And the rest go after, in no particular order.
    foreach(setdiff(map(typeof, t.plugins), done)) do T
        append!(strings, badges(getplugin(t, T), t, pkg))
    end

    return Dict(
        "BADGES" => strings,
        "HAS_CITATION" => hasplugin(t, Citation) && getplugin(t, Citation).readme,
        "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges,
        "PKG" => pkg,
    )
end

badge_order() = [
    Documenter{GitLabCI},
    Documenter{TravisCI},
    GitHubActions,
    GitLabCI,
    TravisCI,
    AppVeyor,
    DroneCI,
    CirrusCI,
    Codecov,
    Coveralls,
]