Sha256: d86eef4c984de4108db91065956eecaa4c46470cbb0f1072e725ca2a385ca7c1

Contents?: true

Size: 1.76 KB

Versions: 11

Compression:

Stored size: 1.76 KB

Contents

module RevealCK
  #
  # Public: A PresentationDSL defines the DSL behind a
  # presentation. It also knows how to load file containing the DSL.
  #
  class PresentationDSL
    include Retrieve
    attr_reader :author, :title, :theme, :transition
    attr_reader :config

    def initialize(args)
      @slides = []
      @config = retrieve(:config, args)
    end

    # Rubocop doesn't like trivial accessors, but docile breaks if
    # trivial accessors are used.
    # rubocop:disable TrivialAccessors
    def theme(theme)
      config.theme = theme
    end

    def transition(transition)
      config.transition = transition
    end

    def title(title)
      config.title = title
    end

    def author(author)
      config.author = author
    end
    # rubocop:enable TrivialAccessors

    def revealjs_config(key, value)
      config.revealjs_config[key] = value
    end

    def slide(template, variables = {})
      variables[:template] = template
      variables[:config] = @config
      @slides << RevealCK::Slide.new(variables)
    end

    def contents_of(path)
      File.open(path).read
    end

    def build
      presentation = RevealCK::Presentation.new config: config
      presentation.theme = @theme if @theme
      presentation.transition = @transition if @transition
      presentation.author = @author if @author
      presentation.title = @title if @title
      @slides.each { |slide| presentation.add slide }
      presentation
    end

    require 'docile'

    def presentation(&block)
      Docile.dsl_eval(self, &block).build
    end

    def self.load(args)
      file, config = retrieve(:file, args), retrieve(:config, args)
      builder = PresentationDSL.new config: config
      contents = File.open(file).read
      builder.instance_eval(contents)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
reveal-ck-3.0.1 lib/reveal-ck/presentation_dsl.rb
reveal-ck-3.0.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.6.2 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.6.1 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.6.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.5.1 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.5.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.4.2 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.4.1 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.4.0 lib/reveal-ck/presentation_dsl.rb
reveal-ck-0.3.0 lib/reveal-ck/presentation_dsl.rb