index_html 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cef5f51ce2aef98cd6e1699a0d4b969520f480ec
4
- data.tar.gz: 00f09303310e5b48cc8ff713880c3095ff8c30ae
3
+ metadata.gz: 1f1e275104533fdf5d31bce94ed3604e4d7f6c75
4
+ data.tar.gz: cd24d5b692d85bb9421adccd471a16d520e68918
5
5
  SHA512:
6
- metadata.gz: 46795df6c4a05c1e80d61f5e8da773f8063006bf9ebe07518e8d9fdd98bde909f980fd32c2f4c60c4aaa3940f16b781a90c88a217daeefb1507a8a1944f05979
7
- data.tar.gz: 3d63e1daebd16bbec285d9e335b95c97c526f5c32fa49d4c267628bc06462dbac14da74bf0877566ec3f47dccd022e597e46586e8d6e3020452c029e8be34f1f
6
+ metadata.gz: 80882e01cc3b38f3227b59dbb057e40e9c3e0724e068f3a59845e55dab2e3196046f7ebaede003439013abc8fb173e77093a1a1ea82681798422188d6bb58496
7
+ data.tar.gz: 57c19489171279480889d448c1fe0917f39377ec5d1d9f3076300e53156e351b7d11775a1d6b3f14d3652119457d26ccfe7bcc115de8963ecee029e30b101553
data/README.md CHANGED
@@ -80,14 +80,14 @@ The output file `index.html` should be generated with something like
80
80
  <header>File List</header>
81
81
  <body>
82
82
  <ol>
83
- <li><a href="spec/fixtures/demo1.xxx.java" target="_blank">spec/fixtures/demo1.xxx.java</li>
84
- <li><a href="spec/fixtures/demo1.xxx.rb" target="_blank">spec/fixtures/demo1.xxx.rb</li>
85
- <li><a href="spec/fixtures/demo2.xxx.java" target="_blank">spec/fixtures/demo2.xxx.java</li>
86
- <li><a href="spec/fixtures/demo2.xxx.rb" target="_blank">spec/fixtures/demo2.xxx.rb</li>
87
- <li><a href="spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">spec/fixtures/sub-dir/demo3.yyy.java</li>
88
- <li><a href="spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo3.yyy.rb</li>
89
- <li><a href="spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">spec/fixtures/sub-dir/demo4.yyy.java</li>
90
- <li><a href="spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo4.yyy.rb</li>
83
+ <li><a href="demo1.xxx.java" target="_blank">demo1.xxx.java</li>
84
+ <li><a href="demo1.xxx.rb" target="_blank">demo1.xxx.rb</li>
85
+ <li><a href="demo2.xxx.java" target="_blank">demo2.xxx.java</li>
86
+ <li><a href="demo2.xxx.rb" target="_blank">demo2.xxx.rb</li>
87
+ <li><a href="sub-dir/demo3.yyy.java" target="_blank">sub-dir/demo3.yyy.java</li>
88
+ <li><a href="sub-dir/demo3.yyy.rb" target="_blank">sub-dir/demo3.yyy.rb</li>
89
+ <li><a href="sub-dir/demo4.yyy.java" target="_blank">sub-dir/demo4.yyy.java</li>
90
+ <li><a href="sub-dir/demo4.yyy.rb" target="_blank">sub-dir/demo4.yyy.rb</li>
91
91
  </ol>
92
92
  </body>
93
93
  </html>
@@ -106,14 +106,14 @@ The output file `index.html` should be something like
106
106
  <header>File List</header>
107
107
  <body>
108
108
  <ol>
