Class: Jekyll::Commands::VDoc
- Inherits:
-
Command
- Object
- Command
- Jekyll::Commands::VDoc
- Defined in:
- lib/jekyll/version/commands/vdoc.rb
Class Method Summary collapse
- .checkIncompatibility(lastVersion, newVersion) ⇒ Object
- .createVersion(newVersion) ⇒ Object
- .getLestVersion ⇒ Object
- .init_with_program(prog) ⇒ Object
Class Method Details
.checkIncompatibility(lastVersion, newVersion) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jekyll/version/commands/vdoc.rb', line 54 def checkIncompatibility(lastVersion, newVersion) path = "#{Dir.pwd}/_docs" raise ArgumentError.new("A version already exists at #{path}/#{newVersion}") if(lastVersion == newVersion) versions = Dir["#{path}/*"] result = versions.find {|item| item == "#{path}/#{newVersion}" } raise ArgumentError.new("A version already exists at #{path}/#{newVersion}") if(result) return false end |
.createVersion(newVersion) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll/version/commands/vdoc.rb', line 39 def createVersion(newVersion) lastVersion_dir = Dir["#{self.getLestVersion}/*.md"] path = "#{Dir.pwd}/_docs/#{newVersion.to_s}" if !File.directory?(path) Dir.mkdir(path) unless Dir.exist?(path) end lastVersion_dir.each do |filename| name = File.basename('filename', '.md')[0,4] dest_folder = "#{path}/" FileUtils.cp(filename, dest_folder) end end |
.getLestVersion ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jekyll/version/commands/vdoc.rb', line 28 def getLestVersion path = "#{Dir.pwd}/_docs" if !File.directory?(path) Dir.mkdir(path) unless Dir.exist?(path) end return Dir["#{path}/*"].last() end |
.init_with_program(prog) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jekyll/version/commands/vdoc.rb', line 7 def init_with_program(prog) prog.command(:vdoc) do |c| c.syntax "vdoc VERSION" c.description "Create a new version for the documentation" c.action do |args, | if args.length != 1 Jekyll.logger.error "You entered the command with invalid parameters, See example: jekyll vdoc 1.0" else lastVersion = self.getLestVersion.to_s.split("/").last() newVersion = args[0] ? args[0] : '0.0.1' if !self.checkIncompatibility(lastVersion, newVersion) self.createVersion(newVersion) Jekyll.logger.info "Version #{newVersion} was successfully created" end end end end end |