Handle HTML fragments in temple.convert task (#35)

* Handle HTML fragments in temple.convert task

* Add GH CI action

* Remove travis config
This commit is contained in:
Mitchell Hanberg 2019-11-22 22:48:20 -05:00 committed by GitHub
parent d2e8a45094
commit 1d71c27a34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 120 additions and 17 deletions

62
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,62 @@
name: CI
on:
pull_request:
push:
branches: master
jobs:
tests:
runs-on: ubuntu-latest
name: Test (${{matrix.elixir}}/${{matrix.otp}})
strategy:
matrix:
otp: [21.x]
elixir: [1.7.x, 1.8.x, 1.9.x]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-elixir@v1.0.0
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- uses: actions/cache@v1
id: cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Run Tests
run: mix test
formatter:
runs-on: ubuntu-latest
name: Formatter (1.9.x/21.x)
steps:
- uses: actions/checkout@v1
- uses: actions/setup-elixir@v1.0.0
with:
otp-version: 21.x
elixir-version: 1.9.x
- uses: actions/cache@v1
id: cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-mix-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: mix deps.get
- name: Run Formatter
run: mix format --check-formatted

View file

@ -1,16 +0,0 @@
language: elixir
elixir:
- 1.7.4
- 1.8.2
- 1.9.0
otp_release:
- 20.3
- 21.3
- 22.0
sudo: false
cache:
directories:
- _build
- deps
script:
- mix test

View file

@ -8,7 +8,9 @@ defmodule Temple.HtmlToTemple do
result =
doc
|> Floki.parse()
|> do_parse(0)
|> List.wrap()
|> Enum.map(&do_parse(&1, 0))
|> Enum.join("\n")
{:ok, result}
end

View file

@ -86,4 +86,59 @@ defmodule Mix.Tasks.HtmlToTempleTest do
end
"""
end
test "parses HTML fragments" do
html = """
<section class="phx-hero">
<h1><%= gettext "Welcome to %{name}!", name: "Phoenix" %></h1>
<p>A productive web framework that<br/>
does not compromise speed or maintainability.</p>
</section>
<section class="row">
<article class="column">
<h2>Resources</h2>
<ul>
<li>
<a href="https://hexdocs.pm/phoenix/overview.html">Guides &amp; Docs</a>
</li>
</ul>
</article>
</section>
"""
{:ok, result} = Temple.HtmlToTemple.parse(html)
assert result === """
section class: "phx-hero" do
h1 do
text "<%= gettext \"Welcome to %{name}!\", name: \"Phoenix\" %>"
end
p do
text "A productive web framework that"
br()
text "
does not compromise speed or maintainability."
end
end
section class: "row" do
article class: "column" do
h2 do
text "Resources"
end
ul do
li do
a href: "https://hexdocs.pm/phoenix/overview.html" do
text "Guides & Docs"
end
end
end
end
end
"""
end
end