Module: IndexHtml
- Defined in:
- lib/index_html.rb,
lib/index_html/cli.rb,
lib/index_html/main.rb,
lib/index_html/version.rb
Defined Under Namespace
Constant Summary collapse
- CustomError =
Class.new(StandardError)
- VERSION =
"0.0.2"
Class Method Summary collapse
-
.basenames!(file_list, args = {}) ⇒ Array<String>
Transform the list of full path to list of base name.
- .escape_uris!(file_list, args = {}) ⇒ Object
-
.htmlify(file_list, args = {}) ⇒ Object
Create html links to list of files.
-
.make_links(file_list, args = {}) ⇒ Array
Make links using <li> tags.
Class Method Details
.basenames!(file_list, args = {}) ⇒ Array<String>
Transform the list of full path to list of base name
50 51 52 53 |
# File 'lib/index_html.rb', line 50 def basenames!(file_list, args = {}) file_list.map!{ |file| File.basename(file) } if args.fetch(:basename, false) file_list end |
.escape_uris!(file_list, args = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/index_html.rb', line 55 def escape_uris!(file_list, args = {}) if args.fetch(:encoded, false) file_list.map!{ |file| URI.escape(file, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) } end file_list end |
.htmlify(file_list, args = {}) ⇒ Object
Create html links to list of files
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/index_html.rb', line 15 def htmlify(file_list, args = {}) header = <<-END.gsub(/^\s+\|/, '') |<html> |<title>File Listing</title> |<header>File List</header> | <body> | <ol> END = <<-END.gsub(/^\s+\|/, '') | </ol> | </body> |</html> END # our options prefix = args.fetch(:prefix, "") indent = args.fetch(:indent, 6) output = args.fetch(:output, "index.html") # write the output to files File.open(output, "w") do |f| f.write(header) make_links(file_list, prefix: prefix).each { |i| f.write("#{' ' * indent}#{i}\n") } f.write() end end |
.make_links(file_list, args = {}) ⇒ Array
Make links using <li> tags
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/index_html.rb', line 65 def make_links(file_list, args = {}) original_links = file_list escape_uris!(file_list, args) file_list = basenames!(file_list, args) prefix = args.fetch(:prefix, "") result = [] original_links.zip(file_list).each do |i,j| result << %Q{<li><a href="#{prefix}#{j}" target="_blank">#{i}</li>} end result end |