Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Convert Ember.js curly Components to angle brackets.
</h1>
  <i>Note: This little tool supports simple, inline (non block) components without helpers. See 
  <a href="https://github.com/emberjs/rfcs/blob/master/text/0311-angle-bracket-invocation.md">RFC 311</a> for more details and advanced invocation examples.</i>
<section>
  <label><h2>Enter curly component:</h2></label>
  <input type="text" value="{{my-component model=model myAction=(action 'myAction')}}">
  <button id="submit">submit</button>
</section>

<section>
  <h2>Result:</h2>
  <p id="result"></p>
</section>
              
            
!

CSS

              
                body {
  font-family: sans-serif;
  padding: 20px;
}

#result {
  background-color: #e3e4e5;
  padding: 15px;
}

input {
  width: 100%;
  font-size: 14px;
  padding: 5px;
}

button {
  margin-top: 10px;
  font-size 14px;
  padding: 5px;
  border-radius: 4px;
  background-color: white;
  border: 3px solid #13d8d5;
}
              
            
!

JS

              
                const extractActions = function(str) {
  let actions = str.match(/([A-Za-z]+=[(]action)(.*?)[)]/g) // get everthing inside of action parens, plus the stuff to the left of the =
  return actions.map(function(item) {
    item = item.trim()
    let a = item.split('=')[0]
    let b = item.split('=')[1]
      .replace('(', '{{')
      .replace(')', '}}')
    return `@${a}=${b}` // replace () with {{}} and add @ to the front
  }).join(' ')
}

const extractComponentName = function(str) {
 let name = str.match(/\{\{(.*?)\s/g)[0]
   .slice(2,-1)
   .trim()
   .replace("{{", '')
  //get everything from the {{ to the first space 
 return capitalizeName(name)
}

const extractParams = function(str) {
  let params = str.match(/\s[A-Za-z]+=(([A-Za-z\.]+)([A-Za-z]+)|([A-Za-z]+))/g)
  // match everything that has letters only on either side of an equals sign, plus `this.`
  return params.map(function(item) {
    item = item.trim()
    let a = item.split('=')[0]
    let b = item.split('=')[1]
    return `@${a}={{${b}}}`
  }).join(' ')
}

const upperFirstLetter = function (str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

const capitalizeName = function (name) {
    return name.split('-').map(function(word) {
      return upperFirstLetter(word)
    }).join('')
}

const convert = function(str) {
  try {
  let actions = extractActions(str)
  let name = extractComponentName(str)
  let params = extractParams(str)
  return `&lt;${name} ${actions} ${params} /&gt;` //lt and gt are < and >
  } catch(err) {
    return "error"
  }
}



document.addEventListener("DOMContentLoaded", function(event) {
  document.querySelector('button').addEventListener('click', event => {
  console.log(convert())
  let input = document.querySelector('input').value
  document.querySelector('#result').innerHTML = convert(input)
});
    
});
              
            
!
999px

Console