index_html 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afb6c2824dec9ffb66110b2681969fc77b1cc9a6
4
- data.tar.gz: b341b80614a07e0368214ef5743643dcc3efd5d6
3
+ metadata.gz: b45984b36cf42d542ec7d1b4bb2eab064402ddce
4
+ data.tar.gz: 0a0488a4927fb09a53347b5bd08dca7950f03e43
5
5
  SHA512:
6
- metadata.gz: eee2f7e4ae7e86a4fa4e8232e9d82cfe64120516d9beb38aafc5fea0fbfa837a90931ea6b76b60db3b586e6bf5f10683213c288c44f5ea0126b2dc78c0dd4706
7
- data.tar.gz: 9a23e82ba4a79c8cdf2f61ddb729752461ed0fd719ca609baf9054c5a3a54fa0a575e2f1467679f8679065e30eedbb01330ab943e8a0fcb38c187bea2e624e98
6
+ metadata.gz: adf048c23932143d768bf64ca1ad1b4391c0088c227d12ea3d4ea63f30efc4f35ba47658fde588bb8de46b679be432a3985b31023c50f2620e7235e8d895df9a
7
+ data.tar.gz: 400502befa090eb221d227dcaca0e52f80043a747a640d771429e3f55d5bcec057afd9e75c5437c5176b711dbe1f02f923233e7f82db20bffca5752c13269c33
data/README.md CHANGED
@@ -70,7 +70,7 @@ This will generate the file `index.html` that you can open from your favourite b
70
70
  - Sample list of files from a given directory
71
71
 
72
72
  ```shell
73
- $html_index generate --base-dir=spec/fixtures --exts=rb java --recursive
73
+ $index_html generate --base-dir=spec/fixtures --exts=rb java --recursive
74
74
  ```
75
75
  The output file `index.html` should be generated with something like
76
76
 
@@ -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="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>
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>
91
91
  </ol>
92
92
  </body>
93
93
  </html>
@@ -95,7 +95,7 @@ The output file `index.html` should be generated with something like
95
95
  - Run with simple prefix option
96
96
 
97
97
  ```shell
98
- html_index generate --base-dir=spec/fixtures --exts=rb java --recursive --prefix=http://localhost/
98
+ index_html generate --base-dir spec/fixtures --exts rb java --recursive --prefix http://localhost/
99
99
  ```
100
100
 
101
101
  The output file `index.html` should be something like
@@ -106,21 +106,28 @@ 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/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>
109
+ <li><a href="http://localhost//spec/fixtures/demo1.xxx.java" target="_blank">http://localhost//spec/fixtures/demo1.xxx.java</li>
110
+ <li><a href="http://localhost//spec/fixtures/demo1.xxx.rb" target="_blank">http://localhost//spec/fixtures/demo1.xxx.rb</li>
111
+ <li><a href="http://localhost//spec/fixtures/demo2.xxx.java" target="_blank">http://localhost//spec/fixtures/demo2.xxx.java</li>
112
+ <li><a href="http://localhost//spec/fixtures/demo2.xxx.rb" target="_blank">http://localhost//spec/fixtures/demo2.xxx.rb</li>
113
+ <li><a href="http://localhost//spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">http://localhost//spec/fixtures/sub-dir/demo3.yyy.java</li>
114
+ <li><a href="http://localhost//spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">http://localhost//spec/fixtures/sub-dir/demo3.yyy.rb</li>
115
+ <li><a href="http://localhost//spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">http://localhost//spec/fixtures/sub-dir/demo4.yyy.java</li>
116
+ <li><a href="http://localhost//spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">http://localhost//spec/fixtures/sub-dir/demo4.yyy.rb</li>
117
117
  </ol>
118
118
  </body>
119
119
  </html>
