<?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: Dave Myburgh</title>
    <description>The latest articles on DEV Community by Dave Myburgh (@davemyb).</description>
    <link>https://dev.to/davemyb</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F317322%2F7c09af6b-25d5-4022-aa55-e346a3b56dad.jpeg</url>
      <title>DEV Community: Dave Myburgh</title>
      <link>https://dev.to/davemyb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davemyb"/>
    <language>en</language>
    <item>
      <title>Setting up StandardJS in VSCode for React work</title>
      <dc:creator>Dave Myburgh</dc:creator>
      <pubDate>Thu, 11 Jun 2020 15:58:22 +0000</pubDate>
      <link>https://dev.to/davemyb/setting-up-standardjs-in-vscode-for-react-work-2am0</link>
      <guid>https://dev.to/davemyb/setting-up-standardjs-in-vscode-for-react-work-2am0</guid>
      <description>&lt;p&gt;I've started learning React - so far it's really cool - and being a bit of a stickler for code styling, I wanted to use something that would keep my code consistent and in line with my current company's style. &lt;/p&gt;

&lt;p&gt;The question that really got me into this was the age-old one of "Semi-colons or no semi-colons at the end of a line?". I will NOT get into which is better, because I have better things in my life to do than debate that :) Anyway, devs at my company recommended &lt;a href="https://standardjs.com/" rel="noopener noreferrer"&gt;StandardJS&lt;/a&gt; (on &lt;a href="https://github.com/standard/standard" rel="noopener noreferrer"&gt;Github&lt;/a&gt;), so here's how I integrated that into &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VSCode&lt;/a&gt;. Note that the Prettier extension is similar to this, and can apparently be configured to work like StandardJS. However, I never tried that myself.&lt;/p&gt;

&lt;p&gt;In my project's folder, I used npm to install the StandardJS package along with ESLint:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install --save-dev standard eslint-plugin-html


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once that was done, I added the following code to &lt;code&gt;package.json&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  "standard.options": {
    "ignore": [
      "node_modules/**"
    ],
    "plugins": [
      "html"
    ],
    "parser": "babel-eslint"
  }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I installed the following extension for VSCode: &lt;a href="https://marketplace.visualstudio.com/items?itemName=chenxsan.vscode-standardjs" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=chenxsan.vscode-standardjs&lt;/a&gt; and then edited my &lt;code&gt;settings.json&lt;/code&gt; file (click the gear icon in the bottom left corner of VSCode, select Settings, then click the little page icon in the top right corner to open &lt;code&gt;settings.json&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxp6d8nhv9i9d1ack6uig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxp6d8nhv9i9d1ack6uig.png" alt="settings.json link"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I added the following code to the end of my file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    // StandardJS settings.
    // ------------------------------
    // Disable default validator first.
    "javascript.format.enable": false,
    "javascript.validate.enable": false,
    "standard.enable": true,
    "standard.autoFixOnSave": true,
    "standard.validate": [
        "javascriptreact"
    ]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I had already set a file association for &lt;code&gt;javascriptreact&lt;/code&gt; earlier, but I will provide it here, just in case you don't have that yet. This is also in &lt;code&gt;settings.json&lt;/code&gt;. If you already have a &lt;code&gt;files.associations&lt;/code&gt; section, just add the &lt;code&gt;*.js&lt;/code&gt; line to it, and don't forget the comma on the preceding line; no trailing comma on the last line:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

    "files.associations": {
        "*.js": "javascriptreact"
    },


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, when you're editing &lt;code&gt;.js&lt;/code&gt; files in a React project, you should see &lt;code&gt;Javascript React&lt;/code&gt; in the status bar of VSCode, in the bottom right corner, with &lt;code&gt;Javascript Standard Style&lt;/code&gt; next to it. If you just see &lt;code&gt;Javascript&lt;/code&gt; for the first part, click on it and select &lt;code&gt;Javascript React&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqj79c3ho2b56tp9ei7w8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqj79c3ho2b56tp9ei7w8.png" alt="File language type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One thing to note: I already had an ESLint extension added to VSCode, so you might need that too. In case you do, this is the one I have &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That's it! Enjoy the nicely formatted code (with no trailing semi-colons) :)&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>react</category>
      <category>standardjs</category>
    </item>
    <item>
      <title>Integrate Ceros experiences with Drupal 8</title>
      <dc:creator>Dave Myburgh</dc:creator>
      <pubDate>Mon, 20 Apr 2020 15:42:53 +0000</pubDate>
      <link>https://dev.to/davemyb/integrate-ceros-experiences-with-drupal-8-di2</link>
      <guid>https://dev.to/davemyb/integrate-ceros-experiences-with-drupal-8-di2</guid>
      <description>&lt;p&gt;I worked on a project recently where the client had some interactive pages created in &lt;a href="https://www.ceros.com/"&gt;Ceros&lt;/a&gt;. They call them "Experiences", so we'll just stick to that naming for Ceros content. Take a look at their examples for some of the cool interactions you can get. It kinda reminds me of the Flash days, except this is HTML5, so it's better :)&lt;/p&gt;

