How can i get stylesheet css file body?

Hi all,
How can i using elixir language to get stylesheet css content?
I want to check a class name if exists in stylesheet css file.
Thanks.

I think you need to help us out a bit with this one. I don’t think it’s clear what your intent is from the above description…

2 Likes

I agree with @hubertlepicki. I am a bit confused exactly what you are after. But, if you really just want to see if a class exists in a style sheet, then one :point_up:t2: solution would be to read the file and match the class name using a regular expression.

1 Like

Hi @Matt @hubertlepicki,Thanks for reply.

Yes, Correct. That class name is my icon class and same with my item name.
I need to check when class name exists in my css file then display , if not exists will set to default icon.
I will run for to read out all item in my page, and using render_check to check,
render_check will return default if that icon name not exists.
<%= for item <- @items do %>
< span class="<%= render_check(item.name) %>"></ span >

<% end %>

Can give me a simple example how to read my css file and using a regular expression to check?
Thanks

Hi all,
I am doing this, can i improve any code?

def render_check(item) do
url = “xxx.css”
response = HTTPoison.get!(url)

if response.body =~ item do
  "icon-" <> item
else
  "icon-default"
end

end

That purely a CSS problem - i.e. you always specify the default icon and the other icon overlaps it if it exists. Example:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Overlapping</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <style type="text/css">
   .icon-one:before { content: "⊟"; }
   .icon-two:before { content: "⊞"; }
   .icon-three:before { content: "⊠"; }
  </style>
</head>

<body>
  <p><span><span class="icon-one" aria-hidden="true"></span>#1</span></p>
  <p><span><span class="icon-two" aria-hidden="true"></span>#2</span></p>
  <p><span><span class="icon-three" aria-hidden="true"></span>#3</span></p>
  <p><span><span class="icon-one icon-two" aria-hidden="true"></span>#4</span></p>
  <p><span><span class="icon-two icon-one" aria-hidden="true"></span>#5</span></p>
  <p><span><span class="icon-three icon-four" aria-hidden="true"></span>#6</span></p>
  <p><span><span class="icon-four icon-three" aria-hidden="true"></span>#7</span></p>
</body>
</html>

results in

tmp

with #4 and #5 icon-two is shown because it’s defined after icon-one
with #6 and #7 icon-three is shown because icon-four doesn’t exist

3 Likes

Also making an http request to check a file that should be local seems highly ineffective. There is grep command in Unix world, or maybe just use File module.

1 Like