120
120
  ```
121
+ ### Known Issues
122
+
123
+ - Will be listed here if any
121
124
 
122
125
  ### Changelogs
123
126
 
127
+ #### 0.0.7
128
+
129
+ - Fix the bug in 'make_links' logic to make it generate the link properly
130
+
124
131
  #### 0.0.6
125
132
 
126
133
  - Fix the Rakefile to include the correct library
@@ -11,7 +11,7 @@ module IndexHtml
11
11
  method_option :prefix,
12
12
  aliases: "-p",
13
13
  desc: "Prefix string to the URL",
14
- default: "" # empty string
14
+ default: "."
15
15
 
16
16
  method_option :indent,
17
17
  aliases: "-d",
@@ -4,6 +4,7 @@ module IndexHtml
4
4
  def run(options = {})
5
5
  files = CodeLister.files options || []
6
6
  unless files.empty?
7
+ puts "FYI: your options #{options}"
7
8
  IndexHtml.htmlify files, options
8
9
  puts "FYI: your result is in #{options[:output]}"
9
10
  else
@@ -1,3 +1,3 @@
1
1
  module IndexHtml
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/index_html.rb CHANGED
@@ -29,7 +29,7 @@ module IndexHtml
29
29
  |</html>
30
30
  END
31
31
 
32
- prefix = args.fetch(:prefix, "")
32
+ prefix = args.fetch(:prefix, ".")
33
33
  indent = args.fetch(:indent, 6)
34
34
  output = args.fetch(:output, "index.html")
35
35
 
@@ -67,28 +67,22 @@ module IndexHtml
67
67
  # @return [Array<String>] the list of valid <li> tags
68
68
  def make_links(file_list, args)
69
69
 
70
- original_links = file_list
70
+ prefix = args.fetch(:prefix, ".")
71
+ base_dir = args[:base_dir]
72
+ result = []
71
73
 
72
- ## TODO: may be never need to escape at this point?
73
- # escape_uris!(file_list, args)
74
- # file_list = basenames!(file_list, args)
74
+ file_list.each do |i|
75
75
 
76
- prefix = args.fetch(:prefix, "")
77
- base_dir = args[:base_dir]
76
+ path = File.absolute_path(i).gsub(Dir.pwd, "")
78
77
 
79
- result = []
78
+ if prefix
79
+ link = %Q{<li><a href="#{prefix}#{path}" target="_blank">#{prefix}#{path}</li>}
80
+ else
81
+ #TODO: may be we never get this condition?
82
+ link = %Q{<li><a href=".#{path}" target="_blank">#{path.gsub(/^\//,"")}</li>}
83
+ end
80
84
 
81
- ## Note: since we always use relative path, we don't need this code anymore!
82
- # original_links.zip(file_list).each do |i,j|
83
- # uri = j.gsub(base_dir,"")
84
- # target = i.gsub(base_dir,"")
85
- # result << %Q{<li><a href="#{prefix}#{uri}" target="_blank">#{target}</li>}
86
- # end
87
-
88
- original_links.each do |i|
89
- uri = i.gsub(base_dir,"")
90
- uri.gsub!(/^\//,"") # remove the '/' if we have one
91
- result << %Q{<li><a href="#{prefix}#{uri}" target="_blank">#{prefix}#{uri}</li>}
85
+ result << link
92
86
  end
93
87
 
94
88
  result
@@ -49,14 +49,14 @@ describe IndexHtml do
49
49
  <header>File List</header>
50
50
  <body>
51
51
  <ol>
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>
52
+ <li><a href="./spec/fixtures/demo1.xxx.java" target="_blank">./spec/fixtures/demo1.xxx.java</li>
53
+ <li><a href="./spec/fixtures/demo1.xxx.rb" target="_blank">./spec/fixtures/demo1.xxx.rb</li>
54
+ <li><a href="./spec/fixtures/demo2.xxx.java" target="_blank">./spec/fixtures/demo2.xxx.java</li>
55
+ <li><a href="./spec/fixtures/demo2.xxx.rb" target="_blank">./spec/fixtures/demo2.xxx.rb</li>
56
+ <li><a href="./spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">./spec/fixtures/sub-dir/demo3.yyy.java</li>
57
+ <li><a href="./spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">./spec/fixtures/sub-dir/demo3.yyy.rb</li>
58
+ <li><a href="./spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">./spec/fixtures/sub-dir/demo4.yyy.java</li>
59
+ <li><a href="./spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">./spec/fixtures/sub-dir/demo4.yyy.rb</li>
60
60
  </ol>
61
61
  </body>
62
62
  </html>
@@ -68,7 +68,7 @@ describe IndexHtml do
68
68
  IndexHtml.htmlify files,
69
69
  indent: 6,
70
70
  output: 'index.html',
71
- prefix: 'http://agilecreativity.com/public/',
71
+ prefix: 'http://agilecreativity.com/public',
72
72
  base_dir: 'spec/fixtures' # Note: must not puts the '/' at the end!
73
73
  expect(capture(:stdout) { system('cat index.html') }).to eq \
74
74
  <<-EOT
@@ -77,14 +77,14 @@ describe IndexHtml do
77
77
  <header>File List</header>
78
78
  <body>
79
79
  <ol>
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>
80
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/demo1.xxx.java" target="_blank">http://agilecreativity.com/public/spec/fixtures/demo1.xxx.java</li>
81
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/demo1.xxx.rb" target="_blank">http://agilecreativity.com/public/spec/fixtures/demo1.xxx.rb</li>
82
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/demo2.xxx.java" target="_blank">http://agilecreativity.com/public/spec/fixtures/demo2.xxx.java</li>
83
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/demo2.xxx.rb" target="_blank">http://agilecreativity.com/public/spec/fixtures/demo2.xxx.rb</li>
84
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/sub-dir/demo3.yyy.java" target="_blank">http://agilecreativity.com/public/spec/fixtures/sub-dir/demo3.yyy.java</li>
85
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/sub-dir/demo3.yyy.rb" target="_blank">http://agilecreativity.com/public/spec/fixtures/sub-dir/demo3.yyy.rb</li>
86
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/sub-dir/demo4.yyy.java" target="_blank">http://agilecreativity.com/public/spec/fixtures/sub-dir/demo4.yyy.java</li>
87
+ <li><a href="http://agilecreativity.com/public/spec/fixtures/sub-dir/demo4.yyy.rb" target="_blank">http://agilecreativity.com/public/spec/fixtures/sub-dir/demo4.yyy.rb</li>
88
88
  </ol>
89
89
  </body>
90
90
  </html>
@@ -94,21 +94,44 @@ describe IndexHtml do
94
94
 
95
95
  context '#make_links' do
96
96
  it 'works with prefix' do
97
- result = IndexHtml.make_links files, base_dir: "spec/fixtures",
98
- prefix: 'public/'
97
+ result = IndexHtml.make_links files, base_dir: "spec/fixtures", prefix: 'public'
99
98
  expect(capture(:stdout) { puts result }).to eq \
100
99
  <<-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>
100
+ <li><a href="public/spec/fixtures/demo1.xxx.rb" target="_blank">public/spec/fixtures/demo1.xxx.rb</li>
101
+ <li><a href="public/spec/fixtures/demo2.xxx.rb" target="_blank">public/spec/fixtures/demo2.xxx.rb</li>
103
102
  EOT
104
103
  end
104
+
105
105
  it 'works without prefix' do
106
106
  result = IndexHtml.make_links(files, base_dir: "spec/fixtures")
107
107
  expect(capture(:stdout) { puts result }).to eq \
108
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>
109
+ <li><a href="./spec/fixtures/demo1.xxx.rb" target="_blank">./spec/fixtures/demo1.xxx.rb</li>
110
+ <li><a href="./spec/fixtures/demo2.xxx.rb" target="_blank">./spec/fixtures/demo2.xxx.rb</li>
111
+ EOT
112
+ end
113
+
114
+ it 'works with base_dir starting with dot' do
115
+ files = CodeLister.files base_dir: './spec/fixtures',
116
+ exts: %w(xxx.rb), recursive: true
117
+ result = IndexHtml.make_links(files, base_dir: "./spec/fixtures/")
118
+ expect(capture(:stdout) { puts result }).to eq \
119
+ <<-EOT
120
+ <li><a href="./spec/fixtures/demo1.xxx.rb" target="_blank">./spec/fixtures/demo1.xxx.rb</li>
121
+ <li><a href="./spec/fixtures/demo2.xxx.rb" target="_blank">./spec/fixtures/demo2.xxx.rb</li>
111
122
  EOT
112
123
  end
124
+
125
+ it 'works with base_dir not starting with dot' do
126
+ files = CodeLister.files base_dir: 'spec/fixtures',
127
+ exts: %w(xxx.rb), recursive: true
128
+ result = IndexHtml.make_links(files, base_dir: "spec/fixtures/")
129
+ expect(capture(:stdout) { puts result }).to eq \
130
+ <<-EOT
131
+ <li><a href="./spec/fixtures/demo1.xxx.rb" target="_blank">./spec/fixtures/demo1.xxx.rb</li>
132
+ <li><a href="./spec/fixtures/demo2.xxx.rb" target="_blank">./spec/fixtures/demo2.xxx.rb</li>
133
+ EOT
134
+ end
135
+
113
136
  end
114
137
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: index_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan