defmodule Mix.Tasks.Dragon.New do @moduledoc false @shortdoc "Create a new Dragon Project" use Mix.Task import Mix.Generator @impl true def run([target]), do: new(target) def run(_), do: IO.puts("Syntax: mix new {target}") ############################################################################## def new(target) do p = fn x -> Path.join(target, x) end create_file(p.("_dragon.yml"), dragon_config_template([])) create_file(p.("_data/site.yml"), data_site_template([])) create_file(p.("_lib/layout/default.html"), layout_default_template([])) create_file(p.("_lib/head.html"), lib_head_template([])) create_file(p.("_lib/footer.html"), lib_footer_template([])) create_file(p.("_lib/navbar.html"), lib_navbar_template([])) create_file(p.("_news/2023-04-04-File-name-here.md"), news_template([])) create_file(p.("index.html"), index_template([])) create_file(p.("assets/js/index.js"), index_js_template([])) create_file(p.("assets/img/favicon.svg"), icon_template([])) create_file(p.("assets/css/main.scss"), main_scss_template([])) create_file(p.("assets/css/plain.css"), plain_css_template([])) create_file(p.("assets/css/_included.scss"), included_scss_template([])) end ################################################################################ embed_template(:plain_css, """ body { font-weight: bold; } """) embed_template(:main_scss, """ @import "included"; """) embed_template(:included_scss, """ body { font-weight: italic; } """) embed_template(:icon, """ """) embed_template(:index_js, """ """) embed_template(:data_site, """ # There are no Dragon assumptions in this file. All content is up to # the site implementation. url: "https://example.com" name: "A site wide name" """) embed_template(:lib_head, """ --- dragon-1.0 --- eex <%%= @site.name %> "> "> "> """) embed_template(:lib_footer, """ --- dragon-1.0 --- eex
""") embed_template(:lib_navbar, """ <%%# Files without dragon template headermatter may also be used %> <%%# This is a comment; put navbar things here %> """) embed_template(:news, """ --- dragon-1.0 title: Optional Collection --- eex A news post """) embed_template(:index, """ --- dragon-1.0 @spec: layout: default.html title: A site! --- eex Contents of the index! """) embed_template(:layout_default, """ --- dragon-1.0 @spec: args: - content --- eex <%%= include "lib/head.html" %> <%%= include "lib/navbar.html" %> <%%= @page.content %>
<%%= include "lib/footer.html" %> """) embed_template(:dragon_config, """ version: 1.0 ## a list of data sources. Currently supported are type: file and collection data: - type: collection path: _news # The "into" keyword inserts the data into the context using this keyword. # if it is unspecified, the contents are inserted at the root of the context. into: news - type: file path: _data # where are layout files located? layouts: _lib/layout # where does the "built" version of the site go? staging: _build """) end