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

Make custom template and locale functioning easier #40

Closed
larsgw opened this issue Apr 7, 2017 · 3 comments
Closed

Make custom template and locale functioning easier #40

larsgw opened this issue Apr 7, 2017 · 3 comments
Assignees
Labels
enhancement Feature requests

Comments

@larsgw
Copy link
Owner

larsgw commented Apr 7, 2017

The current way of using custom templates and locales is confusing to say the best (see #28). Expected features:

  • default and custom template and locale registers, with appropriate methods
  • way to amend templates
@larsgw larsgw added the enhancement Feature requests label Apr 7, 2017
@larsgw larsgw self-assigned this Apr 7, 2017
@larsgw
Copy link
Owner Author

larsgw commented Jul 26, 2017

I outlined some possible APIs in a recent blogpost:

const template = '...'
const templateName = 'custom'

// Suggested new API
Cite.CSL.template.register(templateName, template)

// Nothing new, will stay the same
const data = new Cite(...)
data.get({
  type: 'html',
  style: 'citation-' + templateName
})
// prepends the id like this: "[$ID]: "
const prepend = ({id}) => `[${id}]: `
// appends an altmetric widget
const append = ({DOI}) => `<span class='altmetric-embed' data-doi='${DOI}'></span>`

// Nothing new, will stay the same
const data = new Cite(...)
data.get({
  type: 'html',
  style: 'citation-' + templateName,
  // Suggested new API
  // both properties either function or constant string
  append: append,
  prepend: prepend
})

I'm currently working on the implementation, and it will be slightly different, but not structurally (probably only method names):

const template = '...'
const templateName = 'custom'

// Suggested new API
Cite.CSL.register.addTemplate(templateName, template)

// Nothing new, will stay the same
const data = new Cite(...)
data.get({
  type: 'html',
  style: 'citation-' + templateName
})

@larsgw
Copy link
Owner Author

larsgw commented Aug 1, 2017

I failed to mention this here earlier, but the first part of the API change happened in 3aaaf7c (or v0.3.0-11). For current API, see here for templates and here for locales. Ping @austinjp.

@austinjp
Copy link

austinjp commented Aug 1, 2017

Great work @larsgw , really appreciate it. I'll have a detailed look another day!

@larsgw larsgw closed this as completed in 2ada412 Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants