Class: Courseware::Composer
- Inherits:
-
Object
- Object
- Courseware::Composer
- Defined in:
- lib/courseware/composer.rb
Instance Method Summary collapse
- #build(subject) ⇒ Object
-
#initialize(config, repository = nil) ⇒ Composer
constructor
A new instance of Composer.
- #package(subject) ⇒ Object
Constructor Details
#initialize(config, repository = nil) ⇒ Composer
Returns a new instance of Composer.
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/courseware/composer.rb', line 2 def initialize(config, repository=nil) @config = config @repository = repository || Courseware::Repository.new(config) return if @config[:presfile] == :none if File.exists?(@config[:presfile]) @showoff = JSON.parse(File.read(@config[:presfile])) @coursename = @showoff['name'] @prefix = @showoff['name'].gsub(' ', '_') end end |
Instance Method Details
#build(subject) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/courseware/composer.rb', line 15 def build(subject) courselevel! if subject.nil? raise 'Please re-run this task with a list of tags to include.' end raise 'Please re-run this task with a list of tags to include.' unless subject.is_a? Array raise 'No master section defined in `showoff.json`' unless @showoff.include? 'master' newsections = {} @showoff['master'].each do |section| next if (section['tags'] & subject).empty? name = section['name'] newsections[name] = section['content'] end name = Courseware.question('What would you like to call this variant?', 'custom').gsub(/\W+/, '_') desc = Courseware.question("Enter a customized description if you'd like:") @showoff.delete 'tags' @showoff.delete 'master' @showoff['name'] = name if name @showoff['description'] = desc if desc @showoff['sections'] = newsections File.write("#{name}.json", JSON.pretty_generate(@showoff)) puts "Run your presentation with `showoff serve -f #{name}.json` or `rake present`" end |
#package(subject) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/courseware/composer.rb', line 46 def package(subject) courselevel! on_release! pristine! content = JSON.parse(`showoff info -jf #{subject}`) variant = File.basename(subject, '.json') current = @repository.current(@coursename) if variant == 'showoff' output = @prefix else output = "#{@prefix}-#{variant}" end FileUtils.rm_rf "build/#{@prefix}" FileUtils.mkdir_p "build/#{@prefix}" FileUtils.cp subject, "build/#{@prefix}/showoff.json" # Copy in only the slides used content['files'].each do |path| FileUtils.mkdir_p "build/#{@prefix}/#{File.dirname(path)}" FileUtils.cp path, "build/#{@prefix}/#{path}" end # Copy in only the images used content['images'].each do |path| FileUtils.mkdir_p "build/#{@prefix}/#{File.dirname(path)}" FileUtils.cp path, "build/#{@prefix}/#{path}" end # support is special FileUtils.cp_r '../_support', "build/#{@prefix}/_support" FileUtils.rm_f "build/#{@prefix}/_support/*.pem" FileUtils.rm_f "build/#{@prefix}/_support/*.pub" FileUtils.rm_f "build/#{@prefix}/_support/aws_credentials" # duplicate from cwd to build/variant everything not already copied Dir.glob('**{,/*/**}/*').each do |path| next if path.start_with? 'build' next if path.start_with? 'stats' next if path.start_with? 'pdf' next if path.start_with? '_images' next if path == 'user.js' next if path =~ /^\w+.json$/ next if File.exist? "build/#{@prefix}/#{path}" FileUtils.mkdir_p "build/#{@prefix}/#{File.dirname(path)}" unless File.directory?(path) FileUtils.ln_s File.(path), "build/#{@prefix}/#{path}" end system("tar -C build --dereference -czf build/#{output}-#{current}.tar.gz #{@prefix}") if Courseware.confirm("Would you like to clean up the output build directory?") FileUtils.rm_rf "build/#{@prefix}" end end |