Current section

Files

Jump to
still lib still compiler template_helpers link_to_css.ex
Raw

lib/still/compiler/template_helpers/link_to_css.ex

defmodule Still.Compiler.TemplateHelpers.LinkToCSS do
@moduledoc """
Generates a `link` HTML tag to the target CSS file.
This file must exist and to ensure that, it **will be compiled** outside
`Still.Compiler.CompilationStage`.
"""
alias Still.Compiler.TemplateHelpers.UrlFor
alias Still.SourceFile
import Still.Utils
require Logger
@doc """
Generates a `link` HTML tag to the target CSS file.
All options are converted to the `attr=value` format.
"""
@spec render(map(), String.t(), list(any())) :: String.t()
def render(env, input_file, opts) do
link_opts =
opts
|> Enum.map(fn {k, v} ->
"#{k}=#{v}"
end)
|> Enum.join(" ")
%{output_file: output_file} =
input_file
|> compile_file(use_cache: true)
|> SourceFile.for_extension(env.extension)
"""
<link rel="stylesheet" #{link_opts} href=\"#{UrlFor.render(output_file)}\" />
"""
end
end