<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: May Kittens Devour Your Soul</title>
    <description>The latest articles on DEV Community by May Kittens Devour Your Soul (@diomed).</description>
    <link>https://dev.to/diomed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1100728%2F37163679-3039-4288-ba7d-cf0b74311634.png</url>
      <title>DEV Community: May Kittens Devour Your Soul</title>
      <link>https://dev.to/diomed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/diomed"/>
    <language>en</language>
    <item>
      <title>Fetching JSON data with Alpine.js [ACCIO!]</title>
      <dc:creator>May Kittens Devour Your Soul</dc:creator>
      <pubDate>Fri, 07 Jul 2023 17:16:26 +0000</pubDate>
      <link>https://dev.to/diomed/fetching-json-data-with-alpinejs-accio-261n</link>
      <guid>https://dev.to/diomed/fetching-json-data-with-alpinejs-accio-261n</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/shibun/alpinejs-tutorial-getting-started-with-interactive-web-applications-484c"&gt;Familiarize yourself with alpine.js if you haven't already&lt;/a&gt;. It's after all, probably the best lightweight solution to which every webdev should lean to these days. &lt;/p&gt;

&lt;p&gt;Anyway, one could imagine my frustration and fury, after looking throught bunch of internet searches for something this simple, only to only find out what I really wanted to do - and I wanna display content of JSON files in a reading suitable way [without boring tables].&lt;/p&gt;

&lt;p&gt;So here is the magic code in all it's simplicity:&lt;/p&gt;

&lt;p&gt;We shall start with div that will call data from Harry Potter api&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;cloak&lt;/span&gt; 
     &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;{magic: [], isLoading: true }&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
     &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;async () =&amp;gt; {
          const response = await fetch('https://potterhead-api.vercel.app/api/spells')
          const data = await response.json();
          magic = data;
          console.log(data)
          isLoading = false;
        }&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;x-cloak&lt;/code&gt; - is something we must have in order for content not to blink (idk... seems like minor annoyance and bitter flaw of alpine.js so far)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x-data&lt;/code&gt; - says that our array is called magic&lt;/p&gt;

&lt;p&gt;main stuff is this &lt;/p&gt;

&lt;p&gt;&lt;code&gt;x-init&lt;/code&gt; - which asynchronously calls and &lt;strong&gt;fetches json from API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;as you can see next in code, we say that &lt;code&gt;magic = data&lt;/code&gt;&lt;br&gt;
so that magic  array is gonna be our data&lt;/p&gt;

&lt;p&gt;Unlike people who put everything in tables, we're gonna put it in some bulma tags&lt;/p&gt;

&lt;p&gt;Here is our &lt;strong&gt;template&lt;/strong&gt;. This is what finally DISPLAYS all that magic that happens once we get api answer and data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;spell, index in magic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;field is-grouped is-grouped-multiline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;control&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tags has-addons&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;            
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tag is-link is-medium&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;index+1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tag is-info is-medium&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;spell.name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tag is-dark is-medium&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;spell.description&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now say that for &lt;code&gt;spell, index in magic&lt;/code&gt;&lt;br&gt;
we shall have this list of spell names and spell description.&lt;/p&gt;

&lt;p&gt;index means that we shall count. &lt;br&gt;
You see that we count+1 with &lt;code&gt;index+1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x-text="spell.name"&lt;/code&gt; - gets us name of the spell&lt;br&gt;
&lt;code&gt;x-text="spell.description"&lt;/code&gt; - gets us description of it.&lt;/p&gt;

&lt;p&gt;So this is small overview of what happens in this code which is of course, available in this &lt;a href="https://codepen.io/diomed/pen/vYQZOaV"&gt;demo PEN&lt;/a&gt; on codepen.&lt;/p&gt;

&lt;p&gt;I'll advise you to be careful with JS as one is to be careful with spells. One wrongly written levi-o-sah and you're in trouble.&lt;/p&gt;

&lt;p&gt;PS&lt;/p&gt;

&lt;p&gt;You can name your array differently, but be sure to change that in template then, and in that line where you = it with data.&lt;/p&gt;

&lt;p&gt;You can also name spell something else. &lt;/p&gt;

&lt;p&gt;You can pull all kinds of .json files like this and get data from them. Especially useful if you need a collection of something that is already premade, so you don't have to waste your time writing same things all over again. Because there's probably always someone who already did that.&lt;/p&gt;

&lt;p&gt;Good luck!&lt;/p&gt;

</description>
      <category>alpinejs</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Style your mark and leave a mark</title>
      <dc:creator>May Kittens Devour Your Soul</dc:creator>
      <pubDate>Wed, 05 Jul 2023 13:29:19 +0000</pubDate>
      <link>https://dev.to/diomed/style-your-mark-and-leave-a-mark-6m3</link>
      <guid>https://dev.to/diomed/style-your-mark-and-leave-a-mark-6m3</guid>
      <description>&lt;p&gt;Recently I browsed the web and ran into an article on Medium from 2017. It talked about &lt;a href="https://blog.prototypr.io/css-only-multi-color-backgrounds-4d96a5569a20"&gt;multi colored backgrounds&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;It said that linear gradients are cool for styling backgrounds. &lt;br&gt;
No doubt. No doubt. &lt;/p&gt;

&lt;p&gt;So of course, I used one of them... ON MARK ELEMENT!&lt;br&gt;
Another on span... &lt;/p&gt;

&lt;p&gt;And voila. They look great! &lt;br&gt;
Today in a world where you have web color generators that basically mix those colors for you, into nice ones, it would be a shame not to utilize it on a web page. &lt;/p&gt;

&lt;p&gt;So code and enjoy in making web prettier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;mark&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;110deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#fdcd3b&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#ffed4b&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://jsfiddle.net/xbhaL0fd/"&gt;Example on jsFiddle&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>html</category>
      <category>css</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
