Skip to content

Fixes missing the default "theme" dir location #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2017

Conversation

budziq
Copy link
Contributor

@budziq budziq commented Jun 6, 2017

if one is not specified in book.toml

fixes https://github.com/azerupi/mdBook/issues/313

@budziq budziq force-pushed the fix_theme branch 3 times, most recently from bb92507 to 3bb7fb1 Compare June 14, 2017 19:56
@azerupi
Copy link
Contributor

azerupi commented Jun 22, 2017

I think this is better fixed directly by giving the HtmlConfig a default value for the theme. What do you think?

@budziq
Copy link
Contributor Author

budziq commented Jun 23, 2017

Yep that's much better idea :)

I have pushed a version with suggested changes which in addition changes HtmlConfig.theme from Option<&PathBuf> to PathBuf as now it is guaranteed to always be set (unfortunately a lot of the code had to be adapted to this change). Otherwise I can submit a super minimal version:

-------------------------- src/config/htmlconfig.rs ---------------------------
index 1c42a34..c90c76b 100644
@@ -25,9 +25,10 @@ impl HtmlConfig {
     /// assert_eq!(config.get_destination(), &output);
     /// ```
     pub fn new<T: Into<PathBuf>>(root: T) -> Self {
+        let root = root.into();
         HtmlConfig {
-            destination: root.into().join("book"),
-            theme: None,
+            destination: root.clone().join("book"),
+            theme: Some(root.join("theme")),
             curly_quotes: false,
             google_analytics: None,
             additional_css: Vec::new(),

edit: Pushed the correct branch now.

if not specified in book.toml
@@ -46,7 +46,7 @@ pub struct Theme {
}

impl Theme {
pub fn new(src: Option<&PathBuf>) -> Self {
pub fn new(src: Option<&Path>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we can remove the option here too, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it but but there is this problem that while in the context of HtmlConfig the theme is guaranteed, it is not in the context of MdBook as the HtmlConfig is optional itself

    pub fn get_theme_path(&self) -> Option<&Path> {
        if let Some(htmlconfig) = self.config.get_html_config() {
            return Some(htmlconfig.get_theme());
        }

        None
    }

So removing this option will make us jump through hoops here:

  --> src/renderer/html_handlebars/hbs_renderer.rs:36:39
   |
36 |         let theme = theme::Theme::new(book.get_theme_path());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, let's keep it like it is for now then. Maybe it will get refactored with all the planned changes anyway.

@azerupi azerupi merged commit d50486e into rust-lang:master Jun 24, 2017
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
Fixes missing the default "theme" dir location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regression on default theme directory handling
2 participants