Add the ability to link to text resource for IDE #328

Merged
Irev-Dev merged 1 commits from kurt/327 into main 2021-05-27 22:59:52 +02:00
Irev-Dev commented 2021-05-27 22:52:10 +02:00 (Migrated from github.com)

Very basic feature, puts the url of the resource in the url for the ide
to fetch when it loads. I haven't added the ability to create these
links as it probably needs some consideration with how it fits into the
IDE.

Should work with any url that returns text but obviously has to CORS
enable since it's in the browser, of which gitlab raw content is not
which is kinda bizzare.

works with github raw content like so:
https://cadhub.xyz/dev-ide/openScad#fetch_text_v1=https://raw.githubusercontent.com/aaevan/openscad_objects/main/fire_tablet_bottom_corner.scad
however I would recommend url encoding it with encodeURIComponent in
case there are special characters in the path
http://cadhub.xyz/dev-ide/openScad#fetch_text_v1=https%3A%2F%2Fraw.githubusercontent.com%2Faaevan%2Fopenscad_objects%2Fmain%2Ffire_tablet_bottom_corner.scad

In the case of github, linking to raw is the safest, however it will try
and get to the raw content from the web-app url i.e. the following still
works:
https://cadhub.xyz/dev-ide/openScad#fetch_text_v1=https://github.com/aaevan/openscad_objects/blob/main/fire_tablet_bottom_corner.scad

Resolves #327

Very basic feature, puts the url of the resource in the url for the ide to fetch when it loads. I haven't added the ability to create these links as it probably needs some consideration with how it fits into the IDE. Should work with any url that returns text but obviously has to CORS enable since it's in the browser, of which gitlab raw content is not which is kinda bizzare. works with github raw content like so: https://cadhub.xyz/dev-ide/openScad#fetch_text_v1=https://raw.githubusercontent.com/aaevan/openscad_objects/main/fire_tablet_bottom_corner.scad however I would recommend url encoding it with `encodeURIComponent` in case there are special characters in the path http://cadhub.xyz/dev-ide/openScad#fetch_text_v1=https%3A%2F%2Fraw.githubusercontent.com%2Faaevan%2Fopenscad_objects%2Fmain%2Ffire_tablet_bottom_corner.scad In the case of github, linking to raw is the safest, however it will try and get to the raw content from the web-app url i.e. the following still works: https://cadhub.xyz/dev-ide/openScad#fetch_text_v1=https://github.com/aaevan/openscad_objects/blob/main/fire_tablet_bottom_corner.scad Resolves #327
Irev-Dev (Migrated from github.com) reviewed 2021-05-27 22:52:52 +02:00
@@ -0,0 +1,21 @@
// import { githubSafe } from './IdeToolbarNew.js'
// TODO jest doesn't like ECMAScript modules and is failing further down in the tree because three ES modules
Irev-Dev (Migrated from github.com) commented 2021-05-27 22:52:52 +02:00

I need to sort out testing :(

I need to sort out testing :(
Irev-Dev (Migrated from github.com) reviewed 2021-05-27 22:54:46 +02:00
@@ -4,3 +4,3 @@
[![Netlify Status](https://api.netlify.com/api/v1/badges/77f37543-e54a-4723-8136-157c0221ec27/deploy-status)](https://app.netlify.com/sites/cadhubxyz/deploys)
<!-- [![Netlify Status](https://api.netlify.com/api/v1/badges/77f37543-e54a-4723-8136-157c0221ec27/deploy-status)](https://app.netlify.com/sites/cadhubxyz/deploys) -->
Irev-Dev (Migrated from github.com) commented 2021-05-27 22:54:46 +02:00

Removing because more than often it displays as failed, when what really happened is build was cancel because there was a change to the docs not the app so the build finished early. Not sure if this can be sorted out or not.

Removing because more than often it displays as failed, when what really happened is build was cancel because there was a change to the docs not the app so the build finished early. Not sure if this can be sorted out or not.
Irev-Dev (Migrated from github.com) reviewed 2021-05-27 22:58:41 +02:00
@@ -8,0 +14,4 @@
.replace('/blob/', '/')
: url
const prepareEncodedUrl = flow(decodeURIComponent, githubSafe)
Irev-Dev (Migrated from github.com) commented 2021-05-27 22:58:41 +02:00

Trying to ease my way into some functional concepts. This is just a helper that makes a function the equivalent of

url => githubSafe(decodeURIComponent(url))

Not really needed in this case with only two functions, but the idea is one of the dis-incentives of making small easy to understand functions is that chaining them is pain to write and read a(b(c(input))) so you just make one abc(input).

Trying to ease my way into some functional concepts. This is just a helper that makes a function the equivalent of ``` url => githubSafe(decodeURIComponent(url)) ``` Not really needed in this case with only two functions, but the idea is one of the dis-incentives of making small easy to understand functions is that chaining them is pain to write and read `a(b(c(input)))` so you just make one `abc(input)`.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: h3n3/cadhub#328