diff --git a/extension/package.json b/extension/package.json index 0a3d50b67..c492f97e2 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1,7 +1,7 @@ { "name": "dioxusstudio", - "displayName": "dioxusStudio", - "description": "Toolkit for IDE support in Dioxus apps", + "displayName": "Dioxus", + "description": "Useful tools for working with Dioxus", "version": "0.0.1", "publisher": "jkelleyrtp", "private": true, diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 5a41c7f5f..4322c48e1 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -2,6 +2,7 @@ import * as vscode from 'vscode'; import { spawn } from "child_process"; export function activate(context: vscode.ExtensionContext) { + function registerCommand(cmd: string) { function convert(cmd: string) { const editor = vscode.window.activeTextEditor;// Get the active text editor @@ -10,7 +11,7 @@ export function activate(context: vscode.ExtensionContext) { if (html.length > 0) { let params = ["translate"]; if (cmd.includes("Component")) params.push("--component"); - params.push("--source"); + params.push("--raw"); params.push(html); const child_proc = spawn("dioxus", params); let result = ''; @@ -23,6 +24,8 @@ export function activate(context: vscode.ExtensionContext) { } } } + + const handle = vscode.commands.registerCommand(cmd, () => convert(cmd)); context.subscriptions.push(handle); } diff --git a/src/cli/translate/mod.rs b/src/cli/translate/mod.rs index e239ce318..3440ee6b1 100644 --- a/src/cli/translate/mod.rs +++ b/src/cli/translate/mod.rs @@ -13,6 +13,10 @@ pub struct Translate { #[clap(short, long)] pub file: Option, + /// Input file + #[clap(short, long)] + pub raw: Option, + /// Output file, stdout if not present #[clap(parse(from_os_str))] pub output: Option, @@ -24,14 +28,20 @@ impl Translate { component, output, file, + raw, } = self; - let contents = match file { - Some(input) => std::fs::read_to_string(&input).unwrap_or_else(|e| { + let contents = match (file, raw) { + (Some(input), None) => std::fs::read_to_string(&input).unwrap_or_else(|e| { log::error!("Cloud not read input file: {}.", e); exit(0); }), - None => { + (None, Some(raw)) => raw, + (Some(_), Some(_)) => { + log::error!("Only one of --file or --raw can be specified."); + exit(0); + } + (None, None) => { if atty::is(atty::Stream::Stdin) { log::error!("No input file, source, or stdin to translate from."); exit(0); @@ -67,7 +77,11 @@ impl Translate { } /// render without handling svgs or anything -fn simple_render_child(f: &mut impl std::fmt::Write, child: &Node, il: u32) -> std::fmt::Result { +pub fn simple_render_child( + f: &mut impl std::fmt::Write, + child: &Node, + il: u32, +) -> std::fmt::Result { write_tabs(f, il)?; match child { Node::Text(t) => writeln!(f, "\"{}\"", t)?, diff --git a/tests/test.html b/tests/test.html index 4936ae36a..05ccd7b18 100644 --- a/tests/test.html +++ b/tests/test.html @@ -1,32 +1,48 @@
-
-
-
-
- content -
-

Buy YouTube Videos

-

- Williamsburg occupy sustainable snackwave gochujang. Pinterest cornhole brunch, slow-carb neutra - irony. -

- -
-
-
- content -
-

The Catalyzer

-

- Williamsburg occupy sustainable snackwave gochujang. Pinterest - cornhole brunch, slow-carb neutra irony. -

- -
+
+
+
+
+ content
+

+ Buy YouTube Videos +

+

+ Williamsburg occupy sustainable snackwave gochujang. Pinterest + cornhole brunch, slow-carb neutra irony. +

+ +
+
+
+ content +
+

+ The Catalyzer +

+

+ Williamsburg occupy sustainable snackwave gochujang. Pinterest + cornhole brunch, slow-carb neutra irony. +

+ +
+