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) ⇒ SlideDown

Ensures that the first slide has proper !SLIDE declaration



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

def initialize(raw)
  @raw = raw =~ /\A!SLIDE/ ? raw : "!SLIDE\n#{raw}"
  extract_classes!
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

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



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

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

#render(name) ⇒ Object



62
63
64
65
66
67
# File 'lib/slidedown.rb', line 62

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



54
55
56
# File 'lib/slidedown.rb', line 54

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