jsonresume / theme-utils

Utility methods for theme developers
20 stars 6 forks source link

Future of this repository #5

Open mudassir0909 opened 8 years ago

mudassir0909 commented 8 years ago

The main purpose of this repository is to make the job easier for theme developers in transforming the resume object to suit their theme needs. The current implementation is pretty ad-hoc since all I did was just transfer this repository to jsonresume & I did not have a proper plan back then. So, the code in this repo is highly contextual to elegant's need. I want this to be generic so that any theme developer can use it to their benefits.

Following are the computations most theme developers do

I thought about how the api should look & here's what I propose. The theme developers pass the resume object to utils.transformResume method which would emit out the transformed resume object which they can directly plug into the template, this method would take resume as first argument & options as second argument. So, in a nutshell the code to render a theme would look as follows:

var utils = require('jsonresume-themeutils');

function render(resume) {
    resume = utils.transformResume(resume, options);

    // return the compiled html
}

module.exports = {render: render};

The options object structure will be similar to jsonresume schema, the keys remain the same but the value will be replaced with a transformer function which takes the input as resume[key], does the transformation & returns a value(If this sentence was confusing, I hope it'll be easier with an example below)

var utils = require('jsonresume-themeutils');
var marked = require('marked');

function markdownTransformer(str) {
    return marked(str);
}

function pictureTransformer(url, email) {
    if (url != null) {
        return url; 
    }
    // get url from gravatar
}

function addressTransformer(location) {
    return [location.city, location.state, location.country].join(', ');
}

function profileTransformer(profile) {
    if (profile.url) {
        return profile.url;
    }

    // compute url using profile.network & profile.username
}

function render(resume) {
    var options = {
        basics: {
            summary: markdownTransformer, // equivalent to, resume.basics.summary = markdownTranformer(resume.basics.summary) & so on...
            location: addressTransformer,
            picture: pictureTransformer
        },
        profiles: [profileTransformer], //if the transformer is specified inside an array, it'll be run against each item in the array else it'll run on the complete array.
        work: [{
            startDate: dateTransformer,
            summary: markdownTransformer
        }]
    };

    resume = utils.transformResume(resume, options);

   // return compiled html
}

module.exports = {
  render: render
}

We can move common transformers such as profileTransformer, pictureTransformer etc under this repo so that developers can directly use utils.profilerTransformer so that they can reuse the logic. Thoughts?

thomasdavis commented 8 years ago

Just posting so I get notifications but will come back with a bigger reply.

This repo will be one of the biggest going into the new year.

I would love to see it spilt up a lot more potentially theme-utils-locale, theme-utils-dates etc

There also might be util libraries that aren't exactly theme related, going to white board this out.

Excellent work here though. We should link it from all the theme doc pages asap.