Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future of this repository #5

Open
mudassir0909 opened this issue Dec 25, 2015 · 1 comment
Open

Future of this repository #5

mudassir0909 opened this issue Dec 25, 2015 · 1 comment

Comments

@mudassir0909
Copy link
Member

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

  • get the picture from gravatar using the specified email address if the user fails to provide a url
  • formatting dates
  • computing the resume.basics.location object
  • computing the url for a profile based on the profile.username & profile.network
  • markdown to html conversion

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants