Skip to content

Instantly share code, notes, and snippets.

View allmarkedup's full-sized avatar

Mark Perkins allmarkedup

View GitHub Profile
@allmarkedup
allmarkedup / FractalPlugin.php
Last active August 26, 2021 15:10
Fractal component loader plugin for Craft cms
<?php
namespace Craft;
class FractalPlugin extends BasePlugin
{
public function init()
{
craft()->templates->getTwig()->setLoader(new FractalTemplateLoader());
@allmarkedup
allmarkedup / fractal.js
Created February 7, 2017 09:02
Export JSON map of Fractal @handle references to filesystem paths
const path = require('path');
const fs = require('fs');
const fractal = module.exports = require('@frctl/fractal').create();
function exportPaths() {
const map = {};
for (let item of fractal.components.flatten()) {
map[`@${item.handle}`] = path.relative(process.cwd(), item.viewPath);
}
fs.writeFileSync('components-map.json', JSON.stringify(map, null, 2), 'utf8');
@allmarkedup
allmarkedup / fractal.js
Created November 8, 2016 09:10
Fractal CLI command to export component templates with path rewrites
const fs = require('fs');
function exportTemplates(args, done) {
const app = this.fractal;
const items = app.components.flattenDeep().toArray();
const jobs = [];
for (const item of items) {
@allmarkedup
allmarkedup / fractal.js
Created October 11, 2016 09:40
Fractal + Twig
'use strict';
const twig = require('@frctl/twig');
const fractal = module.exports = require('@frctl/fractal').create();
fractal.set('project.title', 'Twig + Fractal');
/*
* Components
*/
asd
@allmarkedup
allmarkedup / button.jsx
Created August 27, 2016 11:22
Example react component for fractal
import React, { PropTypes } from 'react';
const STYLE_PREFIX = 'c-button';
const Button = (props) => {
const buttonProps = {
className: `${STYLE_PREFIX}`,
disabled: props.disabled,
type: props.submit ? 'submit' : 'button'
};
@allmarkedup
allmarkedup / fractal.js
Created August 17, 2016 09:54
Gulp using fractal.js file
'use strict';
/* Create a new Fractal instance and export it for use elsewhere if required */
const fractal = module.exports = require('@frctl/fractal').create();
/* Set the title of the project */
fractal.set('project.title', 'FooCorp Component Library');
/* Tell Fractal where the components will live */
fractal.components.set('path', __dirname + '/src/components');
{
"context": {
"bar": {
"title": "Title for Bar"
},
"baz": {
"title": "Title for BaZ"
}
}
}
@allmarkedup
allmarkedup / fractal.js
Created April 6, 2016 15:28
Run gulp tasks from within the Fractal interactive CLI interface
'use strict';
const fractal = require('@frctl/fractal');
const gulp = require('./gulpfile');
fractal.command('gulp [task]', function(args, done){
const task = args.task || 'default';
this.console.notice(`Running gulp '${task}' task...`);
gulp.start(task, err => {
if (err) {