Class: Hiki2yard::Command
- Inherits:
-
Object
- Object
- Hiki2yard::Command
- Defined in:
- lib/hiki2yard.rb
Class Method Summary collapse
Instance Method Summary collapse
- #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
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
#copy_file_even_if_exists(source, target) ⇒ Object
81 82 83 |
# File 'lib/hiki2yard.rb', line 81 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
73 74 75 76 77 78 79 |
# File 'lib/hiki2yard.rb', line 73 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
68 69 70 71 |
# File 'lib/hiki2yard.rb', line 68 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 |
# File 'lib/hiki2yard.rb', line 43 def init rev_rakefile mk_yardopts create_dir_if_not_exists(File.join(@target_path,'hikis')) create_dir_if_not_exists(File.join(@target_path,"#{@base_name}.wiki")) rev_gemspec end |
#mk_yardopts ⇒ Object
63 64 65 66 |
# File 'lib/hiki2yard.rb', line 63 def mk_yardopts cont = "-\n**/*.md\n" File.write(File.join(@target_path,'.yardopts'),cont) end |
#rev_gemspec ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/hiki2yard.rb', line 85 def rev_gemspec cont=<<"EOS" spec.add_development_dependency "yard" spec.add_development_dependency "hiki2md" spec.add_development_dependency "mathjax-yard" EOS print "add follows at the tail of #{@target_path}/#{@base_name}.gemspec\n" print cont end |
#rev_rakefile ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hiki2yard.rb', line 52 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 |