Skip to content

Commit

Permalink
fix image import
Browse files Browse the repository at this point in the history
  • Loading branch information
Vahegian committed Mar 8, 2022
1 parent aee630f commit 8ea3409
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
11 changes: 7 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ pub static IMAGE_FILE: &str = "logo.png";

// IPFS
pub static IPFS_GATEWAY: &str = "https://ipfs.anspar.io/gateway";
pub static CID_HTML: &str = "QmTPBUwTPgR23NfxzkQt88T5RqLB8VbSeaYT5DkaQPrQ85";
pub static CID_JS: &str = "QmXDpwgw14uJjkkq4yUMNaspSkwPufDvbw6rp4rd7Xq4Qv";
pub static CID_CSS: &str = "QmQKrx745sM1nY7GKMupMPdECu5eNwaxZajZzc5FW4Pmxh";
pub static CID_LOGO: &str = "QmbFhtCDafQg29u9dQgdAdDtGNoHPftN2HibpoDdxMtaX6";
// pub static CID_HTML: &str = "QmYsv4SdxduRwn2KdR3dG2BoqnNhhkYk7BwgASxSZ3pv1Y";
// pub static CID_JS: &str = "QmXDpwgw14uJjkkq4yUMNaspSkwPufDvbw6rp4rd7Xq4Qv";
// pub static CID_CSS: &str = "QmQKrx745sM1nY7GKMupMPdECu5eNwaxZajZzc5FW4Pmxh";
// pub static CID_LOGO: &str = "QmbFhtCDafQg29u9dQgdAdDtGNoHPftN2HibpoDdxMtaX6";
// pub static CID_WASM_BIN: &str = "";
// pub static CID_WASM_JS: &str = "";

// GITHUB
pub static PROJECT_URL: &str = "https://raw.githubusercontent.com/anspar/arag/main";
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use notify::{watcher, RecursiveMode, Watcher};
use opener;
use std::env;
use std::error::Error;
use std::fmt::format;
use std::fs::File;
use std::sync::mpsc::channel;
use std::time::Duration;
Expand Down
8 changes: 4 additions & 4 deletions src/project_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ fn create_folders(r_path: &str, name: &str) -> Result<(), std::io::Error> {
pub fn create_new_project(r_path: &str, name: &str) -> Result<(), Box<dyn Error>> {
create_folders(r_path, name)?;
create_file_from_web(
&format!("{}/{}", constants::IPFS_GATEWAY, constants::CID_HTML),
&format!("{}/{}/{}", constants::PROJECT_URL, constants::TEMPLATE_DIR, constants::ENTRY_TEMPLATE),
&format!("{}/{}/{}", r_path, &name, constants::TEMPLATE_DIR),
constants::ENTRY_TEMPLATE,
)?;

create_file_from_web(
&format!("{}/{}", constants::IPFS_GATEWAY, constants::CID_JS),
&format!("{}/{}/{}/{}", constants::PROJECT_URL, constants::STATIC_DIR, constants::JAVASCRIPT_DIR, constants::JAVASCRIPT_FILE),
&format!(
"{}/{}/{}/{}",
r_path,
Expand All @@ -63,7 +63,7 @@ pub fn create_new_project(r_path: &str, name: &str) -> Result<(), Box<dyn Error>
)?;

create_file_from_web(
&format!("{}/{}", constants::IPFS_GATEWAY, constants::CID_CSS),
&format!("{}/{}/{}/{}", constants::PROJECT_URL, constants::STATIC_DIR, constants::CSS_DIR, constants::CSS_FILE),
&format!(
"{}/{}/{}/{}",
r_path,
Expand All @@ -75,7 +75,7 @@ pub fn create_new_project(r_path: &str, name: &str) -> Result<(), Box<dyn Error>
)?;

create_file_from_web(
&format!("{}/{}", constants::IPFS_GATEWAY, constants::CID_LOGO),
&format!("{}/{}/{}", constants::PROJECT_URL, constants::STATIC_DIR, constants::IMAGE_FILE),
&format!("{}/{}/{}", r_path, &name, constants::STATIC_DIR),
constants::IMAGE_FILE,
)?;
Expand Down
26 changes: 14 additions & 12 deletions src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,20 @@ context_import_helper!(import_bytes_ipfs => |param: String, c: &Context|{
context_import_helper!(
inject_gateway = |c: &Context| {
minifier::js::minify(&format!(
"let IPFS_GATEWAY = {};
document.addEventListener('DOMContentLoaded', function() {{
setInterval(()=>{{
try{{
if(IPFS_GATEWAY_INJECTED){{ IPFS_GATEWAY=IPFS_GATEWAY_INJECTED }}
}}catch(e){{}}
document.querySelectorAll('[ipfs]').forEach((e, i)=>{{
e.setAttribute('src', `${{IPFS_GATEWAY}}/${{e.getAttribute('ipfs')}}`);
e.removeAttribute('ipfs');
}})
}}, 1000)
}});",
"<script>
let IPFS_GATEWAY = {};
document.addEventListener('DOMContentLoaded', function() {{
setInterval(()=>{{
try{{
if(IPFS_GATEWAY_INJECTED){{ IPFS_GATEWAY=IPFS_GATEWAY_INJECTED }}
}}catch(e){{}}
document.querySelectorAll('[ipfs]').forEach((e, i)=>{{
e.setAttribute('src', `${{IPFS_GATEWAY}}/${{e.getAttribute('ipfs')}}`);
e.removeAttribute('ipfs');
}})
}}, 1000)
}});
</script>",
c.data().to_string()
))
}
Expand Down
5 changes: 1 addition & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -21,9 +20,7 @@ <h1>Arag Dapp Builder</h1>
<a target="_blank" href="https://handlebarsjs.com/guide/expressions.html">Handlebars Docs</a>
</div>
</div>
<script>
{{inject_gateway}}
</script>
{{inject_gateway}}
{{import_js "static/js/index.js"}}
</body>
</html>
Expand Down

0 comments on commit 8ea3409

Please sign in to comment.