Module: Help

Included in:
App
Defined in:
lib/nu/help/help.rb

Instance Method Summary collapse

Instance Method Details

#filter_markdown(from) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nu/help/help.rb', line 32

def filter_markdown(from)
	#links
	from.gsub!(/\[\[(.*)\|.*\]\]/,'\1')
	from.gsub!(/\[\[(.*)\]\]/,'\1')
	
	#word wrap
	col = 80
	from.gsub!(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,"\\1\\3\n")
	
	return from
end

#help_doc_for(descriptor) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nu/help/help.rb', line 10

def help_doc_for(descriptor)
	log "help_doc_for called: descriptor: #{descriptor.inspect}"
	
	if descriptor.is_a?(String)
		descriptor.downcase!
		descriptor_description = descriptor.gsub(/-/, ": ")
	end
	
	if descriptor.is_a?(Array)
		descriptor.map!{|item| item.downcase}
		descriptor_description = descriptor.join(': ')
		descriptor = descriptor.join('-')
	end
	
	file_path = File.join(help_doc_path, descriptor + ".md")
	log "Looking for file at: #{file_path}"
	
	return "No help found for \"#{descriptor_description}\"" unless File.exists?(file_path)
	
	filter_markdown(IO.read(file_path))
end

#help_doc_pathObject



5
6
7
8
# File 'lib/nu/help/help.rb', line 5

def help_doc_path
	gtool = Nu::GemTools.new
	File.expand_path(File.join(gtool.spec_for('nu').full_gem_path,'docs'))
end