109
- <li><a href="http://localhost/spec/fixtures/demo1.xxx.java" target="_blank">spec/fixtures/demo1.xxx.java</li>
110
- <li><a href="http://localhost/spec/fixtures/demo1.xxx.rb" target="_blank">spec/fixtures/demo1.xxx.rb</li>
111
- <li><a href="http://localhost/spec/fixtures/demo2.xxx.java" target="_blank">spec/fixtures/demo2.xxx.java</li>
112
- <li><a href="http://localhost/spec/fixtures/demo2.xxx.rb" target="_blank">spec/fixtures/demo2.xxx.rb</li>
113
- <li><a href="http://localhost/spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">spec/fixtures/sub-dir/demo3.yyy.java</li>
114
- <li><a href="http://localhost/spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo3.yyy.rb</li>
115
- <li><a href="http://localhost/spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">spec/fixtures/sub-dir/demo4.yyy.java</li>
116
- <li><a href="http://localhost/spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo4.yyy.rb</li>
109
+ <li><a href="http://localhost/demo1.xxx.java" target="_blank">http://localhost/demo1.xxx.java</li>
110
+ <li><a href="http://localhost/demo1.xxx.rb" target="_blank">http://localhost/demo1.xxx.rb</li>
111
+ <li><a href="http://localhost/demo2.xxx.java" target="_blank">http://localhost/demo2.xxx.java</li>
112
+ <li><a href="http://localhost/demo2.xxx.rb" target="_blank"http://localhost/>demo2.xxx.rb</li>
113
+ <li><a href="http://localhost/sub-dir/demo3.yyy.java" target="_blank">http://localhost/sub-dir/demo3.yyy.java</li>
114
+ <li><a href="http://localhost/sub-dir/demo3.yyy.rb" target="_blank">http://localhost/sub-dir/demo3.yyy.rb</li>
115
+ <li><a href="http://localhost/sub-dir/demo4.yyy.java" target="_blank">http://localhost/sub-dir/demo4.yyy.java</li>
116
+ <li><a href="http://localhost/sub-dir/demo4.yyy.rb" target="_blank">http://localhost/sub-dir/demo4.yyy.rb</li>
117
117
  </ol>
118
118
  </body>
119
119
  </html>
@@ -121,6 +121,10 @@ The output file `index.html` should be something like
121
121
 
122
122
  ### Changelogs
123
123
 
124
+ #### 0.0.5
125
+
126
+ - Always make the url relative in `make_links` method.
127
+
124
128
  #### 0.0.4
125
129
 
126
130
  - Update code_lister to 0.0.6 for new option and fix the mistake in '-d' option
@@ -1,3 +1,3 @@
1
1
  module IndexHtml
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/index_html.rb CHANGED
@@ -29,22 +29,23 @@ module IndexHtml
29
29
  |</html>
30
30
  END
31
31
 
32
- # our options
33
32
  prefix = args.fetch(:prefix, "")
34
33
  indent = args.fetch(:indent, 6)
35
34
  output = args.fetch(:output, "index.html")
36
35
 
37
- # write the output to files
38
36
  File.open(output, "w") do |f|
39
37
  f.write(header)
40
- make_links(file_list, prefix: prefix).each { |i| f.write("#{' ' * indent}#{i}\n") }
38
+ # TODO: always use relative path to the current :base_name
39
+ links = make_links file_list, prefix: prefix, base_dir: args[:base_dir]
40
+
41
+ links.each { |i| f.write("#{' ' * indent}#{i}\n") }
41
42
  f.write(footer)
42
43
  end
43
44
  end
44
45
 
45
46
  # Transform the list of full path to list of base name
46
47
  #
47
- # @param [Array<String>] file_list if of file path
48
+ # @param [Array<String>] file_list input file list
48
49
  # @param [Hash<Symbol, Object>] args list of options
49
50
  #
50
51
  # @return [Array<String>] list of basename of a given input file
@@ -62,18 +63,36 @@ module IndexHtml
62
63
 
63
64
  # Make links using <li> tags
64
65
  #
65
- # @return [Array] the list of valid <li> tags
66
- def make_links(file_list, args = {})
66
+ # @param [Array<String>] file_list the input file list
67
+ # @param [Hash<Symbol,Object>] args the option hash
68
+ #
69
+ # @return [Array<String>] the list of valid <li> tags
70
+ def make_links(file_list, args)
71
+
67
72
  original_links = file_list
68
- escape_uris!(file_list, args)
69
- file_list = basenames!(file_list, args)
73
+
74
+ ## TODO: may be never need to escape at this point?
75
+ # escape_uris!(file_list, args)
76
+ # file_list = basenames!(file_list, args)
70
77
 
71
78
  prefix = args.fetch(:prefix, "")
79
+ base_dir = args[:base_dir]
72
80
 
73
81
  result = []
