capsctrldays

2008-01-16 (水) [長年日記]

S5をHikiDoc記法でやってみるよ

プレゼン資料をHiki記法で書いといて、 サーバに上げといて、 ブラウザで見れるといいよねー、 みたいな。 Hikiにこういう機能があってもいいんだけども。

RubyでCGI作ったことないので、話半分に聞いてください。

手順

  • S5 blank template archiveをダウンロードして解凍する
  • s5-blank.html を以下と置き換える。単なるガワの部分なので、好きなように変更しても可。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>[slide show title here]</title>
<!-- metadata -->
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
<meta name="generator" content="S5" />
<meta name="version" content="S5 1.1" />
<meta name="author" content="<%= @author %>" />
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
<!-- style sheet links -->
<link rel="stylesheet" href="ui/default/slides.css" type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="ui/default/print.css" type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
<!-- S5 JS -->
<script src="ui/default/slides.js" type="text/javascript"></script>
</head>
<body>

<div class="layout">
<div id="controls"><!-- DO NOT EDIT --></div>
<div id="currentSlide"><!-- DO NOT EDIT --></div>
<div id="header"></div>
<div id="footer">
<h1><%= @location %>/<%= @date %></h1>
<h2><%= @title %></h2>
</div>
</div>

<div class="presentation">
<%= @slides %>
</div>

</body>
</html>
  • hikidoc.rbをダウンロードする
  • 以下のcgiスクリプトを設置する
#!/usr/bin/env ruby
require 'cgi'
require 'hikidoc'
require 'erb'

# re-define for s5
class HikiDoc::HTMLOutput
  def hrule
    @f.puts %Q|</div>\n\n<div class="slide">|
  end
end

# make html of slides
@slides = %Q|<div class="slide">\n|
fname = File.basename(CGI.new.params["name"].to_s.chomp)
fpath = "./data/" + fname
unless File.exist? fpath
  print "Content-type: text/html\n\n"
  print "File Not Found"
  exit # FIXME: need more effective error handling
end
@slides += HikiDoc.to_xhtml(ERB.new(File.open(fpath).read).result)
@slides += '</div>'

# make html of body
erb = ERB.new File.open("s5-blank.html").read

# output
print "Content-type: text/html\n\n"
erb.run
  • プレゼン用の原稿ファイルを置く(たとえば data/test.txt )。これがHiki記法ね。最初のは設定用のパラメータ。
<%
@author = 'author'
@title = 'title'
@date = '2008-1-16'
@location = 'hoge'
%>

! S5: An Introduction
* [[link|http://www.google.com]]

----

! 2ページ目
# one
# two
# three

----

! 3ページ目
""またお前か

ページを区切るには「----」を使ってください。

あとは、

http://example.com/s5.cgi?name=test.txt

でアクセス。

サンプル

追記

あーそっか。ファイルじゃなくてHikiのページをURLで指定できるようにすればいいのか。あとでやる。

設定ファイルはどうしよ。コメント部分にするかなあ。

[Hiki] keynote.rb

なんとなくプラグイン化。こっちはH1でページ区切り。

S5以外にも対応できるようにあとで管理画面作る。

それと、plugin記法のパースをしないと。これはどこでやるんだろう。対応した。

# keynote.rb
def keynote
  @p = @params['p'][0]

  # error
  unless @db.exist? @p
    redirect @cgi, @conf.index_url #FIXME
  end

  # get contents
  parser = @conf.parser::new( @conf)
  tokens = parser.parse( load(@p), 1 )
  formatter = @conf.formatter::new( tokens, @db, self, @conf )
  contents, toc = formatter.to_s, formatter.toc

  # format html for s5
  body = ""
  first_h1 = true
  contents.each_line do |l|
    if /\A<h1>.*<\/h1>\Z/ =~ l
      if first_h1
        first_h1 = false
        body += %Q|<div class="slide">\n|
      else
        body += %Q|</div>\n\n<div class="slide">\n|
      end
    end
    body += l
  end
  body += "</div>"

  # output
  print @cgi.header
  print <<EOS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>#{@p}</title>
<!-- metadata -->
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
<meta name="generator" content="S5" />
<meta name="version" content="S5 1.1" />
<meta name="author" content="#{@conf.author_name}" />
<!-- configuration parameters -->
<meta name="defaultView" content="slideshow" />
<meta name="controlVis" content="hidden" />
<!-- style sheet links -->
<link rel="stylesheet" href="s5/ui/default/slides.css" type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="s5/ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="s5/ui/default/print.css" type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="s5/ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
<!-- S5 JS -->
<script src="s5/ui/default/slides.js" type="text/javascript"></script>
</head>
<body>
<div class="layout">
<div id="controls"><!-- DO NOT EDIT --></div>
<div id="currentSlide"><!-- DO NOT EDIT --></div>
<div id="header"></div>
<div id="footer">
<h1></h1>
<h2>#{@p}</h2>
</div>
</div>
<div class="presentation">

#{body}

</div>
</body>
</html>
EOS
end

add_plugin_command("keynote",
                   "Keynote",
                   {"p" => CGI::escape(@page) }
                   ) if @page and auth?
本日のツッコミ(全1件) [ツッコミを入れる]
1 みるふぃ (2008-01-18 (金) 11:32)

>1年使ってMacのよさが全然分からないというと変人扱いされる。・・・僕も同じ感想ですね。人には言わないので変人扱いはされませんがw