diff --git a/README.md b/README.md index 3f4af42..a8e493c 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,7 @@ -# Attentive +Attentive is a new take on Ruby presentation software. It provides lots of smart things already set up for you: -TODO: Write a gem description +* A simple slide transition system using a slightly hacked up version of Fathom.js. +* Sass, Compass, and CoffeeScript all plugged into Sprockets and ready to generate your presentation's CSS and JavaScripts. +* Pygments for syntax highlighting. +* Simple slide syntax, really really similar to how Showoff does it. -## Installation - -Add this line to your application's Gemfile: - - gem 'attentive' - -And then execute: - - $ bundle - -Or install it yourself as: - - $ gem install attentive - -## Usage - -TODO: Write usage instructions here - -## Contributing - -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Added some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request diff --git a/attentive.gemspec b/attentive.gemspec index 48288bb..b77913a 100644 --- a/attentive.gemspec +++ b/attentive.gemspec @@ -30,5 +30,7 @@ Gem::Specification.new do |gem| gem.add_dependency 'pygments.rb' gem.add_dependency 'jquery-rails' + + gem.add_dependency 'thor' end diff --git a/bin/attentive b/bin/attentive index 6297d29..4d22ac4 100755 --- a/bin/attentive +++ b/bin/attentive @@ -9,6 +9,7 @@ rescue Bundler::GemfileNotFound $: << File.expand_path('../../lib', __FILE__) end +require 'thor' require 'rack' require 'attentive' require 'pygments' diff --git a/lib/attentive/server.rb b/lib/attentive/server.rb index 6e366f6..d11983a 100644 --- a/lib/attentive/server.rb +++ b/lib/attentive/server.rb @@ -10,6 +10,8 @@ require 'sinatra/base' require 'rack/builder' +require 'forwardable' + module Attentive class Server < Rack::Builder def self.call(env) @@ -34,55 +36,91 @@ module Attentive end end + class Slide + extend Forwardable + + def_delegators :lines, :<< + + attr_reader :lines + + def initialize(options = {}) + @options = options + @lines = [] + end + + def classes + ([ 'slide' ] + (@options[:classes] || []).collect { |klass| "style-#{klass}" }).join(' ') + end + + def code_output + new_lines = [] + + code_block = nil + code_language = nil + + lines.each do |line| + if line[%r{^```}] + if code_block + new_lines << Pygments.highlight(code_block.join, :lexer => code_language) + code_block = nil + else + code_block = [] + + parts = line.split(' ') + + code_language = case parts.length + when 1 + 'text' + else + parts.last + end + end + else + if code_block + code_block << line + else + new_lines << line + end + end + end + + new_lines + end + + def markdown_output + RDiscount.new(code_output.join).to_html + end + + def to_html + output = [ %{
} ] + + output << markdown_output + + output << "
" + + output.join("\n") + end + end + class Sinatra < Sinatra::Base set :logging, true helpers do - def trim_lines(code) - code.lines.collect(&:strip).join("\n") - end - def slides - highlights = [] + slides = [] - output = Dir['presentation/*.html'].sort.collect do |file| - xml = Nokogiri::XML("#{File.read(file)}") - - xml.search('slide').collect do |node| - classes = %w{slide} - - if style = node.attributes['style'] - style.to_s.split(' ').each { |s| classes << "style-#{s}" } - end - - node.search('code').collect do |code| - highlighted_code = Pygments.highlight(code.inner_text.strip, :lexer => code.attributes['lang'].to_s) - - code.add_next_sibling("{highlight#{highlights.length}}") - - code.remove - - highlights << highlighted_code - end - - content = node.inner_html - - content = case node.attributes['content'].to_s - when 'html' - content + Dir['presentation/*.slides'].sort.each do |file| + File.readlines(file).each do |line| + if line[%r{^!SLIDE}] + slides << Slide.new(:classes => line.split(' ')[1..-1]) else - RDiscount.new(trim_lines(content)).to_html + slides << Slide.new if !slides.last + slides.last << line end - - %{
#{content}
} - end.join - end.join - - highlights.each_with_index do |highlight, index| - output.gsub!("{highlight#{index}}", highlight) + end end - output + slides.collect(&:to_html).join end end