few more cowboyed updates
This commit is contained in:
parent
be0dfdea74
commit
480e33d26a
32
README.md
32
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
|
||||
|
@ -30,5 +30,7 @@ Gem::Specification.new do |gem|
|
||||
gem.add_dependency 'pygments.rb'
|
||||
|
||||
gem.add_dependency 'jquery-rails'
|
||||
|
||||
gem.add_dependency 'thor'
|
||||
end
|
||||
|
||||
|
@ -9,6 +9,7 @@ rescue Bundler::GemfileNotFound
|
||||
$: << File.expand_path('../../lib', __FILE__)
|
||||
end
|
||||
|
||||
require 'thor'
|
||||
require 'rack'
|
||||
require 'attentive'
|
||||
require 'pygments'
|
||||
|
@ -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 = [ %{<div class="#{classes}"><div class="content">} ]
|
||||
|
||||
output << markdown_output
|
||||
|
||||
output << "</div></div>"
|
||||
|
||||
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("<doc>#{File.read(file)}</doc>")
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
%{<div class="#{classes.join(' ')}"><div class="content">#{content}</div></div>}
|
||||
end.join
|
||||
end.join
|
||||
|
||||
highlights.each_with_index do |highlight, index|
|
||||
output.gsub!("{highlight#{index}}", highlight)
|
||||
end
|
||||
|
||||
output
|
||||
slides.collect(&:to_html).join
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user