diff --git a/README.md b/README.md index c3b2d46..9c7ee2a 100644 --- a/README.md +++ b/README.md @@ -53,46 +53,51 @@ To create a new e-book, just run This command creates a directory `mybook` with the following structure: - . - ├── Gemfile - ├── Gemfile.lock - ├── Guardfile - ├── config - │   ├── helper.rb - │   ├── kitabu.yml - │   └── locales - │   └── en.yml - ├── fonts - ├── images - │   ├── cover.png - │   ├── kitabu.svg - │   ├── markdown.svg - │   └── up.svg - ├── templates - │   ├── epub - │   │   ├── cover.erb - │   │   ├── page.erb - │   │   └── toc.erb - │   ├── html - │   │   └── layout.erb - │   └── styles - │   ├── epub.css - │   ├── files - │   │   ├── normalize.css - │   │   ├── notes.css - │   │   └── toc.css - │   ├── html.css - │   ├── pdf.css - │   └── print.css - └── text - ├── 01_Getting_Started.md - ├── 02_Creating_Chapters.md - ├── 03_Syntax_Highlighting.md.erb - ├── 04_Dynamic_Content.md.erb - ├── 05_Exporting_Files.md - └── 06_Changelog.md - - 11 directories, 27 files +``` +. +├── Gemfile +├── Gemfile.lock +├── Guardfile +├── assets +│   ├── fonts +│   ├── images +│   │   ├── cover.png +│   │   ├── kitabu.svg +│   │   ├── markdown.svg +│   │   └── up.svg +│   ├── scripts +│   └── styles +│   ├── epub.css +│   ├── html.css +│   ├── pdf.css +│   ├── print.css +│   └── support +│   ├── kitabu.css +│   ├── normalize.css +│   ├── notes.css +│   └── toc.css +├── config +│   ├── helpers.rb +│   ├── kitabu.yml +│   └── locales +│   └── en.yml +├── templates +│   ├── epub +│   │   ├── cover.erb +│   │   ├── page.erb +│   │   └── toc.erb +│   └── html +│   └── layout.erb +└── text + ├── 01_Getting_Started.md + ├── 02_Creating_Chapters.md + ├── 03_Syntax_Highlighting.md.erb + ├── 04_Dynamic_Content.md.erb + ├── 05_Exporting_Files.md + └── 06_Changelog.md + +13 directories, 28 files +``` The `config/kitabu.yml` file holds some information about your book; so you'll always change it. @@ -193,7 +198,7 @@ be something like this: ``` -You book's helpers can be added to `config/helper.rb`, as this file is loaded +You book's helpers can be added to `config/helpers.rb`, as this file is loaded automatically by kitabu. You can see available helpers on @@ -254,11 +259,12 @@ end ### Using custom fonts -You can use custom fonts for your PDF. Just add them to the `fonts` directory +You can use custom fonts on your ebooks. Just add them to the `fonts` directory (you can create this directory on your book's root directory if it doesn't exist). -Then, on `templates/styles/pdf.css` you can add the `@font-face` declaration. +Then, on `assets/styles/support/fonts.css` you can add the `@font-face` +declaration. ```css @font-face { @@ -275,12 +281,46 @@ Finally, to use this font, do something like this: } ``` +Instead of doing the above manually, you can also use Prince's `--scanfonts` +option. + +```console +$ prince --scanfonts assets/fonts/* > assets/styles/support/fonts.css +``` + +Just remember to replace the generated path to be something like `../../fonts` +instead. + +> [!TIP] +> +> In most cases, it's easier to redefine `sans-serif`, `serif` and `monospace` +> fonts. To know more about how to do this, read Prince's +> [Redefining the generic font families](https://www.princexml.com/doc/styling/#redefining-the-generic-font-families) +> documentation. + +If you're unsure if fonts are actually being used on PDF files, use the +environment variable `PRINCEOPT` to disable system fonts. + +```console +$ PRINCEOPT='--no-system-fonts --debug --log output/prince.log' kitabu export --only pdf +=> e-book couldn't be exported + +$ tail -n10 output/prince.log +Sat Jan 27 18:39:10 2024: debug: font request: Caslon, serif +Sat Jan 27 18:39:10 2024: warning: Ensure fonts are available on the system or load them via a @font-face rule. +Sat Jan 27 18:39:10 2024: warning: For more information see: +Sat Jan 27 18:39:10 2024: warning: https://www.princexml.com/doc/help-install/#missing-glyphs-or-fonts +Sat Jan 27 18:39:10 2024: internal error: Unable to find any available fonts. +Sat Jan 27 18:39:10 2024: finished: failure +Sat Jan 27 18:39:10 2024: ---- end +``` + ### Configuring Markdown Kitabu uses [Redcarpet](https://github.com/vmg/redcarpet) as the Markdown engine. You can override the default processor by setting `Kitabu::Markdown.processor`. This can be done by adding something like the -following to `config/helper.rb`: +following to `config/helpers.rb`: ```ruby Kitabu::Markdown.processor = Redcarpet::Markdown.new( diff --git a/lib/kitabu.rb b/lib/kitabu.rb index da5b3e5..729962a 100644 --- a/lib/kitabu.rb +++ b/lib/kitabu.rb @@ -33,6 +33,7 @@ module Kitabu require "kitabu/version" require "kitabu/generator" require "kitabu/cli" + require "kitabu/css" require "kitabu/markdown" require "kitabu/source_list" require "kitabu/exporter" @@ -41,7 +42,6 @@ module Kitabu require "kitabu/exporter/epub" require "kitabu/exporter/mobi" require "kitabu/exporter/pdf" - require "kitabu/exporter/css" require "kitabu/footnotes/base" require "kitabu/footnotes/html" require "kitabu/footnotes/pdf" diff --git a/lib/kitabu/css.rb b/lib/kitabu/css.rb new file mode 100644 index 0000000..da45913 --- /dev/null +++ b/lib/kitabu/css.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module Kitabu + class CSS + def self.create_file(root_dir:, config:) + buffer = StringIO.new + buffer << accent_color(config:) + buffer << "\n\n" + buffer << syntax_highlight(config:) + buffer << "\n\n" + buffer << translations(config:) + + support_dir = root_dir.join("assets/styles/support") + + FileUtils.mkdir_p(support_dir) + support_dir.join("kitabu.css").open("w") do |file| + file << buffer.tap(&:rewind).read + end + end + + def self.accent_color(config:) + accent_color = config.fetch(:css_accent_color, "#000") + + <<~CSS + :root { + --accent-color: #{accent_color}; + } + CSS + end + + def self.syntax_highlight(config:) + Rouge::Theme.find( + config.fetch(:syntax_highlight_theme, :github) + ).render(scope: ".highlight") + end + + def self.translations(config:) + backend = I18n.backend.translations + + translations = + backend.each_with_object([]) do |(lang, dict), buffer| + buffer << "html[lang='#{lang}'] {" + + dict.each do |key, value| + next unless value.is_a?(String) && value.lines.count == 1 + + buffer << "--#{key.to_s.tr('_', '-')}-text: #{value.inspect};" + end + + buffer << "}\n" + end + + translations.join("\n") + end + end +end diff --git a/lib/kitabu/exporter.rb b/lib/kitabu/exporter.rb index a4cb9cf..e47f6e7 100644 --- a/lib/kitabu/exporter.rb +++ b/lib/kitabu/exporter.rb @@ -19,7 +19,7 @@ def ui end def export! - helper = root_dir.join("config/helper.rb") + helper = root_dir.join("config/helpers.rb") load(helper) if helper.exist? FileUtils.rm_rf root_dir.join("output").to_s diff --git a/lib/kitabu/exporter/base.rb b/lib/kitabu/exporter/base.rb index 976c5ef..fdfdefa 100644 --- a/lib/kitabu/exporter/base.rb +++ b/lib/kitabu/exporter/base.rb @@ -2,6 +2,16 @@ module Kitabu class Exporter + def self.load_translations(root_dir:) + I18n.load_path += Dir[ + File.expand_path(File.join(__dir__, "../../../templates/en.yml")), + root_dir.join("config/locales/**/*.{yml,rb}").to_s + ] + + I18n.backend.reload! + I18n.backend.eager_load! + end + class Base # The e-book directory. # @@ -12,11 +22,7 @@ class Base attr_accessor :source def self.export(root_dir) - I18n.backend.eager_load! - I18n.load_path += Dir[ - root_dir.join("config/locales/**/*.{yml,rb}").to_s - ] - + Exporter.load_translations(root_dir:) new(root_dir).export end diff --git a/lib/kitabu/exporter/css.rb b/lib/kitabu/exporter/css.rb deleted file mode 100644 index 0732606..0000000 --- a/lib/kitabu/exporter/css.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Kitabu - class Exporter - class CSS < Base - attr_reader :root_dir - - def export - super - - FileUtils.cp_r( - root_dir.join("templates/styles").to_s, - root_dir.join("output").to_s - ) - end - end - end -end diff --git a/lib/kitabu/exporter/epub.rb b/lib/kitabu/exporter/epub.rb index 81d2373..2a5163d 100644 --- a/lib/kitabu/exporter/epub.rb +++ b/lib/kitabu/exporter/epub.rb @@ -42,16 +42,23 @@ def html def export super - copy_styles! - copy_images! + copy_assets write_sections! write_cover! write_toc! + ignore_files = [ + tmp_dir.join("assets/styles/html.css"), + tmp_dir.join("assets/styles/print.css"), + tmp_dir.join("assets/styles/pdf.css") + ].map(&:to_s) + epub.files += [tmp_dir.join("cover.html"), tmp_dir.join("toc.html")] epub.files += tmp_dir.glob("**/*").select do |entry| - !epub.files.include?(entry) && entry.file? + !epub.files.include?(entry) && + entry.file? && + !ignore_files.include?(entry.to_s) end epub.save(epub_path) @@ -62,13 +69,8 @@ def export false end - def copy_styles! - copy_files("output/styles/epub.css", "output/epub/styles") - copy_files("output/styles/files/*.css", "output/epub/styles") - end - - def copy_images! - copy_directory("output/images", "output/epub/images") + def copy_assets + copy_directory("output/assets", "output/epub/assets") end def write_toc! diff --git a/lib/kitabu/exporter/html.rb b/lib/kitabu/exporter/html.rb index c3cdefa..f8eefaf 100644 --- a/lib/kitabu/exporter/html.rb +++ b/lib/kitabu/exporter/html.rb @@ -8,9 +8,8 @@ class HTML < Base # def export super - copy_images! - copy_fonts! - export_stylesheets! + copy_assets + export_kitabu_css File.open(root_dir.join("output/#{name}.html"), "w") do |file| file << render_layout @@ -97,22 +96,17 @@ def content buffer.join end - # Copy images + # Copy assets # - private def copy_images! - copy_directory("images", "output/images") + private def copy_assets + copy_directory("assets", "output/assets") end - # Copy font files + # Export css with utilities for syntax highlighting, translations, and + # accent color. # - private def copy_fonts! - copy_directory("fonts", "output/fonts") - end - - # Export all root stylesheets. - # - private def export_stylesheets! - Exporter::CSS.new(root_dir).export + private def export_kitabu_css + CSS.create_file(config:, root_dir:) end end end diff --git a/lib/kitabu/exporter/pdf.rb b/lib/kitabu/exporter/pdf.rb index 9f10d54..969edd6 100644 --- a/lib/kitabu/exporter/pdf.rb +++ b/lib/kitabu/exporter/pdf.rb @@ -7,6 +7,7 @@ def export super apply_footnotes! args = Shellwords.split(ENV.fetch("PRINCEOPT", "")) + args += Array(config[:prince_args]) spawn_command( ["prince", *args, html_for_pdf.to_s, "-o", pdf_file.to_s] @@ -29,7 +30,7 @@ def create_html_file(target, html, class_name) html .css("link[rel=stylesheet]") .first - .set_attribute "href", "styles/#{class_name}.css" + .set_attribute "href", "assets/styles/#{class_name}.css" File.open(target, "w") {|f| f << html.to_html } end diff --git a/lib/kitabu/generator.rb b/lib/kitabu/generator.rb index 01ef9bc..6f4a41a 100644 --- a/lib/kitabu/generator.rb +++ b/lib/kitabu/generator.rb @@ -16,16 +16,12 @@ def self.source_root "#{File.dirname(__FILE__)}/../../templates" end - def copy_templates - directory "templates", "templates" - end - - def copy_sample_texts - directory "text", "text" + def copy_i18n_file + copy_file "en.yml", "config/locales/en.yml" end - def copy_images - directory "images", "images" + def copy_templates + directory "templates", "templates" end def copy_config_file @@ -35,29 +31,34 @@ def copy_config_file template "config.erb", "config/kitabu.yml" end - def copy_i18n_file - copy_file "en.yml", "config/locales/en.yml" + def copy_assets + directory "assets", "assets" + + Exporter.load_translations(root_dir:) + + CSS.create_file( + root_dir:, + config: YAML.load_file(root_dir.join("config/kitabu.yml")) + .with_indifferent_access + ) + end + + def copy_texts + directory "text", "text" end def copy_helper_file - copy_file "helper.rb", "config/helper.rb" + copy_file "helpers.rb", "config/helpers.rb" end def copy_gemfile copy_file "Gemfile" end - def create_directories - empty_directory "output" - empty_directory "fonts" - end - def create_git_files create_file ".gitignore" do "/output" end - - create_file "fonts/.keep" end def copy_guardfile @@ -71,6 +72,12 @@ def bundle_install end no_commands do + # The root directory + # + def root_dir + @root_dir ||= Pathname.new(destination_root) + end + # Retrieve user's name using finger. # Defaults to John Doe. # diff --git a/lib/kitabu/helpers.rb b/lib/kitabu/helpers.rb index 7dadcef..60f003a 100644 --- a/lib/kitabu/helpers.rb +++ b/lib/kitabu/helpers.rb @@ -2,39 +2,14 @@ module Kitabu module Helpers - def css_translations - backend = I18n.backend.translations - - translations = - backend.each_with_object([]) do |(lang, dict), buffer| - buffer << ":root[lang='#{lang}'] {" - - dict.each do |key, value| - next unless value.is_a?(String) && value.lines.count == 1 - - buffer << "--#{key.to_s.tr('_', '-')}-text: #{value.inspect};" - end - - buffer << "}" - end - - translations.join("\n") - end - - def highlight_theme(name = theme) - html = '" - html - end - def image_tag(path, _attributes = {}) - %[] + %[] end def escape_html(content) CGI.escape_html(content.to_s) end + alias h escape_html def note(class_name = :info, &block) content = block_content(block) diff --git a/lib/kitabu/syntax/highlight.rb b/lib/kitabu/syntax/highlight.rb deleted file mode 100644 index 5865191..0000000 --- a/lib/kitabu/syntax/highlight.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Kitabu - class Syntax - class Highlight - def self.apply(code, language) - coderay(code, language) - end - - def self.coderay(code, language) - html = Nokogiri::HTML(CodeRay.scan(code, language).div(css: :class)) - coderay = html.css("div.CodeRay").first - coderay.set_attribute "class", "CodeRay #{language}" - pre = html.css("pre").first - pre.replace Nokogiri.make("
#{pre.inner_html}
") - - coderay.to_xhtml - end - end - end -end diff --git a/spec/kitabu/exporter/css_spec.rb b/spec/kitabu/exporter/css_spec.rb deleted file mode 100644 index 2deb06f..0000000 --- a/spec/kitabu/exporter/css_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -describe Kitabu::Exporter::CSS do - let(:root) { SPECDIR.join("support/mybook") } - - before do - Kitabu::Exporter::CSS.export(root) - end - - it "generates css files" do - expect(root.join("output/styles/epub.css")).to be_file - expect(root.join("output/styles/pdf.css")).to be_file - expect(root.join("output/styles/print.css")).to be_file - expect(root.join("output/styles/html.css")).to be_file - end -end diff --git a/spec/kitabu/exporter/html_spec.rb b/spec/kitabu/exporter/html_spec.rb index 35d9afb..1a2f35d 100644 --- a/spec/kitabu/exporter/html_spec.rb +++ b/spec/kitabu/exporter/html_spec.rb @@ -67,15 +67,15 @@ expect(html).to have_tag("div.note.info > p", "This is a note!") end - it "copies fonts" do - expect(root.join("output/fonts/OpenSans-CondBold.ttf")).to be_file - end - - it "exports css files" do - expect(root.join("output/styles/epub.css")).to be_file - expect(root.join("output/styles/html.css")).to be_file - expect(root.join("output/styles/pdf.css")).to be_file - expect(root.join("output/styles/print.css")).to be_file + it "copies assets" do + expect(root.join("output/assets/images/cover.png")).to be_file + expect(root.join("output/assets/images/logo.gif")).to be_file + expect(root.join("output/assets/fonts/OpenSans-CondBold.ttf")).to be_file + expect(root.join("output/assets/styles/epub.css")).to be_file + expect(root.join("output/assets/styles/html.css")).to be_file + expect(root.join("output/assets/styles/pdf.css")).to be_file + expect(root.join("output/assets/styles/print.css")).to be_file + expect(root.join("output/assets/scripts")).to be_directory end end end diff --git a/spec/kitabu/exporter/pdf_spec.rb b/spec/kitabu/exporter/pdf_spec.rb index bc7b366..ce43c96 100644 --- a/spec/kitabu/exporter/pdf_spec.rb +++ b/spec/kitabu/exporter/pdf_spec.rb @@ -16,12 +16,12 @@ end it "sets stylesheet for print pdf" do - selector = 'link[rel=stylesheet][href="styles/print.css"]' + selector = 'link[rel=stylesheet][href="assets/styles/print.css"]' expect(root.join("output/mybook.print.html").read).to have_tag(selector) end it "sets stylesheet for pdf" do - selector = 'link[rel=stylesheet][href="styles/pdf.css"]' + selector = 'link[rel=stylesheet][href="assets/styles/pdf.css"]' expect(root.join("output/mybook.pdf.html").read).to have_tag(selector) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 86741a7..ac8b268 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,7 +46,10 @@ def bundle_install ) cleaner = proc do - [TMPDIR, SPECDIR.join("support/mybook/output")].each do |i| + [ + TMPDIR + # SPECDIR.join("support/mybook/output") + ].each do |i| FileUtils.rm_rf(i) end diff --git a/spec/support/mybook/assets/fonts/LibertinusSerif-Bold.otf b/spec/support/mybook/assets/fonts/LibertinusSerif-Bold.otf new file mode 100644 index 0000000..60466f4 Binary files /dev/null and b/spec/support/mybook/assets/fonts/LibertinusSerif-Bold.otf differ diff --git a/spec/support/mybook/assets/fonts/LibertinusSerif-BoldItalic.otf b/spec/support/mybook/assets/fonts/LibertinusSerif-BoldItalic.otf new file mode 100644 index 0000000..4d5f11a Binary files /dev/null and b/spec/support/mybook/assets/fonts/LibertinusSerif-BoldItalic.otf differ diff --git a/spec/support/mybook/assets/fonts/LibertinusSerif-Italic.otf b/spec/support/mybook/assets/fonts/LibertinusSerif-Italic.otf new file mode 100644 index 0000000..1851d94 Binary files /dev/null and b/spec/support/mybook/assets/fonts/LibertinusSerif-Italic.otf differ diff --git a/spec/support/mybook/assets/fonts/LibertinusSerif-Regular.otf b/spec/support/mybook/assets/fonts/LibertinusSerif-Regular.otf new file mode 100644 index 0000000..110efd1 Binary files /dev/null and b/spec/support/mybook/assets/fonts/LibertinusSerif-Regular.otf differ diff --git a/spec/support/mybook/assets/fonts/LibertinusSerif-Semibold.otf b/spec/support/mybook/assets/fonts/LibertinusSerif-Semibold.otf new file mode 100644 index 0000000..5281388 Binary files /dev/null and b/spec/support/mybook/assets/fonts/LibertinusSerif-Semibold.otf differ diff --git a/spec/support/mybook/assets/fonts/LibertinusSerif-SemiboldItalic.otf b/spec/support/mybook/assets/fonts/LibertinusSerif-SemiboldItalic.otf new file mode 100644 index 0000000..19f440d Binary files /dev/null and b/spec/support/mybook/assets/fonts/LibertinusSerif-SemiboldItalic.otf differ diff --git a/spec/support/mybook/fonts/OpenSans-CondBold.ttf b/spec/support/mybook/assets/fonts/OpenSans-CondBold.ttf similarity index 100% rename from spec/support/mybook/fonts/OpenSans-CondBold.ttf rename to spec/support/mybook/assets/fonts/OpenSans-CondBold.ttf diff --git a/spec/support/mybook/templates/epub/cover.png b/spec/support/mybook/assets/images/cover.png similarity index 100% rename from spec/support/mybook/templates/epub/cover.png rename to spec/support/mybook/assets/images/cover.png diff --git a/spec/support/mybook/images/logo.gif b/spec/support/mybook/assets/images/logo.gif similarity index 100% rename from spec/support/mybook/images/logo.gif rename to spec/support/mybook/assets/images/logo.gif diff --git a/spec/support/mybook/code/.gitkeep b/spec/support/mybook/assets/scripts/.keep similarity index 100% rename from spec/support/mybook/code/.gitkeep rename to spec/support/mybook/assets/scripts/.keep diff --git a/spec/support/mybook/templates/styles/epub.css b/spec/support/mybook/assets/styles/epub.css similarity index 50% rename from spec/support/mybook/templates/styles/epub.css rename to spec/support/mybook/assets/styles/epub.css index b8013ef..7b6bb9b 100644 --- a/spec/support/mybook/templates/styles/epub.css +++ b/spec/support/mybook/assets/styles/epub.css @@ -1,3 +1,5 @@ +@import "support/kitabu.css"; + .epub { background: yellow; } diff --git a/spec/support/mybook/assets/styles/html.css b/spec/support/mybook/assets/styles/html.css new file mode 100644 index 0000000..5e37ab0 --- /dev/null +++ b/spec/support/mybook/assets/styles/html.css @@ -0,0 +1,5 @@ +@import "support/kitabu.css"; + +.html { + background: red; +} diff --git a/spec/support/mybook/assets/styles/pdf.css b/spec/support/mybook/assets/styles/pdf.css new file mode 100644 index 0000000..2269f10 --- /dev/null +++ b/spec/support/mybook/assets/styles/pdf.css @@ -0,0 +1,15 @@ +@import "support/kitabu.css"; + +.pdf { + background: blue; +} + +h1, +h2 { + font-family: "Open Sans Condensed"; + text-transform: uppercase; +} + +body { + font-family: "Libertinus Serif"; +} diff --git a/spec/support/mybook/templates/styles/print.css b/spec/support/mybook/assets/styles/print.css similarity index 50% rename from spec/support/mybook/templates/styles/print.css rename to spec/support/mybook/assets/styles/print.css index e9fbee0..e012554 100644 --- a/spec/support/mybook/templates/styles/print.css +++ b/spec/support/mybook/assets/styles/print.css @@ -1,3 +1,5 @@ +@import "support/kitabu.css"; + .print { background: green; } diff --git a/spec/support/mybook/assets/styles/support/fonts.css b/spec/support/mybook/assets/styles/support/fonts.css new file mode 100644 index 0000000..b6e214a --- /dev/null +++ b/spec/support/mybook/assets/styles/support/fonts.css @@ -0,0 +1,62 @@ +/* Libertinus Serif, Bold */ +@font-face { + font-family: "Libertinus Serif"; + font-weight: bold; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Bold.otf"); +} + +/* Libertinus Serif, Bold Italic */ +@font-face { + font-family: "Libertinus Serif"; + font-weight: bold; + font-style: italic; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-BoldItalic.otf"); +} + +/* Libertinus Serif, Italic */ +@font-face { + font-family: "Libertinus Serif"; + font-weight: normal; + font-style: italic; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Italic.otf"); +} + +/* Libertinus Serif, Regular */ +@font-face { + font-family: "Libertinus Serif"; + font-weight: normal; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Regular.otf"); +} + +/* Libertinus Serif, Semibold */ +@font-face { + font-family: "Libertinus Serif"; + font-weight: 600; + font-style: normal; + font-stretch: normal; + src: url("assets/fonts/LibertinusSerif-Semibold.otf"); +} + +/* Libertinus Serif, Semibold Italic */ +@font-face { + font-family: "Libertinus Serif"; + font-weight: 600; + font-style: italic; + font-stretch: normal; + src: url("assets/fonts/LibertinusSerif-SemiboldItalic.otf"); +} + +/* Open Sans Condensed, Bold */ +@font-face { + font-family: "Open Sans Condensed"; + font-weight: bold; + font-style: normal; + font-stretch: condensed; + src: url("assets/fonts/OpenSans-CondBold.ttf"); +} diff --git a/spec/support/mybook/assets/styles/support/kitabu.css b/spec/support/mybook/assets/styles/support/kitabu.css new file mode 100644 index 0000000..735b518 --- /dev/null +++ b/spec/support/mybook/assets/styles/support/kitabu.css @@ -0,0 +1,123 @@ +:root { + --accent-color: #5091b1; +} + + +.highlight table td { padding: 5px; } +.highlight table pre { margin: 0; } +.highlight, .highlight .w { + color: #24292f; + background-color: #f6f8fa; +} +.highlight .k, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt, .highlight .kv { + color: #cf222e; +} +.highlight .gr { + color: #f6f8fa; +} +.highlight .gd { + color: #82071e; + background-color: #ffebe9; +} +.highlight .nb { + color: #953800; +} +.highlight .nc { + color: #953800; +} +.highlight .no { + color: #953800; +} +.highlight .nn { + color: #953800; +} +.highlight .sr { + color: #116329; +} +.highlight .na { + color: #116329; +} +.highlight .nt { + color: #116329; +} +.highlight .gi { + color: #116329; + background-color: #dafbe1; +} +.highlight .kc { + color: #0550ae; +} +.highlight .l, .highlight .ld, .highlight .m, .highlight .mb, .highlight .mf, .highlight .mh, .highlight .mi, .highlight .il, .highlight .mo, .highlight .mx { + color: #0550ae; +} +.highlight .sb { + color: #0550ae; +} +.highlight .bp { + color: #0550ae; +} +.highlight .ne { + color: #0550ae; +} +.highlight .nl { + color: #0550ae; +} +.highlight .py { + color: #0550ae; +} +.highlight .nv, .highlight .vc, .highlight .vg, .highlight .vi, .highlight .vm { + color: #0550ae; +} +.highlight .o, .highlight .ow { + color: #0550ae; +} +.highlight .gh { + color: #0550ae; + font-weight: bold; +} +.highlight .gu { + color: #0550ae; + font-weight: bold; +} +.highlight .s, .highlight .sa, .highlight .sc, .highlight .dl, .highlight .sd, .highlight .s2, .highlight .se, .highlight .sh, .highlight .sx, .highlight .s1, .highlight .ss { + color: #0a3069; +} +.highlight .nd { + color: #8250df; +} +.highlight .nf, .highlight .fm { + color: #8250df; +} +.highlight .err { + color: #f6f8fa; + background-color: #82071e; +} +.highlight .c, .highlight .ch, .highlight .cd, .highlight .cm, .highlight .cp, .highlight .cpf, .highlight .c1, .highlight .cs { + color: #6e7781; +} +.highlight .gl { + color: #6e7781; +} +.highlight .gt { + color: #6e7781; +} +.highlight .ni { + color: #24292f; +} +.highlight .si { + color: #24292f; +} +.highlight .ge { + color: #24292f; + font-style: italic; +} +.highlight .gs { + color: #24292f; + font-weight: bold; +} + +html[lang='en'] { +--contents-text: "Contents"; +--left-blank-text: "This page intentionally left blank"; +--chapter-text: "Chapter"; +} diff --git a/spec/support/mybook/text/.gitkeep b/spec/support/mybook/code/.keep similarity index 100% rename from spec/support/mybook/text/.gitkeep rename to spec/support/mybook/code/.keep diff --git a/spec/support/mybook/config/kitabu.yml b/spec/support/mybook/config/kitabu.yml index 3b8ae99..97170d5 100644 --- a/spec/support/mybook/config/kitabu.yml +++ b/spec/support/mybook/config/kitabu.yml @@ -49,8 +49,8 @@ creators: contributors: [] # Syntax highlight theme. Can be any of supported by Rouge. -theme: github +syntax_highlight_theme: github # Accent color. This will be set as a CSS variable, so you can use it on all # CSS files like `color: var(--accent-color)`. -accent_color: "#5091b1" +css_accent_color: "#5091b1" diff --git a/spec/support/mybook/config/locales/en.yml b/spec/support/mybook/config/locales/en.yml index f73757f..e065fa6 100644 --- a/spec/support/mybook/config/locales/en.yml +++ b/spec/support/mybook/config/locales/en.yml @@ -1,3 +1,12 @@ --- en: + contents: Contents + left_blank: This page intentionally left blank chapter: Chapter + + notes: + warning: Warning! + note: Just so you know… + tip: Here’s a tip! + caution: Caution! + important: Important! diff --git a/spec/support/mybook/templates/epub/cover.erb b/spec/support/mybook/templates/epub/cover.erb index a5c3fbe..385b370 100644 --- a/spec/support/mybook/templates/epub/cover.erb +++ b/spec/support/mybook/templates/epub/cover.erb @@ -1,17 +1,28 @@ - - - + + + + + <%= title %> - - - + + -
-

<%= title %>

-
+ <%= image_tag "cover.png" %> diff --git a/spec/support/mybook/templates/epub/page.erb b/spec/support/mybook/templates/epub/page.erb index b9b99f0..ff95148 100644 --- a/spec/support/mybook/templates/epub/page.erb +++ b/spec/support/mybook/templates/epub/page.erb @@ -1,14 +1,13 @@ - - + + - + <%= I18n.t(:contents, default: "Contents") %> - - <%= highlight_theme('github') %> + - +
<%= content %>
diff --git a/spec/support/mybook/templates/epub/toc.erb b/spec/support/mybook/templates/epub/toc.erb index e3bc5e6..c37fb7c 100644 --- a/spec/support/mybook/templates/epub/toc.erb +++ b/spec/support/mybook/templates/epub/toc.erb @@ -1,8 +1,9 @@ + - + <%= I18n.t(:contents) %> diff --git a/spec/support/mybook/templates/html/layout.erb b/spec/support/mybook/templates/html/layout.erb index 042ad2a..d92f879 100644 --- a/spec/support/mybook/templates/html/layout.erb +++ b/spec/support/mybook/templates/html/layout.erb @@ -1,22 +1,13 @@ - + <%= title %> - + - <%= highlight_theme('github') %> - -
@@ -35,7 +26,7 @@
-
+
<%= content %>
diff --git a/spec/support/mybook/templates/styles/html.css b/spec/support/mybook/templates/styles/html.css deleted file mode 100644 index a27fd40..0000000 --- a/spec/support/mybook/templates/styles/html.css +++ /dev/null @@ -1,3 +0,0 @@ -.html { - background: red; -} diff --git a/spec/support/mybook/templates/styles/pdf.css b/spec/support/mybook/templates/styles/pdf.css deleted file mode 100644 index c8e4a2b..0000000 --- a/spec/support/mybook/templates/styles/pdf.css +++ /dev/null @@ -1,3 +0,0 @@ -.pdf { - background: blue; -} diff --git a/spec/support/shared.rb b/spec/support/shared.rb index aa5ad29..f2e2ecc 100644 --- a/spec/support/shared.rb +++ b/spec/support/shared.rb @@ -8,7 +8,7 @@ end it "creates images directory" do - expect(mybook.join("images/cover.png")).to be_file + expect(mybook.join("assets/images/cover.png")).to be_file end it "creates text directory" do @@ -16,7 +16,7 @@ end it "creates fonts directory" do - expect(mybook.join("fonts")).to be_directory + expect(mybook.join("assets/fonts")).to be_directory end it "creates template directory" do @@ -28,7 +28,7 @@ end it "creates helper file" do - expect(mybook.join("config/helper.rb")).to be_file + expect(mybook.join("config/helpers.rb")).to be_file end it "copies sample texts" do @@ -44,11 +44,15 @@ end it "copies stylesheets" do - expect(mybook.join("templates/styles")).to be_directory - expect(mybook.join("templates/styles/epub.css")).to be_file - expect(mybook.join("templates/styles/print.css")).to be_file - expect(mybook.join("templates/styles/pdf.css")).to be_file - expect(mybook.join("templates/styles/html.css")).to be_file + expect(mybook.join("assets/styles")).to be_directory + expect(mybook.join("assets/styles/epub.css")).to be_file + expect(mybook.join("assets/styles/print.css")).to be_file + expect(mybook.join("assets/styles/pdf.css")).to be_file + expect(mybook.join("assets/styles/html.css")).to be_file + end + + it "creates kitabu.css" do + expect(mybook.join("assets/styles/support/kitabu.css")).to be_file end it "copies Gemfile" do @@ -62,5 +66,6 @@ it "copies epub template files" do expect(mybook.join("templates/epub/cover.erb")).to be_file expect(mybook.join("templates/epub/page.erb")).to be_file + expect(mybook.join("templates/epub/toc.erb")).to be_file end end diff --git a/templates/images/.gitkeep b/templates/assets/fonts/.keep similarity index 100% rename from templates/images/.gitkeep rename to templates/assets/fonts/.keep diff --git a/templates/assets/fonts/FiraCode-Bold.ttf b/templates/assets/fonts/FiraCode-Bold.ttf new file mode 100644 index 0000000..f891bde Binary files /dev/null and b/templates/assets/fonts/FiraCode-Bold.ttf differ diff --git a/templates/assets/fonts/FiraCode-Light.ttf b/templates/assets/fonts/FiraCode-Light.ttf new file mode 100644 index 0000000..5664ec3 Binary files /dev/null and b/templates/assets/fonts/FiraCode-Light.ttf differ diff --git a/templates/assets/fonts/FiraCode-Medium.ttf b/templates/assets/fonts/FiraCode-Medium.ttf new file mode 100644 index 0000000..2c0ecdf Binary files /dev/null and b/templates/assets/fonts/FiraCode-Medium.ttf differ diff --git a/templates/assets/fonts/FiraCode-Regular.ttf b/templates/assets/fonts/FiraCode-Regular.ttf new file mode 100644 index 0000000..bd73685 Binary files /dev/null and b/templates/assets/fonts/FiraCode-Regular.ttf differ diff --git a/templates/assets/fonts/FiraCode-Retina.ttf b/templates/assets/fonts/FiraCode-Retina.ttf new file mode 100644 index 0000000..660742d Binary files /dev/null and b/templates/assets/fonts/FiraCode-Retina.ttf differ diff --git a/templates/assets/fonts/FiraCode-SemiBold.ttf b/templates/assets/fonts/FiraCode-SemiBold.ttf new file mode 100644 index 0000000..d8dcef6 Binary files /dev/null and b/templates/assets/fonts/FiraCode-SemiBold.ttf differ diff --git a/templates/assets/fonts/LibertinusSerif-Bold.otf b/templates/assets/fonts/LibertinusSerif-Bold.otf new file mode 100644 index 0000000..60466f4 Binary files /dev/null and b/templates/assets/fonts/LibertinusSerif-Bold.otf differ diff --git a/templates/assets/fonts/LibertinusSerif-BoldItalic.otf b/templates/assets/fonts/LibertinusSerif-BoldItalic.otf new file mode 100644 index 0000000..4d5f11a Binary files /dev/null and b/templates/assets/fonts/LibertinusSerif-BoldItalic.otf differ diff --git a/templates/assets/fonts/LibertinusSerif-Italic.otf b/templates/assets/fonts/LibertinusSerif-Italic.otf new file mode 100644 index 0000000..1851d94 Binary files /dev/null and b/templates/assets/fonts/LibertinusSerif-Italic.otf differ diff --git a/templates/assets/fonts/LibertinusSerif-Regular.otf b/templates/assets/fonts/LibertinusSerif-Regular.otf new file mode 100644 index 0000000..110efd1 Binary files /dev/null and b/templates/assets/fonts/LibertinusSerif-Regular.otf differ diff --git a/templates/assets/fonts/LibertinusSerif-Semibold.otf b/templates/assets/fonts/LibertinusSerif-Semibold.otf new file mode 100644 index 0000000..5281388 Binary files /dev/null and b/templates/assets/fonts/LibertinusSerif-Semibold.otf differ diff --git a/templates/assets/fonts/LibertinusSerif-SemiboldItalic.otf b/templates/assets/fonts/LibertinusSerif-SemiboldItalic.otf new file mode 100644 index 0000000..19f440d Binary files /dev/null and b/templates/assets/fonts/LibertinusSerif-SemiboldItalic.otf differ diff --git a/templates/assets/fonts/OpenSans-Bold.ttf b/templates/assets/fonts/OpenSans-Bold.ttf new file mode 100644 index 0000000..fd79d43 Binary files /dev/null and b/templates/assets/fonts/OpenSans-Bold.ttf differ diff --git a/templates/assets/fonts/OpenSans-BoldItalic.ttf b/templates/assets/fonts/OpenSans-BoldItalic.ttf new file mode 100644 index 0000000..9bc8009 Binary files /dev/null and b/templates/assets/fonts/OpenSans-BoldItalic.ttf differ diff --git a/templates/assets/fonts/OpenSans-CondBold.ttf b/templates/assets/fonts/OpenSans-CondBold.ttf new file mode 100755 index 0000000..83966f2 Binary files /dev/null and b/templates/assets/fonts/OpenSans-CondBold.ttf differ diff --git a/templates/assets/fonts/OpenSans-ExtraBold.ttf b/templates/assets/fonts/OpenSans-ExtraBold.ttf new file mode 100644 index 0000000..21f6f84 Binary files /dev/null and b/templates/assets/fonts/OpenSans-ExtraBold.ttf differ diff --git a/templates/assets/fonts/OpenSans-ExtraBoldItalic.ttf b/templates/assets/fonts/OpenSans-ExtraBoldItalic.ttf new file mode 100644 index 0000000..31cb688 Binary files /dev/null and b/templates/assets/fonts/OpenSans-ExtraBoldItalic.ttf differ diff --git a/templates/assets/fonts/OpenSans-Italic.ttf b/templates/assets/fonts/OpenSans-Italic.ttf new file mode 100644 index 0000000..c90da48 Binary files /dev/null and b/templates/assets/fonts/OpenSans-Italic.ttf differ diff --git a/templates/assets/fonts/OpenSans-Light.ttf b/templates/assets/fonts/OpenSans-Light.ttf new file mode 100644 index 0000000..0d38189 Binary files /dev/null and b/templates/assets/fonts/OpenSans-Light.ttf differ diff --git a/templates/assets/fonts/OpenSans-LightItalic.ttf b/templates/assets/fonts/OpenSans-LightItalic.ttf new file mode 100644 index 0000000..68299c4 Binary files /dev/null and b/templates/assets/fonts/OpenSans-LightItalic.ttf differ diff --git a/templates/assets/fonts/OpenSans-Regular.ttf b/templates/assets/fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000..db43334 Binary files /dev/null and b/templates/assets/fonts/OpenSans-Regular.ttf differ diff --git a/templates/assets/fonts/OpenSans-Semibold.ttf b/templates/assets/fonts/OpenSans-Semibold.ttf new file mode 100644 index 0000000..1a7679e Binary files /dev/null and b/templates/assets/fonts/OpenSans-Semibold.ttf differ diff --git a/templates/assets/fonts/OpenSans-SemiboldItalic.ttf b/templates/assets/fonts/OpenSans-SemiboldItalic.ttf new file mode 100644 index 0000000..59b6d16 Binary files /dev/null and b/templates/assets/fonts/OpenSans-SemiboldItalic.ttf differ diff --git a/templates/assets/images/.keep b/templates/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/templates/images/cover.png b/templates/assets/images/cover.png similarity index 100% rename from templates/images/cover.png rename to templates/assets/images/cover.png diff --git a/templates/images/kitabu.svg b/templates/assets/images/kitabu.svg similarity index 100% rename from templates/images/kitabu.svg rename to templates/assets/images/kitabu.svg diff --git a/templates/images/markdown.svg b/templates/assets/images/markdown.svg similarity index 100% rename from templates/images/markdown.svg rename to templates/assets/images/markdown.svg diff --git a/templates/images/up.svg b/templates/assets/images/up.svg similarity index 100% rename from templates/images/up.svg rename to templates/assets/images/up.svg diff --git a/templates/assets/scripts/.keep b/templates/assets/scripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/templates/assets/styles/epub.css b/templates/assets/styles/epub.css new file mode 100644 index 0000000..eeca71b --- /dev/null +++ b/templates/assets/styles/epub.css @@ -0,0 +1,9 @@ +@import "support/normalize.css"; +@import "support/kitabu.css"; +@import "support/notes.css"; +@import "support/toc.css"; + +pre { + padding: 10px; + font-size: 12px; +} diff --git a/templates/templates/styles/html.css b/templates/assets/styles/html.css similarity index 96% rename from templates/templates/styles/html.css rename to templates/assets/styles/html.css index 42ea6ea..a686d26 100644 --- a/templates/templates/styles/html.css +++ b/templates/assets/styles/html.css @@ -1,6 +1,7 @@ -@import "./files/normalize.css"; -@import "./files/notes.css"; -@import "./files/toc.css"; +@import "support/normalize.css"; +@import "support/kitabu.css"; +@import "support/notes.css"; +@import "support/toc.css"; :root { --cover-color: var(--accent-color); diff --git a/templates/templates/styles/pdf.css b/templates/assets/styles/pdf.css similarity index 85% rename from templates/templates/styles/pdf.css rename to templates/assets/styles/pdf.css index cd7e570..f323d46 100644 --- a/templates/templates/styles/pdf.css +++ b/templates/assets/styles/pdf.css @@ -1,6 +1,8 @@ -@import "./files/normalize.css"; -@import "./files/notes.css"; -@import "./files/toc.css"; +@import "support/fonts.css"; +@import "support/normalize.css"; +@import "support/kitabu.css"; +@import "support/notes.css"; +@import "support/toc.css"; :root { --frontcover-color: var(--accent-color); @@ -67,7 +69,7 @@ } body { - font-family: Caslon, serif; + font-family: serif; font-size: 14px; line-height: 1.5; } @@ -152,24 +154,16 @@ a { content: "By "; } -/* Chapter */ -.sections { - counter-reset: chapter; -} - -.chapter { - page: chapter; - page-break-before: always; - counter-increment: chapter; -} - -.chapter > h2 { - font-family: sans-serif; +/* Section */ +.section > h2, +.section--no-toc > h2 { + text-transform: uppercase; + font-family: "Open Sans Condensed"; + font-size: 40px; + color: #fff; margin: -100px -100px 75px -100px; background: var(--frontcover-color); padding: 100px; - color: #fff; - font-size: 40px; display: flex; flex-direction: column; @@ -179,6 +173,24 @@ a { height: 285px; } +.section--no-toc > h2:before, +.section.changelog { + content: ""; + display: block; + height: 28px; +} + +.sections { + counter-reset: chapter; +} + +/* Chapter */ +.chapter { + page: chapter; + page-break-before: always; + counter-increment: chapter; +} + .chapter > h3 { margin-top: 40px; } @@ -192,10 +204,11 @@ a { } /* Code highlighting */ +.highlight *, p code, li code { font-size: 12px; - font-family: Menlo, monospace; + font-family: monospace; } div.highlight { @@ -208,10 +221,6 @@ div.highlight pre { padding: 0; } -.highlight * { - font-family: Menlo, monospace; -} - .highlight .gutter { color: #aaa; padding-right: 15px; @@ -241,27 +250,6 @@ div.highlight pre { /* Table of contents */ .table-of-contents { page: chapter; - font-family: sans-serif; -} - -.table-of-contents > h2 { - display: flex; - flex-direction: column; - justify-content: center; - font-family: sans-serif; - margin: -100px -100px 75px -100px; - background: var(--frontcover-color); - color: #fff; - font-size: 40px; - padding: 0 100px; - box-sizing: border-box; - height: 285px; -} - -.table-of-contents > h2:before { - content: ""; - display: block; - height: 28px; } /* Footnotes */ diff --git a/templates/assets/styles/print.css b/templates/assets/styles/print.css new file mode 100644 index 0000000..d67ffa8 --- /dev/null +++ b/templates/assets/styles/print.css @@ -0,0 +1 @@ +@import "pdf.css"; diff --git a/templates/assets/styles/support/fonts.css b/templates/assets/styles/support/fonts.css new file mode 100644 index 0000000..e7bb395 --- /dev/null +++ b/templates/assets/styles/support/fonts.css @@ -0,0 +1,206 @@ +/* Fira Code, Bold */ +@font-face { + font-family: monospace; + font-weight: bold; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/FiraCode-Bold.ttf"); +} + +/* Fira Code, Light */ +@font-face { + font-family: monospace; + font-weight: 300; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/FiraCode-Light.ttf"); +} + +/* Fira Code, Medium */ +@font-face { + font-family: monospace; + font-weight: 500; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/FiraCode-Medium.ttf"); +} + +/* Fira Code, Regular */ +@font-face { + font-family: monospace; + font-weight: normal; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/FiraCode-Regular.ttf"); +} + +/* Fira Code, Retina */ +@font-face { + font-family: monospace; + font-weight: 450; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/FiraCode-Retina.ttf"); +} + +/* Fira Code, SemiBold */ +@font-face { + font-family: monospace; + font-weight: 600; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/FiraCode-SemiBold.ttf"); +} + +/* Libertinus Serif, Bold */ +@font-face { + font-family: serif; + font-weight: bold; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Bold.otf"); +} + +/* Libertinus Serif, Bold Italic */ +@font-face { + font-family: serif; + font-weight: bold; + font-style: italic; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-BoldItalic.otf"); +} + +/* Libertinus Serif, Italic */ +@font-face { + font-family: serif; + font-weight: normal; + font-style: italic; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Italic.otf"); +} + +/* Libertinus Serif, Regular */ +@font-face { + font-family: serif; + font-weight: normal; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Regular.otf"); +} + +/* Libertinus Serif, Semibold */ +@font-face { + font-family: serif; + font-weight: 600; + font-style: normal; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-Semibold.otf"); +} + +/* Libertinus Serif, Semibold Italic */ +@font-face { + font-family: serif; + font-weight: 600; + font-style: italic; + font-stretch: normal; + src: url("../../fonts/LibertinusSerif-SemiboldItalic.otf"); +} + +/* Open Sans, Bold */ +@font-face { + font-family: sans-serif; + font-weight: bold; + font-style: normal; + font-stretch: condensed; + src: url("../../fonts/OpenSans-Bold.ttf"); +} + +/* Open Sans, Bold Italic */ +@font-face { + font-family: sans-serif; + font-weight: bold; + font-style: italic; + font-stretch: condensed; + src: url("../../fonts/OpenSans-BoldItalic.ttf"); +} + +/* Open Sans Condensed, Bold */ +@font-face { + font-family: "Open Sans Condensed"; + font-weight: bold; + font-style: normal; + font-stretch: condensed; + src: url("../../fonts/OpenSans-CondBold.ttf"); +} + +/* Open Sans, Extrabold */ +@font-face { + font-family: sans-serif; + font-weight: 800; + font-style: normal; + font-stretch: condensed; + src: url("../../fonts/OpenSans-ExtraBold.ttf"); +} + +/* Open Sans, Extrabold Italic */ +@font-face { + font-family: sans-serif; + font-weight: 800; + font-style: italic; + font-stretch: condensed; + src: url("../../fonts/OpenSans-ExtraBoldItalic.ttf"); +} + +/* Open Sans, Italic */ +@font-face { + font-family: sans-serif; + font-weight: normal; + font-style: italic; + font-stretch: condensed; + src: url("../../fonts/OpenSans-Italic.ttf"); +} + +/* Open Sans, Light */ +@font-face { + font-family: sans-serif; + font-weight: 300; + font-style: normal; + font-stretch: condensed; + src: url("../../fonts/OpenSans-Light.ttf"); +} + +/* Open Sans, Light Italic */ +@font-face { + font-family: sans-serif; + font-weight: 300; + font-style: italic; + font-stretch: condensed; + src: url("../../fonts/OpenSans-LightItalic.ttf"); +} + +/* Open Sans, Regular */ +@font-face { + font-family: sans-serif; + font-weight: normal; + font-style: normal; + font-stretch: condensed; + src: url("../../fonts/OpenSans-Regular.ttf"); +} + +/* Open Sans, Semibold */ +@font-face { + font-family: sans-serif; + font-weight: 600; + font-style: normal; + font-stretch: condensed; + src: url("../../fonts/OpenSans-Semibold.ttf"); +} + +/* Open Sans, Semibold Italic */ +@font-face { + font-family: sans-serif; + font-weight: 600; + font-style: italic; + font-stretch: condensed; + src: url("../../fonts/OpenSans-SemiboldItalic.ttf"); +} diff --git a/templates/templates/styles/files/normalize.css b/templates/assets/styles/support/normalize.css similarity index 100% rename from templates/templates/styles/files/normalize.css rename to templates/assets/styles/support/normalize.css diff --git a/templates/templates/styles/files/notes.css b/templates/assets/styles/support/notes.css similarity index 100% rename from templates/templates/styles/files/notes.css rename to templates/assets/styles/support/notes.css diff --git a/templates/templates/styles/files/toc.css b/templates/assets/styles/support/toc.css similarity index 100% rename from templates/templates/styles/files/toc.css rename to templates/assets/styles/support/toc.css diff --git a/templates/config.erb b/templates/config.erb index b9b5e7b..330dac9 100644 --- a/templates/config.erb +++ b/templates/config.erb @@ -55,8 +55,17 @@ creators: contributors: [] # Syntax highlight theme. Can be any of supported by Rouge. -theme: github +# https://github.com/rouge-ruby/rouge/tree/master/lib/rouge/themes +syntax_highlight_theme: github # Accent color. This will be set as a CSS variable, so you can use it on all # CSS files like `color: var(--accent-color)`. -accent_color: "#0089F0" +css_accent_color: "#0089F0" + +# Set prince arguments that will be used when generating the PDF. +# By default, no system fonts are allowed. Additionally, you may want to execute +# the following command to see which fonts have been embedded: +# +# $ strings output/kitabu.pdf | grep FontName +# +prince_args: [--no-system-fonts, --debug, --log, output/prince.log] diff --git a/templates/helper.rb b/templates/helpers.rb similarity index 100% rename from templates/helper.rb rename to templates/helpers.rb diff --git a/templates/templates/epub/page.erb b/templates/templates/epub/page.erb index 9a49cb2..9bcc889 100644 --- a/templates/templates/epub/page.erb +++ b/templates/templates/epub/page.erb @@ -3,8 +3,7 @@ <%= page_title %> - - <%= highlight_theme %> + diff --git a/templates/templates/epub/toc.erb b/templates/templates/epub/toc.erb index e3bc5e6..af85413 100644 --- a/templates/templates/epub/toc.erb +++ b/templates/templates/epub/toc.erb @@ -2,7 +2,7 @@ - + <%= I18n.t(:contents) %> diff --git a/templates/templates/html/layout.erb b/templates/templates/html/layout.erb index 22c8600..5f37680 100644 --- a/templates/templates/html/layout.erb +++ b/templates/templates/html/layout.erb @@ -3,19 +3,11 @@ <%= title %> - + - <%= highlight_theme %> - @@ -29,7 +21,7 @@
-
+

<%= I18n.t(:contents) %>

<%= toc %> diff --git a/templates/templates/styles/epub.css b/templates/templates/styles/epub.css deleted file mode 100644 index 88a807a..0000000 --- a/templates/templates/styles/epub.css +++ /dev/null @@ -1,8 +0,0 @@ -@import "normalize.css"; -@import "notes.css"; -@import "toc.css"; - -pre { - padding: 10px; - font-size: 12px; -} diff --git a/templates/templates/styles/print.css b/templates/templates/styles/print.css deleted file mode 100644 index 775691f..0000000 --- a/templates/templates/styles/print.css +++ /dev/null @@ -1,2 +0,0 @@ -@import "normalize.css"; -@import "pdf.css"; diff --git a/templates/text/01_Getting_Started.md b/templates/text/01_Getting_Started.md index 23aada1..d803085 100644 --- a/templates/text/01_Getting_Started.md +++ b/templates/text/01_Getting_Started.md @@ -4,7 +4,7 @@ This guide is designed for beginners who want to get started with Kitabu from scratch. Kitabu uses Ruby to generate e-books in different formats by using [Markdown](https://en.wikipedia.org/wiki/Markdown). -![Markdown Logo](images/markdown.svg) +![Markdown Logo](assets/images/markdown.svg) But before doing it so, you need to have some things installed: diff --git a/templates/text/03_Syntax_Highlighting.md.erb b/templates/text/03_Syntax_Highlighting.md.erb index 2229cf1..17a1936 100644 --- a/templates/text/03_Syntax_Highlighting.md.erb +++ b/templates/text/03_Syntax_Highlighting.md.erb @@ -2,7 +2,7 @@ ### What about the syntax -Kitabu uses [Route](http://rubygems.org/gems/rouge) as the syntax highlight +Kitabu uses [Rouge](http://rubygems.org/gems/rouge) as the syntax highlight formatter. It emits an output compatible with stylesheets designed for [pygments](https://pygments.org), the Python library used by many. diff --git a/templates/text/04_Dynamic_Content.md.erb b/templates/text/04_Dynamic_Content.md.erb index e270a32..b784cfb 100644 --- a/templates/text/04_Dynamic_Content.md.erb +++ b/templates/text/04_Dynamic_Content.md.erb @@ -9,7 +9,7 @@ On the previous chapter, we listed all supported Rouge lexers. To do that, I created a helper that looks like this: ```ruby -<%= File.read("./config/helper.rb") %> +<%= File.read("./config/helpers.rb") %> ``` To use it, I just needed to add `<%%= lexers_list %>` to my text file. This diff --git a/templates/text/05_Exporting_Files.md b/templates/text/05_Exporting_Files.md index e3bcfd1..5bf4303 100644 --- a/templates/text/05_Exporting_Files.md +++ b/templates/text/05_Exporting_Files.md @@ -9,34 +9,63 @@ $ kitabu export ``` This command will generate all supported formats[^1]. The generated files will -be placed on your `output` directory; the following output list only the -relevant files. +be placed on your `output` directory. ``` -$ tree output output -├── fonts -├── images -│   ├── cover.png -│   ├── kitabu.svg -│   ├── markdown.svg -│   └── up.svg +├── assets +│   ├── fonts +│   ├── images +│   │   ├── cover.png +│   │   ├── kitabu.svg +│   │   ├── markdown.svg +│   │   └── up.svg +│   ├── scripts +│   └── styles +│   ├── epub.css +│   ├── html.css +│   ├── pdf.css +│   ├── print.css +│   └── support +│   ├── kitabu.css +│   ├── normalize.css +│   ├── notes.css +│   └── toc.css +├── epub +│   ├── assets +│   │   ├── fonts +│   │   ├── images +│   │   │   ├── cover.png +│   │   │   ├── kitabu.svg +│   │   │   ├── markdown.svg +│   │   │   └── up.svg +│   │   ├── scripts +│   │   └── styles +│   │   ├── epub.css +│   │   ├── html.css +│   │   ├── pdf.css +│   │   ├── print.css +│   │   └── support +│   │   ├── kitabu.css +│   │   ├── normalize.css +│   │   ├── notes.css +│   │   └── toc.css +│   ├── cover.html +│   ├── section_0.html +│   ├── section_1.html +│   ├── section_2.html +│   ├── section_3.html +│   ├── section_4.html +│   ├── section_5.html +│   ├── section_6.html +│   └── toc.html ├── sample.epub ├── sample.html ├── sample.mobi ├── sample.pdf ├── sample.pdf.html ├── sample.print.html -├── sample.print.pdf -└── styles - ├── epub.css - ├── files - │   ├── normalize.css - │   ├── notes.css - │   └── toc.css - ├── html.css - ├── pdf.css - └── print.css +└── sample.print.pdf ``` This can take a while depending on your book size, but usually the process is