&lt;p&gt;The default way to have the Ceros experiences appear on your website is to use their embed code, which consists of a wrapper div with a bunch of inline styles and attributes, an iframe, and a Javascript file import. As long as your page doesn't do anything to mess with the dimensions of the wrapper div and iframe, it should just work.&lt;/p&gt;

&lt;p&gt;Here's an example embed code (I've formatted it so it's easier to read - it's usually one long line):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; 
  &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;'
    position: relative;
    width: auto;
    padding: 0 0 174.84%;
    height: 0;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: 0;
    border: 0 none
  '&lt;/span&gt; 
  &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"experience-5c93c4d6c1129"&lt;/span&gt; 
  &lt;span class="na"&gt;data-aspectRatio=&lt;/span&gt;&lt;span class="s"&gt;"0.5719"&lt;/span&gt; 
  &lt;span class="na"&gt;data-mobile-aspectRatio=&lt;/span&gt;&lt;span class="s"&gt;"0.2716"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;iframe&lt;/span&gt; 
    &lt;span class="na"&gt;allowfullscreen&lt;/span&gt; 
    &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;'//view.ceros.com/ceros-educate/adaptive-layouts-build-along-1?heightOverride=2238&amp;amp;mobileHeightOverride=2945'&lt;/span&gt; 
    &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;'
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      margin: 0;
      padding: 0;
      border: 0 none;
      height: 1px;
      width: 1px;
      min-height: 100%;
      min-width: 100%
    '&lt;/span&gt; 
    &lt;span class="na"&gt;frameborder=&lt;/span&gt;&lt;span class="s"&gt;'0'&lt;/span&gt; 
    &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;'ceros-experience'&lt;/span&gt; 
    &lt;span class="na"&gt;scrolling=&lt;/span&gt;&lt;span class="s"&gt;'no'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"//view.ceros.com/scroll-proxy.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the padding inline style on the wrapper div - the bottom padding amount will vary depending on the aspect ratio and size of the iframe. Without it, your iframe will not be the right size and weird things start to happen with content that should be below the iframe.&lt;/p&gt;

&lt;p&gt;A CMS like Drupal is a slightly different beast, though. Sure, you can create a text format that implements no filtering and throw the embed code into a textarea that uses that filter. That will work just fine in many cases e.g. if you're the only one working on your site. But, if you have multiple people adding content to your site, security becomes an issue, and not stripping out potentially bad things - like scripts - is generally not a good idea. You could create a text format that specifically only allows the elements in the embed code, but the Allowed HTML filter will ALWAYS strip out inline styles, so you lose that critical bottom padding.&lt;/p&gt;

