Class: SlideDown

Inherits:
Object
  • Object
show all
Defined in:
lib/slidedown.rb

Constant Summary collapse

USAGE =
"The SlideDown command line interface takes a .md (Markdown) file as its only required argument. It will convert the file to HTML in standard out. Options:
-t, --template [TEMPLATE] the .erb files in /templates directory. Default is -t default, which prints stylesheets and javascripts inline. The import template uses link and script tags."

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, opts = {}) ⇒ SlideDown

Ensures that the first slide has proper !SLIDE declaration



49
50
51
52
53
54
55
# File 'lib/slidedown.rb', line 49

def initialize(raw, opts = {})
  @raw = raw =~ /\A!SLIDE/ ? raw : "!SLIDE\n#{raw}"
  extract_classes!

  self.stylesheets = opts[:stylesheets] || local_stylesheets
  self.title =       opts[:title]       || "Slides"
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



15
16
17
# File 'lib/slidedown.rb', line 15

def classes
  @classes
end

#stylesheetsObject

Returns the value of attribute stylesheets.



14
15
16
# File 'lib/slidedown.rb', line 14

def stylesheets
  @stylesheets
end

#titleObject

Returns the value of attribute title.



14
15
16
# File 'lib/slidedown.rb', line 14

def title
  @title
end

Class Method Details

.option_parser(source) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/slidedown.rb', line 32

def self.option_parser(source)
  OptionParser.new do |opts|
    opts.on('-h', '--help') { puts USAGE }
    opts.on('-t', '--template TEMPLATE') do |template|
      render(source, template)
    end
  end
end

.render(source_path, template = "default") ⇒ Object



41
42
43
44
45
46
# File 'lib/slidedown.rb', line 41

def self.render(source_path, template = "default")
  if source_path
    slideshow = new(File.read(source_path))
    puts slideshow.render(template)
  end
end

.run!(argv = ARGV) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/slidedown.rb', line 17

def self.run!(argv = ARGV)
  args = argv.dup

  if args.empty?
    puts USAGE
  else
    source = args[0]
    if args.length == 1
      render(source)
    else
      option_parser(source).parse!(args)
    end
  end
end

Instance Method Details

#read(path) ⇒ Object



61
62
63
# File 'lib/slidedown.rb', line 61

def read(path)
  File.read(File.join(File.dirname(__FILE__), '..', "templates", path))
end

#render(name) ⇒ Object



65
66
67
68
69
70
# File 'lib/slidedown.rb', line 65

def render(name)
  directory = File.join(File.dirname(__FILE__), "..", "templates")
  path      = File.join(directory, "#{name}.erb")
  template  = File.read(path)
  ERB.new(template).result(binding)
end

#slidesObject



57
58
59
# File 'lib/slidedown.rb', line 57

def slides
  @slides ||= lines.map { |text| Slide.new(text, *@classes.shift) }
end