Class: Courseware::Manager
- Inherits:
-
Object
- Object
- Courseware::Manager
- Defined in:
- lib/courseware/manager.rb,
lib/courseware/manager/validators.rb
Instance Attribute Summary collapse
-
#coursename ⇒ Object
readonly
Returns the value of attribute coursename.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(config, repository = nil, generator = nil, printer = nil) ⇒ Manager
constructor
A new instance of Manager.
- #lint ⇒ Object
- #missing ⇒ Object
- #obsolete ⇒ Object
- #release(type) ⇒ Object
- #releasenotes ⇒ Object
- #wordcount(subject) ⇒ Object
Constructor Details
#initialize(config, repository = nil, generator = nil, printer = nil) ⇒ Manager
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/courseware/manager.rb', line 11 def initialize(config, repository=nil, generator=nil, printer=nil) @config = config @repository = repository || Courseware::Repository.new(config) @generator = generator || Courseware::Generator.new(config) @warnings = 0 @errors = 0 showoff = Courseware.parse_showoff(@config[:presfile]) @coursename = showoff['name'] @prefix = showoff['name'].gsub(' ', '_') @sections = showoff['sections'] @password = showoff['key'] end |
Instance Attribute Details
#coursename ⇒ Object (readonly)
Returns the value of attribute coursename.
9 10 11 |
# File 'lib/courseware/manager.rb', line 9 def coursename @coursename end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/courseware/manager.rb', line 9 def errors @errors end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/courseware/manager.rb', line 9 def prefix @prefix end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
9 10 11 |
# File 'lib/courseware/manager.rb', line 9 def warnings @warnings end |
Instance Method Details
#lint ⇒ Object
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 |
# File 'lib/courseware/manager/validators.rb', line 48 def lint puts "Checking Markdown style:" style = File.join(@config[:cachedir], 'templates', 'markdown_style.rb') style = File.exists?(style) ? style : 'all' issues = 0 unless system('mdl', '--version') puts ' * Markdown linter not found: gem install mdl' puts @warnings += 1 return end Dir.glob('**/*.md') do |file| next if File.symlink? file next if File.directory? file next if file =~ /^_.*$|^[^\/]*$/ issues += 1 unless system('mdl', '-s', style, file) end if issues > 0 puts puts 'Rule explanations can be found at:' puts ' * https://github.com/mivok/markdownlint/blob/master/docs/RULES.md' puts @warnings += issues end end |
#missing ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/courseware/manager/validators.rb', line 31 def missing sections = @sections.dup # This seems backwards, but we do it this way to get a case sensitive match # http://stackoverflow.com/questions/357754/can-i-traverse-symlinked-directories-in-ruby-with-a-glob -- Baby jesus is crying. Dir.glob("**{,/*/**}/*.md") do |file| sections.delete(file) end return if sections.empty? puts "Missing slides:" sections.each do || puts " * #{slide}" @errors += 1 end end |
#obsolete ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/courseware/manager/validators.rb', line 3 def obsolete # We need to get all slides from all variants to determine what's obsolete. allsections = Dir.glob('*.json').collect do |variant| Courseware.parse_showoff(variant)['sections'] rescue nil end.flatten.uniq puts "Obsolete images:" Dir.glob('**/_images/*') do |file| next if File.symlink? file next if File.directory? file next if system("grep #{file} *.css */*.md >/dev/null 2>&1") puts " * #{file}" @warnings += 1 end puts "Obsolete slides:" Dir.glob('**/*.md') do |file| next if File.symlink? file next if File.directory? file next if file =~ /^_.*$|^[^\/]*$/ next if allsections.include? file puts " * #{file}" @warnings += 1 end end |
#release(type) ⇒ Object
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 |
# File 'lib/courseware/manager.rb', line 49 def release(type) courselevel! master! clean! @repository.update version = Courseware.increment(@repository.current(@coursename), type) Courseware.bailout?("Building a release for #{@coursename} version #{version}.") raise "Release notes not updated for #{version}" unless Courseware.grep(version, 'Release-Notes.md') Courseware.dialog('Last Repository Commit', @repository.last_commit) Courseware.bailout?('Abort now if the commit message displayed is not what you expected.') build_pdfs(version) point_of_no_return Courseware.bailout?('Please inspect the generated PDF files and abort if corrections must be made.') do @repository.discard(@config[:stylesheet]) end @repository.commit(@config[:stylesheet], "Updating for #{@coursename} release #{version}") @repository.tag("#{@prefix}-#{version}", "Releasing #{@coursename} version #{version}") # places the PDF files should be uploaded to @config[:release][:links].each do |link| system("open #{link}") end puts "Release shipped. Please upload PDF files to printer and break out the bubbly." end |
#releasenotes ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/courseware/manager.rb', line 25 def releasenotes courselevel! master! clean! @repository.update current = @repository.current(@coursename) version = Courseware.increment(current) tag = "#{@coursename}-#{current}" notes = @repository.releasenotes(tag, version) # print to screen puts notes # and copy if on OS X begin IO.popen('pbcopy', 'w') { |f| f.puts notes } puts puts "{{ Copied to clipboard }}" rescue end end |
#wordcount(subject) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/courseware/manager.rb', line 79 def wordcount(subject) $logger.debug "Counting words for #{subject}" opts = print_opts(@repository.current(prefix)) puts "Words longer than a single character:" Courseware::Printer.new(@config, opts) do |printer| subject.each do |item| printer.generate_html(item) doc = Nokogiri::HTML(File.read('static/index.html')) count = doc.css('body').text.split.select {|w| w.size > 1 }.count puts " * #{item}: #{count}" FileUtils.rm_rf('static') end end end |