&lt;p&gt;Turns out, Ceros has an oEmbed option too. Once you have Drupal configured, you simply provide the url to the Ceros experience using the https:\view.ceros.com[account][page-url] format, and it generates the embed code for you. No security issues and nothing important gets stripped out.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to configure Drupal for oEmbed
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install the &lt;a href="https://www.drupal.org/project/url_embed"&gt;URL Embed&lt;/a&gt; module (will install &lt;a href="https://www.drupal.org/project/embed"&gt;Embed module&lt;/a&gt; too).&lt;/li&gt;
&lt;li&gt;Go to /admin/config/content/formats and create a new text format for Ceros content. You could also add it to an existing format if you prefer.&lt;/li&gt;
&lt;li&gt;Enable the filters "Display embedded URLs" and "Convert URLs to URL embeds".&lt;/li&gt;
&lt;li&gt;Ensure that "Convert URLs to URL embeds" runs before "Display embedded URLs".&lt;/li&gt;
&lt;li&gt;If the "Limit allowed HTML tags" filter is enabled, add  to the Allowed HTML tags.&lt;/li&gt;
&lt;li&gt;If you have CKEditor enabled for the text format, URL Embed provides a button (it has a music note and a video icon on it) that you can add to your toolbar to make embedding urls easier. It will open up a modal to put your url in, then load it and display it in CKEditor directly.&lt;/li&gt;
&lt;li&gt;I created a separate field just for Ceros content, but you can easily just embed directly into existing fields via CKEditor. The field is a text (formatted) field and uses the special Ceros text format as the default. Note: I had to put a space in the text field to make it actually keep the Ceros text format as the default format.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's basically it. If you put a Ceros url into the field and save the node, you should see the spinner from Ceros appear and eventually your content will load. Ensure that you see the bottom padding amount is showing up on the wrapper div and you should be all set.&lt;/p&gt;

</description>
      <category>drupal</category>
      <category>ceros</category>
      <category>oembed</category>
    </item>
    <item>
      <title>Simple command-line trick to help manage multiple projects</title>
      <dc:creator>Dave Myburgh</dc:creator>
      <pubDate>Tue, 14 Jan 2020 16:29:24 +0000</pubDate>
      <link>https://dev.to/davemyb/simple-command-line-trick-to-help-manage-multiple-projects-300a</link>
      <guid>https://dev.to/davemyb/simple-command-line-trick-to-help-manage-multiple-projects-300a</guid>
      <description>&lt;p&gt;I work on multiple projects during a regular work day - usually 2-4, but could be as many as 8. Each project has a different main Git branch, theme folder, build command to compile said theme, and a couple of other settings (I'm a Drupal developer, so several settings are Drupal-specific, but the concept I'm going to explain can apply to any type of project). Keeping track of each of these as I switch between projects was a pain in the neck, so I came up with an old-school solution.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;tl;dr: Create a dot-file in your project root folder that contains the relevant info and display it when you change to that project.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the olden days of Norton Commander and BBS systems, you could create a file in your directories that contained descriptions for files in that directory. I think the file was named &lt;code&gt;descript.ion&lt;/code&gt; or something like that. Anyway, using that idea, I created a &lt;code&gt;.readme&lt;/code&gt; file in each project's root folder. The file contains a standard structure so that it's easy for me to find the info I need. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Git main branch : dev
Config import   : vcs
Drupal version  : 8.7.11
Code folder     : docroot/profiles/myproject/
Theme folder    : docroot/profiles/myproject/themes/myproject_theme
Theme scripts   : npm run exec
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Don't forget to exclude this file in your &lt;code&gt;.gitignore&lt;/code&gt; file. I guess you could leave it there for other developers in your team, as long as there is nothing sensitive in there - depending on what your root folder is, this file might get exposed at some point.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This alone is pretty handy, but I had to type &lt;code&gt;cat .readme&lt;/code&gt; each time to see this info, and if I can save some typing, I will. Each project already had a bash alias that changes directory to it, so all I did was add &lt;code&gt;cat .readme&lt;/code&gt; to that alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias mp="cd ~/Sites/myproject &amp;amp;&amp;amp; ls -al &amp;amp;&amp;amp; cat .readme"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;ls&lt;/code&gt; command is helpful to me to know exactly where I am - how many times do you cd into a directory and immediately type &lt;code&gt;ls&lt;/code&gt;?? In fact, I integrated the &lt;code&gt;ls&lt;/code&gt; into the &lt;code&gt;cd&lt;/code&gt; command and removed it from the alias above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias l="ls -al"

function cd () {
  builtin cd "$1"
  l
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above aliases go into &lt;code&gt;~/.bash_profile&lt;/code&gt; or &lt;code&gt;~/.bashrc&lt;/code&gt; depending on your OS. I only work on Mac and Linux, so I don't know if you can do something similar in Windows' command line.&lt;/p&gt;

&lt;p&gt;That's it. Hopefully you find this as useful as I do. If anyone has a different solution let me know in the comments below.&lt;/p&gt;

</description>
      <category>bash</category>
    </item>
  </channel>
</rss>
