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.
12 13 14 15 16 17 18 19 |
# File 'lib/hiki2yard.rb', line 12 def initialize(argv=[]) @argv = argv @source_path = File.('..', __FILE__) @target_path = Dir.pwd p @base_name=File.basename(@target_path) p @source_path,@target_path @opts={} end |
Class Method Details
.run(argv = []) ⇒ Object
8 9 10 |
# File 'lib/hiki2yard.rb', line 8 def self.run(argv=[]) new(argv).execute end |
Instance Method Details
#copy_file_even_if_exists(source, target) ⇒ Object
75 76 77 |
# File 'lib/hiki2yard.rb', line 75 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
70 71 72 73 |
# File 'lib/hiki2yard.rb', line 70 def copy_file_if_not_exists(source, target) return if File::exists?(target) FileUtils.cp(source,target,:verbose=>true) # :noop=>true) end |
#create_dir_if_not_exists(data_path) ⇒ Object
65 66 67 68 |
# File 'lib/hiki2yard.rb', line 65 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hiki2yard.rb', line 21 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
41 42 43 44 45 46 47 48 |
# File 'lib/hiki2yard.rb', line 41 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
60 61 62 63 |
# File 'lib/hiki2yard.rb', line 60 def mk_yardopts cont = "-\n**/*.md\n" File.write(File.join(@target_path,'.yardopts'),cont) end |
#rev_gemspec ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/hiki2yard.rb', line 79 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
50 51 52 53 54 55 56 57 58 |
# File 'lib/hiki2yard.rb', line 50 def rev_rakefile source=File.join(@source_path,'hiki2yard','new_rakefile') target=File.join(@target_path,'Rakefile') if @opts[:force] then copy_file_even_if_exists(source, target) else copy_file_if_not_exists(source, target) end end |