-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
202 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,52 @@ | ||
pub mod prelude; | ||
use std::{path::PathBuf, str::FromStr}; | ||
pub mod module_generator; | ||
pub use module_generator::*; | ||
|
||
use ligen_ir::{Module, Library}; | ||
use std::path::PathBuf; | ||
|
||
use ligen_ir::Library; | ||
use prelude::*; | ||
|
||
use ligen_generator::{file_generator::{TemplateRegister, Template, TemplateBasedGenerator}, register_templates}; | ||
use ligen_generator::file_generator::{FileGenerator, FileSet, Template}; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct RustImporter {} | ||
pub struct LibraryGenerator {} | ||
|
||
impl TemplateRegister for RustImporter { | ||
fn register_templates(&self, template: &mut Template) -> Result<()> { | ||
register_templates!(template, module); | ||
// register_templates!(template, identifier, arguments, implementation, method, function, module, object, parameters, library); | ||
impl LibraryGenerator { | ||
pub fn generate_project_file(&self, library: &Library, file_set: &mut FileSet) -> Result<()> { | ||
let file = file_set.entry(PathBuf::from("Cargo.toml")); | ||
let mut template = Template::new(); | ||
template.register_template("project", include_str!("templates/Cargo.hbs"))?; | ||
let template = template.render("project", &library)?; | ||
let root = file.section("root"); | ||
root.write(template); | ||
Ok(()) | ||
} | ||
|
||
pub fn generate_lib_file(&self, library: &Library, file_set: &mut FileSet) -> Result<()> { | ||
let file = file_set.entry(PathBuf::from("src").join("lib.rs")); | ||
let section = file.section("documentation"); | ||
section.writeln(library.metadata.description.split("\n").map(|s| format!("//! {}", s)).collect::<Vec<String>>().join("\n")); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl TemplateBasedGenerator for RustImporter { | ||
fn register_functions(&self, _library: &Library, _template: &mut Template) { | ||
//register_functions!(template, mapped_type, marshal_output); | ||
pub fn generate_readme(&self, library: &Library, file_set: &mut FileSet) -> Result<()> { | ||
let file = file_set.entry(PathBuf::from("README.md")); | ||
let root = file.section("root"); | ||
root.write(&library.metadata.description); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl FileGenerator for LibraryGenerator { | ||
type Input = Library; | ||
fn base_path(&self) -> PathBuf { | ||
PathBuf::from("python".to_string()) | ||
PathBuf::from("rust".to_string()) | ||
} | ||
|
||
fn module_generation_path(&self, library: &Library, module: &Module) -> PathBuf { | ||
let is_root_module = library.root_module == *module; | ||
let name = if is_root_module { "lib.rs" } else { "mod.rs" }; | ||
let mut path = PathBuf::from_str("src").unwrap(); | ||
path = path.join(PathBuf::from(module.identifier.name.clone())); | ||
path = path.join(name); | ||
path | ||
fn generate_files(&self, library: &Library, file_set: &mut FileSet) -> Result<()> { | ||
self.generate_project_file(library, file_set)?; | ||
self.generate_lib_file(library, file_set)?; | ||
Ok(()) | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "{{identifier.name}}" | ||
version = "{{metadata.version}}" | ||
edition = "2021" | ||
description = "{{metadata.summary}}" | ||
license = "{{metadata.license}}" | ||
homepage = "{{metadata.homepage}}" | ||
authors = [{{#each metadata.authors}}"{{name}} <{{email}}>"{{#unless @last}}, {{/unless}}{{/each}}] | ||
keywords = [{{#each metadata.keywords}}"{{this}}"{{#unless @last}}, {{/unless}}{{/each}}] | ||
readme = "README.md" |
129 changes: 0 additions & 129 deletions
129
ecosystem/rust/importer/src/templates/ligen/python/instagrapi/src
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.