Skip to content

Commit

Permalink
replace all codeCup with codecup
Browse files Browse the repository at this point in the history
  • Loading branch information
calumk committed Nov 17, 2023
1 parent 6bc1372 commit f8b8982
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 93 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<p align="center">
<img src="assets/logo.png" width="190"><br>
CodeCup: A micro code-editor for awesome web pages.<br>
codecup: A micro code-editor for awesome web pages.<br>
A Fork of <a href="https://github.com/kazzkiq/CodeFlask">CodeFlask</a>
</p>

Expand All @@ -22,7 +22,7 @@ CodeFlask was a brilliant project, but seems to be unmaintained, and it required
* Required (Legacy deps - might rebuild)
* Small theme tweaks (Border, rounded corners.)

* updateded all codeflask references to codeCup - 13/11/2023
* updateded all codeflask references to codecup - 13/11/2023

### Core Changes
> (Submitted as [PR](https://github.com/kazzkiq/CodeFlask/pull/134) to CodeFlask, incase it gets picked up again)
Expand All @@ -35,7 +35,7 @@ CodeFlask was a brilliant project, but seems to be unmaintained, and it required

## Installation

You can install CodeCup via npm:
You can install codecup via npm:

```
npm i @calumk/codecup
Expand All @@ -50,23 +50,23 @@ https://cdn.jsdelivr.net/npm/@calumk/codecup
## Usage

```js
import CodeCup from 'codecup';
import codecup from 'codecup';

const flask = new CodeCup('#my-selector', { language: 'js' });
const flask = new codecup('#my-selector', { language: 'js' });
```
You can also pass a DOM element instead of a selector:
```js
import CodeCup from 'codecup';
import codecup from 'codecup';

const editorElem = document.getElementById('editor');
const flask = new CodeCup(editorElem, { language: 'js' });
const flask = new codecup(editorElem, { language: 'js' });
```
Usage with Shadow DOM:
```js
import CodeCup from 'codecup';
import codecup from 'codecup';
...
const shadowElem = this.shadowRoot.querySelector('#editor');
const flask = new CodeCup(shadowElem, { language: 'js', styleParent: this.shadowRoot });
const flask = new codecup(shadowElem, { language: 'js', styleParent: this.shadowRoot });
```
### Listening for changes in editor

Expand Down Expand Up @@ -94,9 +94,9 @@ const code = cup.getCode();
### Enabling line numbers

```js
import CodeCup from 'codecup';
import codecup from 'codecup';

const cup = new CodeCup('#my-selector', {
const cup = new codecup('#my-selector', {
language: 'js',
lineNumbers: true
});
Expand All @@ -105,9 +105,9 @@ const cup = new CodeCup('#my-selector', {
### Enabling rtl (right to left writing)

```js
import CodeCup from 'codecup';
import codecup from 'codecup';

const cup = new CodeCup('#my-selector', {
const cup = new codecup('#my-selector', {
language: 'js',
rtl: true
});
Expand All @@ -116,9 +116,9 @@ const cup = new CodeCup('#my-selector', {
### Enabling read only mode

```js
import CodeCup from 'codecup';
import codecup from 'codecup';

const cup = new CodeCup('#my-selector', {
const cup = new codecup('#my-selector', {
language: 'js',
readonly: true
});
Expand All @@ -134,9 +134,9 @@ cup.addLanguage('ruby', options)

```js
import Prism from 'prismjs';
import CodeCup from 'codecup';
import codecup from 'codecup';

const cup = new CodeCup('#my-selector', {
const cup = new codecup('#my-selector', {
language: 'ruby',
readonly: true
});
Expand All @@ -146,28 +146,28 @@ cup.addLanguage('ruby', Prism.languages['ruby']);

This API is simply a proxy to add a new language to [Prism](http://prismjs.com/) itself (the code highlighter). The `options` parameter must be the same accepted in Prism. You can read more about it [here](http://prismjs.com/extending.html#language-definitions).

By default, CodeCup supports the following languages (which are also the default supported in Prism):
By default, codecup supports the following languages (which are also the default supported in Prism):

- Markup (HTML/XML);
- CSS;
- C-like;
- JavaScript;

### Adding your own theme to CodeCup
### Adding your own theme to codecup

By default, CodeCup comes with a simple theme made from scratch called **[CodeNoon](https://github.com/kazzkiq/CodeCup.js/blob/master/src/styles/theme-default.js)**.
By default, codecup comes with a simple theme made from scratch called **[CodeNoon](https://github.com/kazzkiq/codecup.js/blob/master/src/styles/theme-default.js)**.

You can easily override this theme with your own by writting your own CSS and adding it to your project. If that's the case, you should also disable **CodeNoon** with the `defaultTheme` option:

```js
import CodeCup from 'codecup';
import codecup from 'codecup';

const cup = new CodeCup('#my-selector', {
const cup = new codecup('#my-selector', {
language: 'js',
defaultTheme: false
});
```

# Credits & Thanks

CodeCup.js was made possible by awesome open-source projects such as [Prism.js](https://github.com/PrismJS/prism) and [Webpack](https://github.com/webpack).
codecup.js was made possible by awesome open-source projects such as [Prism.js](https://github.com/PrismJS/prism) and [Webpack](https://github.com/webpack).
4 changes: 2 additions & 2 deletions dist/codecup.bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script src="../dist/codeCup.bundle.js"></script>
<script src="../dist/codecup.bundle.js"></script>

<div class="container">

Expand Down Expand Up @@ -30,7 +30,7 @@
let current_language = 'javascript'

let change_language = () => {
// ask the user for a language using a simple js alert popup, then update the codeCup language
// ask the user for a language using a simple js alert popup, then update the codecup language
let language = prompt('Enter a language to change to', current_language)
cup.updateLanguage(language)
}
Expand All @@ -52,7 +52,7 @@

let demo_create = () => {
demo_dispose();
cup = new codeCup('#cf_holder', {
cup = new codecup('#cf_holder', {
language: current_language,
lineNumbers: true
});
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@calumk/codecup",
"version": "1.6.1",
"version": "1.6.2",
"description": "A micro code-editor for awesome web pages",
"main": "dist/codeCup.bundle.js",
"main": "dist/codecup.bundle.js",
"files": [
"dist/codeCup.bundle.js",
"dist/codecup.bundle.js",
"README.md",
"LICENSE"
],
Expand All @@ -28,7 +28,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/calumk/codeCup.git"
"url": "git+https://github.com/calumk/codecup.git"
},
"keywords": [
"code-editor",
Expand All @@ -39,7 +39,7 @@
"author": "Calum Knot",
"license": "MIT",
"bugs": {
"url": "https://github.com/calumk/codeCup/issues"
"url": "https://github.com/calumk/codecup/issues"
},
"homepage": "https://github.com/calumk/codeCup"
"homepage": "https://github.com/calumk/codecup"
}
32 changes: 16 additions & 16 deletions src/codecup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import Prism from 'prismjs'
import 'prismjs/plugins/autoloader/prism-autoloader';
Prism.plugins.autoloader.languages_path = 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/';

export default class codeCup {
export default class codecup {
constructor (selectorOrElement, opts) {
if (!selectorOrElement) {
// If no selector or element is passed to codeCup,
// If no selector or element is passed to codecup,
// stop execution and throw error.
throw Error('codeCup expects a parameter which is Element or a String selector')
throw Error('codecup expects a parameter which is Element or a String selector')
}

if (!opts) {
// If no selector or element is passed to codeCup,
// If no selector or element is passed to codecup,
// stop execution and throw error.
throw Error('codeCup expects an object containing options as second parameter')
throw Error('codecup expects an object containing options as second parameter')
}

if (selectorOrElement.nodeType) {
Expand All @@ -43,7 +43,7 @@ export default class codeCup {
const isCSSInjected = injectCss(editorCss, null, this.opts.styleParent)

if (!isCSSInjected) {
throw Error('Failed to inject codeCup CSS.')
throw Error('Failed to inject codecup CSS.')
}

// The order matters (pre > code). Don't change it
Expand All @@ -67,33 +67,33 @@ export default class codeCup {
this.code = this.editorRoot.innerHTML
this.editorRoot.innerHTML = ''
this.elWrapper = this.createElement('div', this.editorRoot)
this.elWrapper.classList.add('codeCup')
this.elWrapper.classList.add('codecup')
}

createTextarea () {
this.elTextarea = this.createElement('textarea', this.elWrapper)
this.elTextarea.classList.add('codeCup__textarea', 'codeCup__flatten')
this.elTextarea.classList.add('codecup__textarea', 'codecup__flatten')
}

createPre () {
this.elPre = this.createElement('pre', this.elWrapper)
this.elPre.classList.add('codeCup__pre', 'codeCup__flatten')
this.elPre.classList.add('codecup__pre', 'codecup__flatten')
}

createCode () {
this.elCode = this.createElement('code', this.elPre)
this.elCode.classList.add('codeCup__code', `language-${this.opts.language || 'html'}`)
this.elCode.classList.add('codecup__code', `language-${this.opts.language || 'html'}`)
}

createLineNumbers () {
this.elLineNumbers = this.createElement('div', this.elWrapper)
this.elLineNumbers.classList.add('codeCup__lines')
this.elWrapper.classList.add('codeCup--has-line-numbers')
this.elLineNumbers.classList.add('codecup__lines')
this.elWrapper.classList.add('codecup--has-line-numbers')
this.setLineNumber()
}

destroyLineNumbers () {
this.elWrapper.classList.remove('codeCup--has-line-numbers')
this.elWrapper.classList.remove('codecup--has-line-numbers')
// console.log(this.elLineNumbers)
this.elLineNumbers.remove()
}
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class codeCup {
}

if (this.opts.lineNumbers) {
// this.elWrapper.classList.add('codeCup--has-line-numbers')
// this.elWrapper.classList.add('codecup--has-line-numbers')
this.createLineNumbers()
}

Expand All @@ -165,7 +165,7 @@ export default class codeCup {
let numberList = ''

for (let i = 1; i <= this.lineNumber; i++) {
numberList = numberList + `<span class="codeCup__lines__line">${i}</span>`
numberList = numberList + `<span class="codecup__lines__line">${i}</span>`
}

this.elLineNumbers.innerHTML = numberList
Expand Down Expand Up @@ -422,7 +422,7 @@ export default class codeCup {
onUpdate (callback) {
// console.log("chanfge")
if (callback && {}.toString.call(callback) !== '[object Function]') {
throw Error('codeCup expects callback of type Function')
throw Error('codecup expects callback of type Function')
}

this.updateCallBack = callback
Expand Down
26 changes: 13 additions & 13 deletions src/styles/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ const LINE_NUMBER_WIDTH = '40px'


export const editorCss = `
.codeCup {
.codecup {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.codeCup, .codeCup * {
.codecup, .codecup * {
box-sizing: border-box;
}
.codeCup__pre {
.codecup__pre {
pointer-events: none;
z-index: 3;
overflow: hidden;
}
.codeCup__textarea {
.codecup__textarea {
background: none;
border: none;
color: ${COLOR};
Expand All @@ -40,17 +40,17 @@ export const editorCss = `
height: 100%;
}
.codeCup--has-line-numbers .codeCup__textarea {
.codecup--has-line-numbers .codecup__textarea {
width: calc(100% - ${LINE_NUMBER_WIDTH});
}
.codeCup__code {
.codecup__code {
display: block;
font-family: ${FONT_FAMILY};
overflow: hidden;
}
.codeCup__flatten {
.codecup__flatten {
padding: 10px;
font-size: ${FONT_SIZE};
line-height: ${LINE_HEIGHT};
Expand All @@ -64,12 +64,12 @@ export const editorCss = `
text-align: left;
}
.codeCup--has-line-numbers .codeCup__flatten {
.codecup--has-line-numbers .codecup__flatten {
width: calc(100% - ${LINE_NUMBER_WIDTH});
left: ${LINE_NUMBER_WIDTH};
}
.codeCup__line-highlight {
.codecup__line-highlight {
position: absolute;
top: 10px;
left: 0;
Expand All @@ -79,7 +79,7 @@ export const editorCss = `
z-index: 1;
}
.codeCup__lines {
.codecup__lines {
padding: 10px 4px;
font-size: 12px;
line-height: ${LINE_HEIGHT};
Expand All @@ -94,15 +94,15 @@ export const editorCss = `
z-index: 2;
}
.codeCup__lines__line {
.codecup__lines__line {
display: block;
}
.codeCup.codeCup--has-line-numbers {
.codecup.codecup--has-line-numbers {
padding-left: ${LINE_NUMBER_WIDTH};
}
.codeCup.codeCup--has-line-numbers:before {
.codecup.codecup--has-line-numbers:before {
content: '';
position: absolute;
left: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/styles/injector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function injectCss (css, styleName, parent) {
const CSS_ID = styleName || 'codeCup-style'
const CSS_ID = styleName || 'codecup-style'
const PARENT = parent || document.head

if (!css) {
Expand Down
Loading

0 comments on commit f8b8982

Please sign in to comment.