Skip to content

Commit

Permalink
Fix parsing dashes in css classes
Browse files Browse the repository at this point in the history
Closes #12
  • Loading branch information
doomspork committed Aug 5, 2015
1 parent 097d0a3 commit 99f9a7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/slim_fast/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule SlimFast.Parser do
defp attribute_val(value), do: parse_eex(value, true)

defp css_classes(input) do
css = ~r/\.([\w-]{1,})/
css = ~r/\.([\w-]+)/
|> Regex.scan(input)
|> Enum.flat_map(fn ([_|class]) -> class end)

Expand Down Expand Up @@ -108,7 +108,7 @@ defmodule SlimFast.Parser do
end

defp parse_line(_, line) do
parts = ~r/^\s*(?<tag>\w*(?:[#.]\w+)*)(?<attrs>(?:\s*[\w-]+\s*=(".+"|\w+))*)(?<tail>.*)/
parts = ~r/^\s*(?<tag>\w*(?:[#.][\w-]+)*)(?<attrs>(?:\s*[\w-]+\s*=(".+"|\w+))*)(?<tail>.*)/
|> Regex.named_captures(line)

{tag, basics} = parse_tag(line)
Expand Down
7 changes: 7 additions & 0 deletions test/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ defmodule ParserTest do
assert parsed == [{0, {:div, attributes: [class: ["class"], id: "id"], children: []}}, {2, {:p, attributes: [], children: ["Hello World"]}}]
end

test "parses css classes with dashes" do
{_, {:div, opts}} = ".my-css-class test"
|> Parser.parse_line

assert opts == [attributes: [class: ["my-css-class"]], children: ["test"]]
end

test "parses attributes" do
{_, {:meta, opts}} = "meta name=variable content=\"one two\""
|> Parser.parse_line
Expand Down

0 comments on commit 99f9a7d

Please sign in to comment.