Sha256: 45e6b3ac4062cba332b00edfaeaea2ff83399e8ac4e12df9b3c4d2419ac6c561

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

require 'rake'
require 'rake/tasklib'
require 'reveal-ck'

module RevealCK
  # Generate a reveal.js presentation
  class RakeTask < Rake::TaskLib
    include ::Rake::DSL if defined?(::Rake::DSL)

    # Name of task.
    #
    # default:
    #   :reveal
    attr_accessor :name

    # File containing slide content.
    #
    # default:
    #   'slides.*'
    attr_accessor :file

    # Directory where slides are placed.
    #
    # default:
    #   'slides'
    attr_accessor :dir

    attr_accessor :user_dir
    attr_accessor :gem_dir
    attr_accessor :config

    def initialize(*args, &task_block)
      @name     = args.shift || :reveal
      @file     = FileList['slides.*'].first
      @dir      = 'slides'
      @user_dir = Dir.pwd
      @gem_dir  = RevealCK.path
      @config   = Config.new
      yield self if block_given?
      define(args, &task_block)
    end

    # @private
    def run_task(verbose)
      puts "Generating slides for '#{file}'.." if verbose

      slides_builder = RevealCK::Builders::SlidesBuilder.new(
        user_dir:      user_dir,
        gem_dir:       gem_dir,
        output_dir:    dir,
        slides_file:   file,
        config:        config
      )
      slides_builder.prepare
      slides_builder.build
    end

    def define(args, &task_block)
      last_comment = ::Rake.application.last_comment
      desc 'Generate a reveal.js presentation' unless last_comment
      task name, *args do |_, task_args|
        RakeFileUtils.__send__(:verbose, verbose) do
          yield(*[self, task_args].slice(0, task_block.arity)) if task_block
          run_task verbose
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reveal-ck-3.5.0 lib/reveal-ck/rake_task.rb
reveal-ck-3.4.0 lib/reveal-ck/rake_task.rb
reveal-ck-3.3.1 lib/reveal-ck/rake_task.rb