Sha256: d42f1331fc399eb73cda31a0ecc6645bc1a9cdac57c54ea9e4f7c142ce626571

Contents?: true

Size: 1.87 KB

Versions: 11

Compression:

Stored size: 1.87 KB

Contents

require 'html/pipeline'
require 'html/pipeline/reveal_ck_emoji_filter'

module RevealCK
  module Builders
    # Given a slides_file, a Rake application, and a place where the
    # transformed slides file should end up, this class knows how to
    # work with Rake and create the slides.html.
    class CreateSlidesHtml < CreationTask
      attr_reader :slides_file, :output_dir, :config

      def initialize(args)
        @slides_file = retrieve(:slides_file, args)
        @output_dir = retrieve(:output_dir, args)
        @config = retrieve(:config, args)
        super
      end

      def setup
        slides_html_file = "#{output_dir}/slides.html"
        task(slides_html_file) do
          File.open(slides_html_file, 'w') do |slides_html|
            slides_html.puts(presentation_html)
          end
        end
        things_to_create.add(slides_html_file)
      end

      private

      def presentation_html
        presentation = RevealCK::Presentation.load(file: slides_file,
                                                   config: config)
        initial_html = presentation.html
        apply_filters_to(initial_html)
      end

      def apply_filters_to(html)
        load_dependencies(config.requires)
        filters = get_classes_from_array(config.filters)
        pipeline = HTML::Pipeline.new(filters)
        filtered_html_string = FilteredHtmlString.new(html: html,
                                                      config: config.to_h,
                                                      pipeline: pipeline)
        filtered_html_string.render
      end

      def load_dependencies(array_of_includes)
        array_of_includes.each { |name| require name }
      end

      def get_classes_from_array(array_of_names)
        array_of_names.map do |name|
          name.split('::').reduce(Object) { |acc, elem| acc.const_get(elem) }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reveal-ck-4.0.0 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.9.2 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.9.1 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.9.0 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.8.1 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.8.0 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.7.0 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.6.0 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.5.1 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.5.0 lib/reveal-ck/builders/create_slides_html.rb
reveal-ck-3.4.0 lib/reveal-ck/builders/create_slides_html.rb