Class: Hiki2yard::Command
- Inherits:
-
Object
- Object
- Hiki2yard::Command
- Defined in:
- lib/hiki2yard.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_pre_in_latexes ⇒ Object
- #copy_file_even_if_exists(source, target) ⇒ Object
- #copy_file_if_not_exists(source, target) ⇒ Object
- #create_dir_if_not_exists(data_path) ⇒ Object
- #execute ⇒ Object
- #init ⇒ Object
-
#initialize(argv = []) ⇒ Command
constructor
A new instance of Command.
- #mk_yardopts ⇒ Object
- #rev_gemspec ⇒ Object
- #rev_rakefile ⇒ Object
- #rev_rakefile2 ⇒ Object
Constructor Details
#initialize(argv = []) ⇒ Command
Returns a new instance of Command
13 14 15 16 17 18 19 20 21 |
# File 'lib/hiki2yard.rb', line 13 def initialize(argv=[]) @argv = argv @source_path = File.('..', __FILE__) @target_path = Dir.pwd @base_name=File.basename(@target_path) print "source_path= \'#{@source_path}\'\n" print "target_path= \'#{@target_path}\'\n" @opts={} end |
Class Method Details
.run(argv = []) ⇒ Object
9 10 11 |
# File 'lib/hiki2yard.rb', line 9 def self.run(argv=[]) new(argv).execute end |
Instance Method Details
#add_pre_in_latexes ⇒ Object
53 54 55 56 57 58 |
# File 'lib/hiki2yard.rb', line 53 def add_pre_in_latexes source=File.join(@source_path,'hiki2yard','handout_pre.tex') target=File.join(@target_path,'latexes') p command = "cp #{source} #{target}" system command end |
#copy_file_even_if_exists(source, target) ⇒ Object
97 98 99 |
# File 'lib/hiki2yard.rb', line 97 def copy_file_even_if_exists(source, target) FileUtils.cp(source,target,:verbose=>true) # :noop=>true) end |
#copy_file_if_not_exists(source, target) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/hiki2yard.rb', line 89 def copy_file_if_not_exists(source, target) if File::exists?(target) print "File #{target} exists, not copy.\n" return end FileUtils.cp(source,target,:verbose=>true) # :noop=>true) end |
#create_dir_if_not_exists(data_path) ⇒ Object
84 85 86 87 |
# File 'lib/hiki2yard.rb', line 84 def create_dir_if_not_exists(data_path) return if File::exists?(data_path) FileUtils.mkdir(data_path,:verbose=>true) # :noop=>true) end |
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hiki2yard.rb', line 23 def execute @argv << '--help' if @argv.size==0 command_parser = OptionParser.new do |opt| opt.on('-v', 'show program Version.') { |v| opt.version = Hiki2yard::VERSION puts opt.ver } opt.on('-f','--force','force copy new Rakefile.') { @opts[:force]=true } opt.on('-i','--init','initialize hiki2yard directory.') { |v| init exit } end command_parser. = "Usage: hiki2yard [options] FILE" command_parser.parse!(@argv) exit end |
#init ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/hiki2yard.rb', line 43 def init rev_rakefile2 mk_yardopts create_dir_if_not_exists(File.join(@target_path,'hikis')) create_dir_if_not_exists(File.join(@target_path,"#{@base_name}.wiki")) create_dir_if_not_exists(File.join(@target_path,'latexes')) add_pre_in_latexes rev_gemspec end |
#mk_yardopts ⇒ Object
79 80 81 82 |
# File 'lib/hiki2yard.rb', line 79 def mk_yardopts cont = "-\n**/*.md\n" File.write(File.join(@target_path,'.yardopts'),cont) end |
#rev_gemspec ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hiki2yard.rb', line 101 def rev_gemspec cont=<<"EOS" spec.add_development_dependency "yard" spec.add_development_dependency "hiki2md" spec.add_development_dependency "mathjax-yard" spec.add_development_dependency "hiki2latex" EOS print "add follows at the tail of #{@target_path}/#{@base_name}.gemspec\n" print cont end |
#rev_rakefile ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/hiki2yard.rb', line 68 def rev_rakefile source=File.join(@source_path,'hiki2yard','new_rakefile') target=File.join(@target_path,'Rakefile') p @opts[:force] if @opts[:force] then copy_file_even_if_exists(source, target) else copy_file_if_not_exists(source, target) end end |
#rev_rakefile2 ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/hiki2yard.rb', line 60 def rev_rakefile2 rev_rakefile source=File.join(@source_path,'hiki2yard','latex_task.rb') target=File.join(@target_path,'Rakefile') p command = "cat #{source} >> #{target}" system command end |