Class: MarkdownSlider

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

Constant Summary collapse

VERSION =
'0.0.3'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MarkdownSlider

Returns a new instance of MarkdownSlider.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/markdown_slider.rb', line 48

def initialize(options = {})

  @version  = MarkdownSlider::VERSION

  @title    = options[:title]    || 'title'
  @template = options[:template] || MarkdownSlider::TEMPLATE
  @style    = options[:style]    || MarkdownSlider::STYLE
  @script   = options[:script]   || MarkdownSlider::SCRIPT

  @parser = Redcarpet::Markdown.new(
    Redcarpet::Render::HTML,
    {
      :tables              => true,
      :fenced_code_blocks  => true,
      :autolink            => true,
      :strikethrough       => true,
      :space_after_headers => true,
    }
  )

end

Instance Attribute Details

#scriptObject (readonly)

Returns the value of attribute script.



10
11
12
# File 'lib/markdown_slider.rb', line 10

def script
  @script
end

#slidesObject (readonly)

Returns the value of attribute slides.



10
11
12
# File 'lib/markdown_slider.rb', line 10

def slides
  @slides
end

#styleObject (readonly)

Returns the value of attribute style.



10
11
12
# File 'lib/markdown_slider.rb', line 10

def style
  @style
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/markdown_slider.rb', line 10

def title
  @title
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/markdown_slider.rb', line 10

def version
  @version
end

Class Method Details

.run(markdown, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/markdown_slider.rb', line 12

def self.run(markdown, options = {})

  raise ArgumentError, "specified source not found: #{markdown}" unless File.exist?(markdown)

  input = File::read(markdown)

  # check options
  if options.has_key?(:template)
    if File.exist?(options[:template])
      options[:template] = File::read(options[:template])
    else
      raise ArgumentError, "specified template not found: #{options[:template]}"
    end
  end

  if options.has_key?(:style)
    if File.exist?(options[:style])
      options[:style] = File::read(options[:style])
    else
      raise ArgumentError, "specified css not found: #{options[:style]}"
    end
  end

  if options.has_key?(:script)
    if File.exist?(options[:script])
      options[:script] = File::read(options[:script])
    else
      raise ArgumentError, "specified script not found: #{options[:script]}"
    end
  end

  MarkdownSlider.new(options).publish(input)

end

Instance Method Details

#publish(input) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/markdown_slider.rb', line 70

def publish(input)

  @slides = split(@parser.render(input))

  ERB.new(@template).result(binding)

end