Git Product home page Git Product logo

codepled's Introduction

Codepled Logo

Codepled

A new type of media for coding tutorials.

Combine the advantages of tutorial videos with those of blog posts.

Have the code side by side with the explanations and see it change in real time:

Codepled Preview


Navigate as if you were watching a video.

Codepled Navigation Preview


But copy and paste code.

Codepled Copy and Paste Preview

How to use

For complete examples check out the examples section.

Include Codepled

To use the codepled editor you need to insert codepled.min.js and codepled.min.css and provide a container element that we give the id my-codepled:

<link rel="stylesheet" href="../codepled.min.css" />
...
<script src="../codepled.min.js"></script>
...
<div id="my-codepled"></div>

Initialize Player

To initialize the player we need to create an instance of the PlayerUi and provide the selector of our container element. Afterwards we initialize the player instance with our commands (the content) and a title.

<script>
  const commands = ...;
  const player = new Codepled.PlayerUi("#my-codepled");
  player.init(
    commands,
    "Title of My Codepled"
  );
</script>

Structure of the Commands Array

The player takes an array of commands. Each command is itself an array with two elements: [type, payload]. The following commands are supported:

DELETE

Deletes numberOfChars characters from the current cursor position.

Payload:

numberOfChars: number

INSERT

Inserts strToInsert at the current cursor position.

Payload:

strToInsert: string

SKIP

Moves the cursor numberOfChars characters forward.

Payload:

numberOfChars: number

SHOW_TEXT

Payload:

{
  message: string,
  title?: string,
  level?: number = 1,
  toc?: boolean = true,
  pause?: boolean = false
}

Shows message in the text window. If toc is true, it will be shown in the table of contents. If a title is provided, it will be used in the table of contents. If no title is provided, it will generate one, based on the first characters of message. level can be 1 or 2 and defines the level in the table of contents. If pause is set to true the plater will be paused after showing the message.

HIGHLIGHT_LINES

Highlights code lines from start till end starting at index 1;

Payload:

{
  start: number,
  end: number
}

SCROLL_TO

Scrolls to line.

Payload:

line: number

SET_CURSOR

Sets cursor to position.

Payload:

position: number

PAUSE

Pauses the player.

Payload: none

REPLACE_ALL

Replaces the whole content of the code window with newContent.

Payload:

newContent: string

CREATE_DIFF

Creates a set of INSERT, DELETE and SKIP commands that transform source into target.

Payload:

{
  source: string,
  target: string
}

codepled's People

Contributors

annoraaq avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

codepled's Issues

Delete and insert operations lead to animated transformation

To prove technical applicability I want to see an animated replay of several insertions and deletions of code.

AC:

  • Meaningfull sample input (inserts and deletions) is generated
  • the sample input is shown as an animated text transformation with some delay between the steps and a cursor.

highlight deleted lines

And fix bug for insert lines:

When lines are also deleted, the inserted lines highlight algorithm does not work anymore...

highlight added code

Algo idea:
keep all lines touched by insert commands
highlight these lines on a show_text command
reset these lines on a show_text command

Todo:

  • highlight new lines on forwarding
  • highlight lines where smth was deleted

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.