Giter Site home page Giter Site logo

Comments (7)

nkuehn avatar nkuehn commented on July 17, 2024

update from a conversation with @emmenko about how to approach the topic:

  • we will go for an import and webpack-based approach. Users learn the import notation and have to lean it anyways for MDX transclusion.
  • code examples from outside the repository will be provided via a special package in the respective content repository which pulls the examples from whereever they live (e.g. the repository of an SDK) and then provides the files as a javascript package.

I'll update the issue description here

FYI @davifantasia

from commercetools-docs-kit.

davifantasia avatar davifantasia commented on July 17, 2024

I just want to say I started working on this.

from commercetools-docs-kit.

davifantasia avatar davifantasia commented on July 17, 2024

To be able to implement this:

import CartCreateExampleJs from '@commercetools-docs/code-examples/javascript/cart/create.js'
import CartCreateExampleJava from '../../code-examples/java/cart/create.java'

<CartCreateExampleJs title="Creating a Cart in Javascript" />
<CartCreateExampleJava highlightLines="5-10" title="Creating a Cart in Java" />

I looked into exporting CodeBlock component from a webpack loader. I mainly used this plugin as a base, because it pretty much has a similar process compared to what we want to achieve:

https://github.com/gregberge/svgr/blob/master/packages/webpack

My conclusion is that I have to understand how Babel transpiles both ES6 and React. At least for now, I don’t think it’s worth the effort.

from commercetools-docs-kit.

davifantasia avatar davifantasia commented on July 17, 2024

Current solution proposal:

Expose a AutoCodeExample component which authors can then use like so:

<AutoCodeExample import="@package/path/to/sample-code.js" title="JavaScript Code Sample" />

<AutoCodeExample import="/path/to/sample-code.java" />

AutoCodeExample - name was chosen after discussing with @adinakleine , since this tool is author-centric.

This component would only work with a simple webpack loader tool that returns file contents as a string which the component can then render as content of a code block.

from commercetools-docs-kit.

emmenko avatar emmenko commented on July 17, 2024

In the PR #299 you only load code examples from a local folder. What about external files?

from commercetools-docs-kit.

davifantasia avatar davifantasia commented on July 17, 2024

In the PR #299 you only load code examples from a local folder. What about external files?

That is still a draft PR. I appreciate early review but in this case I suggest you wait until I mark it as ready for review.

from commercetools-docs-kit.

davifantasia avatar davifantasia commented on July 17, 2024

I still had trouble implementing this task by taking advantage of building a webpack plugin. So I sat down with @jenschude to find a solution, after that I decided on a different approach. Please see the PR here - #300

from commercetools-docs-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.