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:
parent
d2e8a45094
commit
1d71c27a34
4 changed files with 120 additions and 17 deletions
62
.github/workflows/ci.yml
vendored
Normal file
62
.github/workflows/ci.yml
vendored
Normal 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
|
||||
|
16
.travis.yml
16
.travis.yml
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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 & 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
|
||||
|
|
Reference in a new issue