Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
feat: initial commit
  • Loading branch information
mhanberg committed Feb 21, 2024
0 parents commit 124cfdb
Show file tree
Hide file tree
Showing 31 changed files with 705 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
56 changes: 56 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release:
name: release
runs-on: ubuntu-latest
strategy:
matrix:
otp: [26.2.2]
elixir: [1.15.7]
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: elixir
package-name: tableau_new
bump-minor-pre-major: true

- uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}

- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
if: ${{ steps.release.outputs.release_created }}

- uses: actions/cache@v3
id: cache
if: ${{ steps.release.outputs.release_created }}
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ matrix.otp }}-${{ matrix.elixir }}-
- name: Install Dependencies
if: steps.release.outputs.release_created && steps.cache.outputs.cache-hit != 'true'
run: mix deps.get

- name: publish to hex
if: ${{ steps.release.outputs.release_created }}
env:
HEX_API_KEY: ${{secrets.HEX_API_KEY}}
run: |
mix hex.publish package --yes
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
tableau_new-*.tar

# Temporary files, for example, from tests.
/tmp/
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2024 Mitchell Hanberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# mix tableau.new

Mix task to generate a new [Tableau](https://github.com/elixir-tools/tableau) website.

## Installation

```elixir
mix archive.install hex tableau_new
```

## --help

```
mix tableau.new <app_name> [<opts>]
Flags
--template Template syntax to use. Options are heex, temple, eex. (required)
--assets Asset framework to use. Options are vanilla, tailwind. (optional, defaults to vanilla)
--help Shows this help text.
Example
mix tableau.new my_awesome_site
mix tableau.new my_awesome_site --template temple
mix tableau.new my_awesome_site --template eex --assets tailwind
```
158 changes: 158 additions & 0 deletions lib/mix/tasks/tableau.new.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
defmodule Mix.Tasks.Tableau.New do
@help """
mix tableau.new <app_name> [<flags>]
Flags
--template Template syntax to use. Options are heex, temple, eex. (required)
--assets Asset framework to use. Options are vanilla, tailwind. (optional, defaults to vanilla)
--help Shows this help text.
Example
mix tableau.new my_awesome_site
mix tableau.new my_awesome_site --template temple
mix tableau.new my_awesome_site --template eex --assets tailwind
"""
@moduledoc @help
@shortdoc "Generate a new Tableau website"

use Mix.Task

def run(argv) do
{opts, argv} =
OptionParser.parse!(argv,
strict: [
assets: :string,
template: :string,
help: :boolean
]
)

opts =
case Keyword.validate(opts, [:assets, :template, help: false]) do
{:ok, opts} ->
opts

{:error, unknown} ->
Mix.shell().error("Unknown options: #{Enum.map_join(unknown, &"--#{&1}")}")
raise "Unknown options passed to `mix tableau.new`"
end

if opts[:help] do
Mix.shell().info(@help)

System.halt(0)
end

[app | _] = argv
templates = Path.join(:code.priv_dir(:tableau_new), "templates")

for source <- Path.wildcard(Path.join(templates, "primary/**/*.{ex,exs}")) do
target =
Path.relative_to(source, Path.join(templates, "primary"))
|> String.replace("app_name", app)

assigns = [
app: app,
app_module: Macro.camelize(app),
template: opts[:template],
assets: opts[:assets]
]

Mix.Generator.copy_template(source, target, assigns)
end

cond do
opts[:template] == "temple" ->
for source <- Path.wildcard(Path.join(templates, "temple/**/*.{ex,exs}")) do
target =
Path.relative_to(source, Path.join(templates, "temple"))
|> String.replace("app_name", app)

assigns = [
app: app,
app_module: Macro.camelize(app),
template: opts[:template],
assets: opts[:assets]
]

Mix.Generator.copy_template(source, target, assigns)
end

opts[:template] == "heex" ->
for source <- Path.wildcard(Path.join(templates, "heex/**/*.{ex,exs}")) do
target =
Path.relative_to(source, Path.join(templates, "heex"))
|> String.replace("app_name", app)

assigns = [
app: app,
app_module: Macro.camelize(app),
template: opts[:template],
assets: opts[:assets]
]

Mix.Generator.copy_template(source, target, assigns)
end

opts[:template] == "eex" ->
for source <- Path.wildcard(Path.join(templates, "eex/**/*.{ex,exs}")) do
target =
Path.relative_to(source, Path.join(templates, "eex"))
|> String.replace("app_name", app)

assigns = [
app: app,
app_module: Macro.camelize(app),
template: opts[:template],
assets: opts[:assets]
]

Mix.Generator.copy_template(source, target, assigns)
end

true ->
Mix.shell().error("Unknown template value: --template=#{opts[:template]}")
raise "Unknown template value: --template=#{opts[:template]}"
end

cond do
opts[:assets] == "tailwind" ->
for source <- Path.wildcard(Path.join(templates, "tailwind/**/*.{css,js}")) do
target =
Path.relative_to(source, Path.join(templates, "tailwind"))
|> String.replace("app_name", app)

assigns = [
app: app,
app_module: Macro.camelize(app),
template: opts[:template],
assets: opts[:assets]
]

Mix.Generator.copy_template(source, target, assigns)
end

opts[:assets] in ["vanilla", nil] ->
for source <- Path.wildcard(Path.join(templates, "no_assets/**/*.{css}")) do
target =
Path.relative_to(source, Path.join(templates, "no_assets"))
|> String.replace("app_name", app)

assigns = [
app: app,
app_module: Macro.camelize(app),
template: opts[:template],
assets: opts[:assets]
]

Mix.Generator.copy_template(source, target, assigns)
end

true ->
Mix.shell().error("Unknown assets value: --assets=#{opts[:assets]}")
raise "Unknown assets value: --assets=#{opts[:assets]}"
end
end
end
18 changes: 18 additions & 0 deletions lib/tableau_new.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule TableauNew do
@moduledoc """
Documentation for `TableauNew`.
"""

@doc """
Hello world.
## Examples
iex> TableauNew.hello()
:world
"""
def hello do
:world
end
end
43 changes: 43 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule TableauNew.MixProject do
use Mix.Project
@source_url "https://github.com/elixir-tools/tableau_new"

def project do
[
app: :tableau_new,
description: "Project generator for Tableau",
version: "0.1.0",
elixir: "~> 1.15",
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end

defp package do
[
maintainers: ["Mitchell Hanberg"],
licenses: ["MIT"],
links: %{
GitHub: @source_url,
Sponsor: "https://github.com/sponsors/mhanberg"
},
files: ~w(lib priv LICENSE mix.exs README.md .formatter.exs)
]
end
end
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%{
}
8 changes: 8 additions & 0 deletions priv/templates/eex/lib/app_name.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule <%= @app_module %> do
defmacro sigil_H({:<<>>, opts, [bin]}, _mods) do
quote do
_ = var!(assigns)
unquote(EEx.compile_string(bin, opts))
end
end
end
Loading

0 comments on commit 124cfdb

Please sign in to comment.