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.
11 12 13 14 15 16 17 18 |
# File 'lib/hiki2yard.rb', line 11 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
7 8 9 |
# File 'lib/hiki2yard.rb', line 7 def self.run(argv=[]) new(argv).execute end |
Instance Method Details
#copy_file_even_if_exists(source, target) ⇒ Object
74 75 76 |
# File 'lib/hiki2yard.rb', line 74 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
69 70 71 72 |
# File 'lib/hiki2yard.rb', line 69 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
64 65 66 67 |
# File 'lib/hiki2yard.rb', line 64 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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hiki2yard.rb', line 20 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
40 41 42 43 44 45 46 47 |
# File 'lib/hiki2yard.rb', line 40 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
59 60 61 62 |
# File 'lib/hiki2yard.rb', line 59 def mk_yardopts cont = "-\n**/*.md\n" File.write(File.join(@target_path,'.yardopts'),cont) end |
#rev_gemspec ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/hiki2yard.rb', line 78 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
49 50 51 52 53 54 55 56 57 |
# File 'lib/hiki2yard.rb', line 49 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 |