lib/slippery/rake_tasks.rb in slippery-0.0.3 vs lib/slippery/rake_tasks.rb in slippery-0.1.0

- old
+ new

@@ -24,15 +24,15 @@ def presentation_names presentations.map {|path| [ path.basename(path.extname), path ] } end - def markdown_to_hexp(infile) + def markdown_to_hexp(infile, options = {}) doc = Slippery::Document.new(infile.read) - doc = Slippery::Presentation.new(doc, options) + doc = Slippery::Presentation.new(doc, @options.merge(options)) - doc.process(*processors) + doc.process(*processors.reject {|pr| options[:skip_self_contained] && pr == Slippery::Processors::SelfContained}) end def processor(selector, &blk) processors << ->(node) do node.replace(selector) do |node| @@ -43,10 +43,20 @@ def self_contained processors << Slippery::Processors::SelfContained end + def title(title) + processor 'head' do |head| + head <<= H[:title, title] + end + end + + def add_highlighting(style = Slippery::Processors::AddHighlight::DEFAULT_STYLE, version = Slippery::Processors::AddHighlight::DEFAULT_VERSION) + processors << Slippery::Processors::AddHighlight.new(style, version) + end + def define namespace @name do desc "build all" task :build => presentation_names.map(&:first).map {|name| "#{@name}:build:#{name}"} @@ -59,17 +69,20 @@ end end namespace :watch do presentation_names.each do |name, path| + files = markdown_to_hexp(path, skip_self_contained: true).select('link,script').map {|link| link.attr('href') || link.attr('src')}.compact + files = files.select {|f| File.exist?(f)} + desc "watch #{name} for changes" - WatchTask.new(name, [path.to_s]) do + WatchTask.new(name, [path.to_s, *files]) do dest = Tempfile.new("#{name}.html") File.open("#{name}.html") { |src| FileUtils.copy_stream(src, dest) } dest.close Rake::Task["#{@name}:build:#{name}"].execute puts "="*60 - print `diff -u #{dest.path} #{name}.html` if File.exist? "#{name}.html" + print `diff -u #{dest.path} #{name}.html | cut -c1-150` if File.exist? "#{name}.html" end end end end