Skip to content

Commit

Permalink
Allow colons and slashes in attribute shortcuts (#163)
Browse files Browse the repository at this point in the history
* update deps to fix build on elixir 1.11

* allow colons and slashes in attribute shortcuts

Fixes #162.

* simplify shortcut_value rule in parser

* add github workflow to run tests

* Delete test.yml

Co-authored-by: Sean Callan <[email protected]>
  • Loading branch information
utkarshkukreti and doomspork authored Apr 28, 2021
1 parent 4aac1cc commit 0e90977
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/slime/parser/transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ defmodule Slime.Parser.Transform do
end

def transform(:tag_name, input, _index), do: to_string(input)
def transform(:shortcut_value, input, _index), do: to_string(input)
def transform(:attribute_name, input, _index), do: to_string(input)
def transform(:crlf, input, _index), do: to_string(input)
def transform(_symdol, input, _index), do: input
Expand Down
3 changes: 2 additions & 1 deletion src/slime_parser.peg.eex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tag_shortcut <- tag:tag_name attrs:shortcuts / tag:tag_name / attrs:shortcuts;

shortcuts <- head:shortcut tail:(shortcut)*;

shortcut <- type:('.' / '#' / '@' / '$' / '%' / '^' / '&' / '+' / '!') value:tag_name;
shortcut <- type:('.' / '#' / '@' / '$' / '%' / '^' / '&' / '+' / '!') value:shortcut_value;

attributes <- wrapped_attributes / plain_attributes;

Expand Down Expand Up @@ -96,6 +96,7 @@ embedded_engine_lines <- indented_text_line (crlf indented_text_line)*;
indented_text_line <- space? text_item*;
tag_name <- [a-zA-Z0-9_-]+;
shortcut_value <- ([:/]? [a-zA-Z0-9_-])+;
attribute_name <- [a-zA-Z0-9._@:-]+;
space <- [ \t]+;
indent <- '\x{0E}';
Expand Down
5 changes: 5 additions & 0 deletions test/rendering/attributes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ defmodule RenderAttributesTest do
assert render(".my-css-class test") == ~s[<div class="my-css-class">test</div>]
end

test "class name in .-dot shortcut can include colons and slashes" do
assert render(".relative.sm:pb-16.md:pb-20.lg:w-1/2 test") ==
~s[<div class="relative sm:pb-16 md:pb-20 lg:w-1/2">test</div>]
end

test "text content can contain `.` character" do
assert render(~s(div test.class)) == ~s(<div>test.class</div>)
end
Expand Down

0 comments on commit 0e90977

Please sign in to comment.