Class: OrgToSlides::Converter

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

Instance Method Summary collapse

Instance Method Details

#ast_to_reveal_js_structure(ast) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/org2slides.rb', line 104

def ast_to_reveal_js_structure(ast)
  slides = []

  # TODO: run to_html on ruby parser ast first, or can we do it after?

  ast.headlines.each do |h|
    slide_title =  h.body_lines[0].to_s
    slide_body = h.body_lines[1..(h.body_lines.size-1)].map{|l| l.to_s}.join("\n")
    slides << {:title => slide_title, :body => slide_body}
  end

  puts slides
end

#body(orgfile_path) ⇒ Object



8
9
10
# File 'lib/org2slides.rb', line 8

def body(orgfile_path)
  `cat #{orgfile_path}`
end

#convert(orgfile_path) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/org2slides.rb', line 118

def convert(orgfile_path)

  org_body = contents = File.read(orgfile_path)
  ast = Orgmode::Parser.new(org_body)
  slide_markup_body = ast.to_revealjs_html

  title = "" # TODO derive title from filename and|or org contents
  full_body = layout(title, slide_markup_body)

  #puts body

  htmldir_name = orgfile_path.gsub(".org", "")
  gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
  `cp -r #{gem_root_path}/templates/reveal_js_template #{htmldir_name}_generated_slides`
  File.open("#{htmldir_name}_generated_slides/index.html", 'w') { |file| file.write(full_body) }
  return htmldir_name
end

#convert_old(orgfile_path) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/org2slides.rb', line 86

def convert_old(orgfile_path)
  title = "" # TODO derive title from filename and|or org contents
  puts `org2html #{orgfile_path}`
  htmlfile_path = orgfile_path.gsub(".org", ".html")
  htmldir_name = orgfile_path.gsub(".org", "")
  body = body(htmlfile_path)
  body = transform_divs_into_sections(body)
  body = slide_layout(title, body)

  # TODO use path of this file to find dir of template dir where gem is actually located

  gem_root_path = File.expand_path(File.dirname(__FILE__))+"/.."
  `cp -r #{gem_root_path}/templates/reveal_js_template #{htmldir_name}_generated_slides`
  File.open("#{htmldir_name}_generated_slides/index.html", 'w') { |file| file.write(body) }
  `rm #{htmlfile_path}`
  return htmldir_name
end

#layout(title, body) ⇒ Object



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/org2slides.rb', line 16

def layout(title, body)
  <<MARKUP
<!doctype html>
<html lang="en">
  <head>
<meta charset="utf-8">
<title>#{title}</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link href='http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/theme/default.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<script>
  // If the query includes 'print-pdf' we'll use the PDF print sheet
  document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
    <script src="lib/js/html5shiv.js"></script>
<![endif]-->
  </head>
  <body>
<div class="reveal">
  <!-- Used to fade in a background when a specific slide state is reached -->
  <div class="state-background"></div>

  <!-- Any section element inside of this container is displayed as a slide -->
  <div class="slides">

  #{body}

  </div>

  <!-- The navigational controls UI -->
  <aside class="controls">
    <a class="left" href="#">&#x25C4;</a>
    <a class="right" href="#">&#x25BA;</a>
    <a class="up" href="#">&#x25B2;</a>
    <a class="down" href="#">&#x25BC;</a>
  </aside>
  <!-- Presentation progress bar -->
  <div class="progress"><span></span></div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
  // Full list of configuration options available here:
  // https://github.com/hakimel/reveal.js#configuration
  Reveal.initialize({
      controls: true,
      progress: true,
      history: true,
      transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/linear(2d)
      // Optional libraries used to extend on reveal.js
      dependencies: [
          { src: 'lib/js/highlight.js', async: true, callback: function() { window.hljs.initHighlightingOnLoad(); } },
          { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
          { src: 'lib/js/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
          { src: 'lib/js/data-markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
          { src: 'socket.io/socket.io.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
          { src: 'plugin/speakernotes/client.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
      ]
  });
</script>
  </body>
</html>
MARKUP
end

#title(orgfile_path) ⇒ Object



12
13
14
# File 'lib/org2slides.rb', line 12

def title(orgfile_path)
  `cat #{orgfile_path} | grep "#+TITLE:" `.gsub("#+TITLE:", "").strip
end