Class: Mdslide::Creator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCreator

Returns a new instance of Creator.



12
13
14
15
16
17
18
19
20
21
# File 'lib/mdslide/creator.rb', line 12

def initialize
  @stylesheets = ['base.css']
  @scripts = ['jquery.min.js','slides.js']
  @theme_scripts     = []
  @theme_stylesheets = []

  @page_template = File.open(File.dirname(__FILE__)  + '/../../templates/page.html.erb','r'){|r| erb = ERB.new(r.read)}
  @slide_template = File.open(File.dirname(__FILE__) + '/../../templates/slide.html.erb','r'){|r| erb = ERB.new(r.read)}
  @title = 'Slides converted by Mdslide'
end

Instance Attribute Details

#scriptsObject (readonly)

Returns the value of attribute scripts.



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

def scripts
  @scripts
end

#stylesheetsObject (readonly)

Returns the value of attribute stylesheets.



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

def stylesheets
  @stylesheets
end

#theme_scriptsObject (readonly)

Returns the value of attribute theme_scripts.



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

def theme_scripts
  @theme_scripts
end

#theme_stylesheetsObject (readonly)

Returns the value of attribute theme_stylesheets.



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

def theme_stylesheets
  @theme_stylesheets
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/mdslide/creator.rb', line 11

def title
  @title
end

Instance Method Details

#convert_markdown(md) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mdslide/creator.rb', line 36

def convert_markdown md
  body = ''
  md.toutf8.gsub(/\r\n?/, "\n").split(/^\/\/+$/).map do |slide|
    if slide =~ /(^|\s)(https?:\/\/[^\s]+)($|\s)/
      slide.gsub!(/(^|\s)(https?:\/\/[^\s]+)($|\s)/){"#{$1}[#{$2}](#{$2})#{$3}"}
    end
    if slide =~ /(^|\s)@([a-zA-Z0-9_]+)($|\s)/
      slide.gsub!(/(^|\s)@([a-zA-Z0-9_]+)($|\s)/, "#{$1}[@#{$2}](https://twitter.com/#{$2})#{$3}")
    end
    body += @slide_template.result(self.get_binding{Kramdown::Document.new(slide).to_html})
  end
  @page_template.result(self.get_binding{body})
end

#get_bindingObject



32
33
34
# File 'lib/mdslide/creator.rb', line 32

def get_binding
  binding
end

#set_theme(name) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/mdslide/creator.rb', line 23

def set_theme name
  theme = Themes[name.to_sym]
  if theme
    theme[:css] && @theme_stylesheets.replace(theme[:css])
    theme[:js]  && @theme_scripts.replace(theme[:js])
  end
  return theme
end