This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Allow custom output file name and custom master slide name (preservin…

…g the option of multiple master slides)
  • Loading branch information...
dmfrancisco committed Jul 28, 2011
1 parent 52530b5 commit caf473ed6d51481df333271208319008b8fa4c53
Showing with 52 additions and 13 deletions.
  1. 0 src/{index.html → master.html}
  2. +52 −13 watch
File renamed without changes.
View
65 watch
@@ -39,7 +39,10 @@ require 'rake'
# Default options
$options = {
:source => 'src',
+ :master => 'master.html',
:live => true,
+ :output => 'slideshow.html',
+ :multiple => false,
:port => 6543,
:binding => "0.0.0.0"
}
@@ -51,15 +54,20 @@ module Builder
# To see the original source visit http://ryanfunduk.com/simple-partials/
def self.write_output(filename, result)
- ext = filename.split('.').last
+ if $options[:output] && !$options[:multiple]
+ filename = $options[:output]
+ else
+ # If there are N .html files in the source folder (excluding the partials), the result will be N html files
+ ext = filename.split('.').last
- filename = filename.split '/'
- filename.delete $options[:source]
- filename.insert -2, ext unless ext == 'html'
- filename = filename.join '/'
+ filename = filename.split '/'
+ filename.delete $options[:source]
+ filename.insert -2, ext unless ext == 'html'
+ filename = filename.join '/'
- result.gsub! /V%/, '<%'
- result.gsub! /%V/, '%>'
+ result.gsub! /V%/, '<%'
+ result.gsub! /%V/, '%>'
+ end
f = File.open(filename, 'wb')
f.write(result)
@@ -86,7 +94,13 @@ module Builder
# Build the compiled html file that includes the layout and all partials
def self.build
$partials = 0
- sources = FileList["#{$options[:source]}/*.*"].exclude("#{$options[:source]}/*.partial")
+
+ if !$options[:multiple]
+ # If the result should be only one html file, then only one .html should exist
+ sources = ["#{$options[:source]}/#{$options[:master]}"]
+ else
+ sources = FileList["#{$options[:source]}/*.*"].exclude("#{$options[:source]}/*.partial")
+ end
sources.each do |source|
puts "\nCOMPILING : #{source}"
@@ -106,12 +120,24 @@ module Options
# Check if the specified options are valid
def self.valid_options?
dir_exists = File.directory? $options[:source]
- if !dir_exists and $options[:custom_source]
- puts "Invalid directory for the --source option."
+ if !dir_exists && $options[:custom_source]
+ puts "Invalid directory specified with the --source option."
elsif !dir_exists
- puts "Cannot find the slideshow folder. Please use the --source option."
+ puts "Could not find the slideshow folder." \
+ "Please use the --source option if you want to use a custom value (default is '#{$options[:source]}')."
+ end
+
+ master_exists = File.exists? "#{$options[:source]}/#{$options[:master]}"
+ if !master_exists && $options[:custom_master] && !$options[:multiple]
+ puts "Invalid file name for the master slide specified with the --input option."
+ elsif !master_exists && !$options[:multiple]
+ puts "Could not find the master slide file. " \
+ "Please use the --input option if you want to use a custom value (default is '#{$options[:master]}')."
+ else
+ master_exists = true # It doesn't really exist, but we'll handle several master slides
end
- dir_exists
+
+ dir_exists && master_exists
end
def self.init
@@ -124,7 +150,20 @@ module Options
# Slideshow folder
opts.on( '-s', '--source DIR', 'Creates a slideshow using the files on the specified folder' ) do |dir|
$options[:source] = dir
- $options[:custom_source] = true
+ $options[:custom_source] = true # This var is only used to print a better error message
+ end
+ # Name of the resulting html file
+ opts.on( '-o', '--output FILENAME', 'Name of the resulting html file' ) do |filename|
+ $options[:output] = filename
+ end
+ # Name of the master slide html file
+ opts.on( '-i', '--input FILENAME', 'Name of the master slide file' ) do |filename|
+ $options[:master] = filename
+ $options[:custom_master] = true # This var is only used to print a better error message
+ end
+ # Allow several slideshows inside the source folder
+ opts.on( '-m', '--multiple', 'Allow several slideshows inside the source folder' ) do
+ $options[:multiple] = true
end
# Excluding live.js
opts.on( '-n', '--nolive', 'Excludes the live.js library' ) do

0 comments on commit caf473e

Please sign in to comment.