Sha256: fd017ccf8b1931b8f07128a3e2ef4bbe326835d97ae9783d235cd1fffd3e44f2

Contents?: true

Size: 720 Bytes

Versions: 4

Compression:

Stored size: 720 Bytes

Contents

# frozen_string_literal: true

require 'hs/preview/html_preview'

module HS
  module CoursePreview
    include HS::HTMLPreview

    def preview
      html_preview do
        body_element
      end
    end

    def save_preview
      file = "#{HS::Config.preview_dir}/index.html"
      File.open(file, 'w') { |f| f.write(preview) }
    end

    private

    def body_element
      [
        '<body>',
        title_preview,
        toc_preview,
        '</body>'
      ].join("\n")
    end

    def title_preview
      "  <h1 class=\"title\">#{title.strip}</h1>"
    end

    def toc_preview
      [
        '  <ul>',
        chapters.map(&:toc_preview).join("\n"),
        '  </ul>'
      ].join("\n")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hs-cli-0.2.2 lib/hs/preview/course_preview.rb
hs-cli-0.2.1 lib/hs/preview/course_preview.rb
hs-cli-0.2.0 lib/hs/preview/course_preview.rb
hs-cli-0.1.2 lib/hs/preview/course_preview.rb