Skip to content

Commit

Permalink
read plugins path from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
daynin committed Mar 28, 2023
1 parent 7d318b1 commit f21fd62
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
4 changes: 3 additions & 1 deletion docs/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ <h1 id="configuration"><a class="header" href="#configuration">Configuration</a>
<code>book_name</code> - a name of the result book.
<code>book_build_dir</code> - a directory that contains the build result.
<a href="https://github.com/daynin/fundoc/blob/master/#L71-L75">[~]</a></p>
<p><code>plugins_dir</code> - path to the plugins directory.
<a href="https://github.com/daynin/fundoc/blob/master/#L81-L83">[~]</a></p>
<p>Fundoc will read all the configuration parameters from the <code>fundoc.json</code> config file
which should be placed into the working directory of the programm's process (generally, it's a root of a
project)
<a href="https://github.com/daynin/fundoc/blob/master/#L83-L87">[~]</a></p>
<a href="https://github.com/daynin/fundoc/blob/master/#L89-L93">[~]</a></p>
<p>You can disable parsing for a part of your file or a whole file by adding this comment: <code>fundoc-disable</code>.
If you wan't to turn fundoc on few lines below just add this comment: <code>fundoc-enable</code>.</p>
<p>In case when you don't write the enable-comment all text from disable comment until the end of
Expand Down
4 changes: 3 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ <h1 id="configuration"><a class="header" href="#configuration">Configuration</a>
<code>book_name</code> - a name of the result book.
<code>book_build_dir</code> - a directory that contains the build result.
<a href="https://github.com/daynin/fundoc/blob/master/#L71-L75">[~]</a></p>
<p><code>plugins_dir</code> - path to the plugins directory.
<a href="https://github.com/daynin/fundoc/blob/master/#L81-L83">[~]</a></p>
<p>Fundoc will read all the configuration parameters from the <code>fundoc.json</code> config file
which should be placed into the working directory of the programm's process (generally, it's a root of a
project)
<a href="https://github.com/daynin/fundoc/blob/master/#L83-L87">[~]</a></p>
<a href="https://github.com/daynin/fundoc/blob/master/#L89-L93">[~]</a></p>
<p>You can disable parsing for a part of your file or a whole file by adding this comment: <code>fundoc-disable</code>.
If you wan't to turn fundoc on few lines below just add this comment: <code>fundoc-enable</code>.</p>
<p>In case when you don't write the enable-comment all text from disable comment until the end of
Expand Down
4 changes: 3 additions & 1 deletion docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ <h1 id="configuration"><a class="header" href="#configuration">Configuration</a>
<code>book_name</code> - a name of the result book.
<code>book_build_dir</code> - a directory that contains the build result.
<a href="https://github.com/daynin/fundoc/blob/master/#L71-L75">[~]</a></p>
<p><code>plugins_dir</code> - path to the plugins directory.
<a href="https://github.com/daynin/fundoc/blob/master/#L81-L83">[~]</a></p>
<p>Fundoc will read all the configuration parameters from the <code>fundoc.json</code> config file
which should be placed into the working directory of the programm's process (generally, it's a root of a
project)
<a href="https://github.com/daynin/fundoc/blob/master/#L83-L87">[~]</a></p>
<a href="https://github.com/daynin/fundoc/blob/master/#L89-L93">[~]</a></p>
<p>You can disable parsing for a part of your file or a whole file by adding this comment: <code>fundoc-disable</code>.
If you wan't to turn fundoc on few lines below just add this comment: <code>fundoc-enable</code>.</p>
<p>In case when you don't write the enable-comment all text from disable comment until the end of
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion fundoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"comment_end_string": null,
"mdbook": true,
"book_name": "Fundoc",
"book_build_dir": "./docs"
"book_build_dir": "./docs",
"plugins_dir": "./plugins"
}
8 changes: 0 additions & 8 deletions plugins/preprocessors/mermaid.html.lua

This file was deleted.

7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub struct Config {
pub mdbook: Option<bool>,
pub book_name: Option<String>,
pub book_build_dir: Option<String>,
/**
* @Article Configuration
*
* `plugins_dir` - path to the plugins directory.
*/
pub plugins_dir: Option<String>,
}

/**
Expand Down Expand Up @@ -178,6 +184,7 @@ pub fn create_default_config() {
comment_start_string: None,
comment_end_string: None,
comment_prefix: None,
plugins_dir: Some(String::from("./plugins")),
})
.unwrap();

Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ fn main() {
if let Some(true) = args.get_one::<bool>("init") {
config::create_default_config()
} else if let Some(true) = args.get_one::<bool>("extension") {
let plugins = plugins::Plugins::new(lua_runtime::LuaRuntime::new());
plugins.run_as_plugin();
match config::read_config(None) {
Some(config) => {
let plugins = plugins::Plugins::new(lua_runtime::LuaRuntime::new(), config);
plugins.run_as_plugin();
},
_ => {},
}
} else {
match config::read_config(None) {
Some(config) => {
Expand Down
12 changes: 9 additions & 3 deletions src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
use regex::Regex;
use std::{env, fs, io, process};

use crate::config;
use crate::lua_runtime;

pub struct Plugins {
lua_runtime: lua_runtime::LuaRuntime,
config: config::Config,
}

impl Plugins {
pub fn new(lua_runtime: lua_runtime::LuaRuntime) -> Self {
Self { lua_runtime }
pub fn new(lua_runtime: lua_runtime::LuaRuntime, config: config::Config) -> Self {
Self { lua_runtime, config }
}

pub fn run_as_plugin(&self) {
let paths = fs::read_dir("./plugins/preprocessors/");
if self.config.plugins_dir.is_none() {
()
}

let paths = fs::read_dir(self.config.plugins_dir.as_ref().unwrap());
let args: Vec<String> = env::args().collect();

if args.len() > 3 {
Expand Down

0 comments on commit f21fd62

Please sign in to comment.