From f6a0f5ba417ad7eaff85f4b9c2c2b3b0a3b3ba27 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 27 Jul 2010 11:09:36 -0400 Subject: [PATCH] more cleanup work --- Rakefile | 2 +- lib/s6-gen/generator.rb | 48 ++++++++++++++++++++++++++++++++++++ lib/s6-gen/presentation.rb | 18 -------------- lib/s6-gen/rake.rb | 1 + lib/s6-gen/rake/generate.rb | 49 +++---------------------------------- lib/s6-gen/rake/server.rb | 6 +++++ templates/layout.haml | 26 +++++++++++--------- 7 files changed, 74 insertions(+), 76 deletions(-) create mode 100644 lib/s6-gen/generator.rb delete mode 100644 lib/s6-gen/presentation.rb create mode 100644 lib/s6-gen/rake/server.rb diff --git a/Rakefile b/Rakefile index 4c66117..61935d4 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ begin s.email = "john@coswellproductions.com" s.homepage = "http://github.com/johnbintz/s6-gen" s.description = "Create new S6 presenations using Haml" - s.authors = ["JJohn Bintz"] + s.authors = ["John Bintz"] s.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"] s.add_dependency 'haml' end diff --git a/lib/s6-gen/generator.rb b/lib/s6-gen/generator.rb new file mode 100644 index 0000000..a7b200e --- /dev/null +++ b/lib/s6-gen/generator.rb @@ -0,0 +1,48 @@ +require 'haml' +require 'compass' +require 'sass' +require 'fileutils' + +module S6Gen + module Generator + def all! + html! + css! + end + + def html! + raise "No #{@source_dir}/index.haml file found!" if !File.exist?("#{@source_dir}/index.haml") + + FileUtils.mkdir_p @target_dir + + layout = File.exist?("#{@source_dir}/layout.haml") ? "#{@source_dir}/layout.haml" : File.join(S6Gen::ROOT, 'templates/layout.haml') + File.open("#{@target_dir}/index.html", 'w') do |file| + file.puts Haml::Engine.new(File.read(layout)).to_html(self) { render('index.haml') } + end + end + + def css! + raise "No #{@source_dir}/style.sass file found!" if !File.exist?("#{@source_dir}/style.sass") + + FileUtils.mkdir_p @target_dir + + Compass.configuration do |config| + config.project_path = Dir.pwd + config.sass_dir = @source_dir + + config.images_dir = File.join(@target_dir, 'graphics') + config.http_path = "" + config.http_images_path = 'graphics' + config.output_style = :compact + end + + File.open("#{@target_dir}/style.css", 'w') do |file| + file.puts Sass::Engine.new(File.read("#{@source_dir}/style.sass"), Compass.sass_engine_options).to_css + end + end + + def render(file) + Haml::Engine.new(File.read(File.join(@source_dir, file))).to_html(self) + end + end +end diff --git a/lib/s6-gen/presentation.rb b/lib/s6-gen/presentation.rb deleted file mode 100644 index 4c21116..0000000 --- a/lib/s6-gen/presentation.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'haml' - -module S6Gen - class Presentation - def self.render(file, root) - presentation = self.new(root) - presentation.render(file) - end - - def initialize(root) - @root = root - end - - def render(file) - Haml::Engine.new(File.read(File.join(@root, file))).to_html(self) - end - end -end diff --git a/lib/s6-gen/rake.rb b/lib/s6-gen/rake.rb index d991a58..7e7da35 100644 --- a/lib/s6-gen/rake.rb +++ b/lib/s6-gen/rake.rb @@ -1,3 +1,4 @@ require 'rubygems' +require 's6-gen/generator' Dir[File.join(File.dirname(__FILE__), 'rake/*.rb')].each { |file| require file } diff --git a/lib/s6-gen/rake/generate.rb b/lib/s6-gen/rake/generate.rb index 2e246cd..451dd8e 100644 --- a/lib/s6-gen/rake/generate.rb +++ b/lib/s6-gen/rake/generate.rb @@ -1,50 +1,9 @@ -require 's6-gen' -require 's6-gen/presentation' require 'fileutils' -require 'compass' -require 'sass' -module S6Gen - module RakeHelper - def all! - html! - css! - end +include S6Gen::Generator - def html! - raise "No src/index.haml file found!" if !File.exist?('src/index.haml') - - FileUtils.mkdir_p 'public' - - layout = File.exist?('src/layout.haml') ? 'src/layout.haml' : File.join(S6Gen::ROOT, 'templates/layout.haml') - File.open('public/index.html', 'w') do |file| - file.puts Haml::Engine.new(File.read(layout)).to_html(self) { S6Gen::Presentation.render('index.haml', 'src') } - end - end - - def css! - raise "No src/style.sass file found!" if !File.exist?('src/style.sass') - - FileUtils.mkdir_p 'public' - - Compass.configuration do |config| - config.project_path = Dir.pwd - config.sass_dir = 'src' - - config.images_dir = File.join('public', 'graphics') - config.http_path = "" - config.http_images_path = 'graphics' - config.output_style = :compact - end - - File.open('public/style.css', 'w') do |file| - file.puts Sass::Engine.new(File.read('src/style.sass'), Compass.sass_engine_options).to_css - end - end - end -end - -include S6Gen::RakeHelper +@source_dir ||= 'src' +@target_dir ||= 'public' namespace :s6 do desc "Regenerate presentation index.html file" @@ -64,7 +23,7 @@ namespace :s6 do task :watch do require 'directory_watcher' - watcher = DirectoryWatcher.new 'src', :pre_load => true + watcher = DirectoryWatcher.new @source_dir, :pre_load => true watcher.interval = 1 watcher.add_observer do |*args| args.each { |e| puts e } diff --git a/lib/s6-gen/rake/server.rb b/lib/s6-gen/rake/server.rb new file mode 100644 index 0000000..e246bed --- /dev/null +++ b/lib/s6-gen/rake/server.rb @@ -0,0 +1,6 @@ +namespace :server do + desc "Start Thin" + task :thin do + system %{thin start} + end +end diff --git a/templates/layout.haml b/templates/layout.haml index b716211..641d23b 100644 --- a/templates/layout.haml +++ b/templates/layout.haml @@ -11,19 +11,21 @@ %script{:src => 'jquery/jquery-ui-1.7.2.effects.min.js', :type => 'text/javascript'} %script{:src => 's6/shared/slides.core.js', :type => 'text/javascript'} %script{:src => 's6/shared/slides.js', :type => 'text/javascript'} + :javascript - $(function() { - var center; - center = function() { - setTimeout(function() { - $('.center').each(function() { - $(this).css('left', ($(window).width() - $(this).width()) / 2); - }); - center(); - }, 50); - }; - center(); - }); + function updatePermaLink() { + $('#plink').get(0).href = window.location.pathname + '#slide' + snum; + + var padding = 20; + + var availableWidth = $(window).width() - padding; + var availableHeight = $('.presentation > .slide:visible').height() - padding; + + $('.center').each(function() { + $(this).css('left', (availableWidth - $(this).width()) / 2); + $(this).css('top', (availableHeight - $(this).height()) / 2); + }); + } %body .layout .background