Sha256: adf3d870e85220c959ca5ab9f3aa1f1629e020dbc2db44e53b2d21847fee5b12

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

module Rpub
  module Commands
    class Preview < Base
      include CompilationHelpers

      identifier 'preview'

      def initialize(*args)
        super
        @filename = 'preview.html'
      end

      def invoke
        super
        return unless markdown_files.any?
        File.open(@filename, 'w') do |f|
          f.write move_styles_inline(Typogruby.improve(concatenated_document.to_html))
        end
      end

    private

      def move_styles_inline(html)
        style_block = %Q{<style>\n#{File.read(styles)}\n</style>}
        html.gsub %r{</head>}, style_block + "\n</head>"
      end

      def parser
        OptionParser.new do |opts|
          opts.banner = <<-EOS
Usage: rpub preview [options]

Generate a single-page HTML file for easy previewing of your content with the
layout and styles used when generating .epub files. By default, the output
file will be named "preview.html".

Options:
EOS
          opts.separator ''
          opts.on '-l', '--layout FILENAME', 'Specify an explicit layout file to use' do |filename|
            @layout = filename
          end

          opts.on '-o', '--output FILENAME', 'Specify an explicit output file' do |filename|
            @filename = filename
          end

          opts.separator ''
          opts.separator 'Generic options:'
          opts.separator ''

          opts.on_tail '-h', '--help', 'Display this message' do
            puts opts
            exit
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rpub-0.4.0 lib/rpub/commands/preview.rb
rpub-0.3.0 lib/rpub/commands/preview.rb