74
- original_links.zip(file_list).each do |i,j|
75
- result << %Q{<li><a href="#{prefix}#{j}" target="_blank">#{i}</li>}
82
+
83
+ ## Note: since we always use relative path, we don't need this code anymore!
84
+ # original_links.zip(file_list).each do |i,j|
85
+ # uri = j.gsub(base_dir,"")
86
+ # target = i.gsub(base_dir,"")
87
+ # result << %Q{<li><a href="#{prefix}#{uri}" target="_blank">#{target}</li>}
88
+ # end
89
+
90
+ original_links.each do |i|
91
+ uri = i.gsub(base_dir,"")
92
+ uri.gsub!(/^\//,"") # remove the '/' if we have one
93
+ result << %Q{<li><a href="#{prefix}#{uri}" target="_blank">#{prefix}#{uri}</li>}
76
94
  end
95
+
77
96
  result
78
97
  end
79
98
 
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require_relative '../spec_helper'
2
3
 
3
4
  describe IndexHtml do
@@ -28,7 +29,6 @@ describe IndexHtml do
28
29
  end
29
30
  end
30
31
 
31
- #TODO: add proper test here
32
32
  context '#htmlify' do
33
33
  let :files do
34
34
  CodeLister.files base_dir: 'spec/fixtures',
@@ -37,9 +37,11 @@ describe IndexHtml do
37
37
  end
38
38
 
39
39
  it 'generates simple index file' do
40
+ FileUtils.rm_rf('index.html')
40
41
  IndexHtml.htmlify files,
41
42
  indent: 6,
42
- output: 'index.html'
43
+ output: 'index.html',
44
+ base_dir: 'spec/fixtures'
43
45
  expect(capture(:stdout) { system('cat index.html') }).to eq \
44
46
  <<-EOT
45
47
  <html>
@@ -47,14 +49,14 @@ describe IndexHtml do
47
49
  <header>File List</header>
48
50
  <body>
49
51
  <ol>
50
- <li><a href="spec/fixtures/demo1.xxx.java" target="_blank">spec/fixtures/demo1.xxx.java</li>
51
- <li><a href="spec/fixtures/demo1.xxx.rb" target="_blank">spec/fixtures/demo1.xxx.rb</li>
52
- <li><a href="spec/fixtures/demo2.xxx.java" target="_blank">spec/fixtures/demo2.xxx.java</li>
53
- <li><a href="spec/fixtures/demo2.xxx.rb" target="_blank">spec/fixtures/demo2.xxx.rb</li>
54
- <li><a href="spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">spec/fixtures/sub-dir/demo3.yyy.java</li>
55
- <li><a href="spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo3.yyy.rb</li>
56
- <li><a href="spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">spec/fixtures/sub-dir/demo4.yyy.java</li>
57
- <li><a href="spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo4.yyy.rb</li>
52
+ <li><a href="demo1.xxx.java" target="_blank">demo1.xxx.java</li>
53
+ <li><a href="demo1.xxx.rb" target="_blank">demo1.xxx.rb</li>
54
+ <li><a href="demo2.xxx.java" target="_blank">demo2.xxx.java</li>
55
+ <li><a href="demo2.xxx.rb" target="_blank">demo2.xxx.rb</li>
56
+ <li><a href="sub-dir/demo3.yyy.java" target="_blank">sub-dir/demo3.yyy.java</li>
57
+ <li><a href="sub-dir/demo3.yyy.rb" target="_blank">sub-dir/demo3.yyy.rb</li>
58
+ <li><a href="sub-dir/demo4.yyy.java" target="_blank">sub-dir/demo4.yyy.java</li>
59
+ <li><a href="sub-dir/demo4.yyy.rb" target="_blank">sub-dir/demo4.yyy.rb</li>
58
60
  </ol>
59
61
  </body>
60
62
  </html>
@@ -62,10 +64,12 @@ describe IndexHtml do
62
64
  end
63
65
 
64
66
  it 'generates simple index file with prefix' do
67
+ FileUtils.rm_rf('index.html')
65
68
  IndexHtml.htmlify files,
66
69
  indent: 6,
67
70
  output: 'index.html',
68
- prefix: 'http://agilecreativity.com/'
71
+ prefix: 'http://agilecreativity.com/public/',
72
+ base_dir: 'spec/fixtures' # Note: must not puts the '/' at the end!
69
73
  expect(capture(:stdout) { system('cat index.html') }).to eq \
70
74
  <<-EOT
71
75
  <html>
@@ -73,18 +77,38 @@ describe IndexHtml do
73
77
  <header>File List</header>
74
78
  <body>
75
79
  <ol>
76
- <li><a href="http://agilecreativity.com/spec/fixtures/demo1.xxx.java" target="_blank">spec/fixtures/demo1.xxx.java</li>
77
- <li><a href="http://agilecreativity.com/spec/fixtures/demo1.xxx.rb" target="_blank">spec/fixtures/demo1.xxx.rb</li>
78
- <li><a href="http://agilecreativity.com/spec/fixtures/demo2.xxx.java" target="_blank">spec/fixtures/demo2.xxx.java</li>
79
- <li><a href="http://agilecreativity.com/spec/fixtures/demo2.xxx.rb" target="_blank">spec/fixtures/demo2.xxx.rb</li>
80
- <li><a href="http://agilecreativity.com/spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">spec/fixtures/sub-dir/demo3.yyy.java</li>
81
- <li><a href="http://agilecreativity.com/spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo3.yyy.rb</li>
82
- <li><a href="http://agilecreativity.com/spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">spec/fixtures/sub-dir/demo4.yyy.java</li>
83
- <li><a href="http://agilecreativity.com/spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">spec/fixtures/sub-dir/demo4.yyy.rb</li>
80
+ <li><a href="http://agilecreativity.com/public/demo1.xxx.java" target="_blank">http://agilecreativity.com/public/demo1.xxx.java</li>
81
+ <li><a href="http://agilecreativity.com/public/demo1.xxx.rb" target="_blank">http://agilecreativity.com/public/demo1.xxx.rb</li>
82
+ <li><a href="http://agilecreativity.com/public/demo2.xxx.java" target="_blank">http://agilecreativity.com/public/demo2.xxx.java</li>
83
+ <li><a href="http://agilecreativity.com/public/demo2.xxx.rb" target="_blank">http://agilecreativity.com/public/demo2.xxx.rb</li>
84
+ <li><a href="http://agilecreativity.com/public/sub-dir/demo3.yyy.java" target="_blank">http://agilecreativity.com/public/sub-dir/demo3.yyy.java</li>
85
+ <li><a href="http://agilecreativity.com/public/sub-dir/demo3.yyy.rb" target="_blank">http://agilecreativity.com/public/sub-dir/demo3.yyy.rb</li>
86
+ <li><a href="http://agilecreativity.com/public/sub-dir/demo4.yyy.java" target="_blank">http://agilecreativity.com/public/sub-dir/demo4.yyy.java</li>
87
+ <li><a href="http://agilecreativity.com/public/sub-dir/demo4.yyy.rb" target="_blank">http://agilecreativity.com/public/sub-dir/demo4.yyy.rb</li>
84
88
  </ol>
85
89
  </body>
86
90
  </html>
87
91
  EOT
88
92
  end
89
93
  end
94
+
95
+ context '#make_links' do
96
+ it 'works with prefix' do
97
+ result = IndexHtml.make_links files, base_dir: "spec/fixtures",
98
+ prefix: 'public/'
99
+ expect(capture(:stdout) { puts result }).to eq \
100
+ <<-EOT
101
+ <li><a href="public/demo1.xxx.rb" target="_blank">public/demo1.xxx.rb</li>
102
+ <li><a href="public/demo2.xxx.rb" target="_blank">public/demo2.xxx.rb</li>
103
+ EOT
104
+ end
105
+ it 'works without prefix' do
106
+ result = IndexHtml.make_links(files, base_dir: "spec/fixtures")
107
+ expect(capture(:stdout) { puts result }).to eq \
108
+ <<-EOT
109
+ <li><a href="demo1.xxx.rb" target="_blank">demo1.xxx.rb</li>
110
+ <li><a href="demo2.xxx.rb" target="_blank">demo2.xxx.rb</li>
111
+ EOT
112
+ end
113
+ end
90
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: index_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_lister