|
| 1 | +# -*- ruby -*- |
| 2 | +# Generate HTML slides, for S5, from Markdown input. |
| 3 | +# |
| 4 | +# See README.md for pre-requisites. |
| 5 | +# --------------------------------------------------------------------------- |
| 6 | + |
| 7 | +require 'rubygems' |
| 8 | +require 'rake/clean' |
| 9 | +require 'slidedown' |
| 10 | +require 'albino' |
| 11 | + |
| 12 | +PRESO_DIR = 'preso' |
| 13 | +SLIDE_INPUTS = FileList[File.join(PRESO_DIR, '*.md')] |
| 14 | +SASS_DIR = "sass" |
| 15 | +DATA_DIR = "data" |
| 16 | +CSS_DIR = "." |
| 17 | + |
| 18 | +SASS_FILES = FileList["#{SASS_DIR}/*.scss"] |
| 19 | +CSS_OUTPUT_FILES = SASS_FILES.map do |f| |
| 20 | + f.gsub(/^#{SASS_DIR}/, CSS_DIR).gsub(/\.scss$/, '.css') |
| 21 | +end |
| 22 | + |
| 23 | +CLEAN << CSS_OUTPUT_FILES |
| 24 | +CLEAN << FileList['*.html'] |
| 25 | +CLEAN << "static" |
| 26 | +PWD = File.dirname(__FILE__) |
| 27 | + |
| 28 | +task :default => :slides |
| 29 | +task :css => CSS_OUTPUT_FILES |
| 30 | +task :run => :css do |
| 31 | + sh "showoff serve" |
| 32 | +end |
| 33 | + |
| 34 | +task :slides => ['Rakefile'] + CSS_OUTPUT_FILES + SLIDE_INPUTS do |t| |
| 35 | + sh "showoff static" |
| 36 | + cp "chariot.png", File.join("static", "file") |
| 37 | + cp FileList[File.join(PRESO_DIR, "*.png")], "static" |
| 38 | + fix_static_html(File.join("static", "index.html")) |
| 39 | +end |
| 40 | + |
| 41 | +def fix_static_html(path) |
| 42 | + # Not sure why ShowOff does this, but image URLs get preceded with a |
| 43 | + # file: URL. |
| 44 | + require 'tempfile' |
| 45 | + temp = Tempfile.new('static') |
| 46 | + begin |
| 47 | + static_index = File.join("static", "index.html") |
| 48 | + preso_url = "file://" + File.expand_path(PRESO_DIR) + "/" |
| 49 | + File.open(static_index).readlines.each do |line| |
| 50 | + temp.write(line.sub(%r|#{preso_url}|, "")) |
| 51 | + end |
| 52 | + temp.rewind |
| 53 | + File.open(static_index, 'w') do |f| |
| 54 | + f.write temp.read |
| 55 | + end |
| 56 | + ensure |
| 57 | + temp.close |
| 58 | + temp.unlink |
| 59 | + end |
| 60 | +end |
| 61 | + |
| 62 | +# --------------------------------------------------------------------------- |
| 63 | +# Auto-generate CSS files from any SASS input files. |
| 64 | + |
| 65 | +directory CSS_DIR |
| 66 | + |
| 67 | +# Figure out the name of the SCSS file necessary make a CSS file. |
| 68 | +def css_to_scss |
| 69 | + Proc.new {|task| task.sub(/^#{CSS_DIR}/, SASS_DIR). |
| 70 | + sub(/\.css$/, '.scss')} |
| 71 | +end |
| 72 | + |
| 73 | +rule %r{^#{CSS_DIR}/.*\.css$} => [css_to_scss, 'Rakefile'] + SASS_FILES do |t| |
| 74 | + require 'sass' |
| 75 | + mkdir_p CSS_DIR |
| 76 | + puts("#{t.source} -> #{t.name}") |
| 77 | + Dir.chdir('sass') do |
| 78 | + sass_input = File.basename(t.source) |
| 79 | + engine = Sass::Engine.new(File.open(sass_input).readlines.join(''), |
| 80 | + :syntax => :scss) |
| 81 | + out = File.open(File.join('..', t.name), 'w') |
| 82 | + out.write("/* AUTOMATICALLY GENERATED FROM #{t.source} on #{Time.now} */\n") |
| 83 | + out.write(engine.render) |
| 84 | + # Force close, to force flush BEFORE running other tasks. |
| 85 | + out.close |
| 86 | + end |
| 87 | +end |
| 88 | + |
0 commit comments