index_html 0.2.3 → 0.2.4

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: a7b776cb63b00982e749761e9d52b4aed324408d
4
- data.tar.gz: 31aa65091d74f4135ad13dcdf1023eb933a526a4
3
+ metadata.gz: 6af345c57730f78e986067d187096c58f01b6611
4
+ data.tar.gz: 689614e980a258929a497b5c1d563f1ea455a56e
5
5
  SHA512:
6
- metadata.gz: 0092576780534fb541ce155c54fc05e32a19a9b43b0be1ab4d09d9480f232b4af4e139c02cbd58c19356d090547f8a4dacca3b86616843587ef103ed8b85b66c
7
- data.tar.gz: cbc246c08491b6d7d1a44d7e982daa815edad89cfb4c96376e228311b6ed39c5f29ef91aa95927da012802af31349a59e3e443cec37b3169b4d265a100c4f725
6
+ metadata.gz: 547b5ffd227a1e3bb0afa28db3a1b99134d6a29f510d2fd72f5347b53da959b91ad9114e8e11ad59e63455e2d67a7a0ad67db434be73a6e2ed75cee63ed00b0e
7
+ data.tar.gz: 650a36ec7c9262711194801219095cc78960ffb9e14c33fcb29119e6a2f8733671c8e9bb6df6086cd03fdd3da544915b4fb48fb8239c6c6a36c1e3cc4ebbdc41
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ### Changelogs
2
2
 
3
+ #### 0.2.4
4
+
5
+ - Use require instead of require_relative
6
+ - Misc code cleanup
7
+
3
8
  #### 0.2.3
4
9
 
5
10
  - Make it possible to remove the last extension from the link for `vim_printer`
data/bin/index_html CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require "code_lister"
3
2
  require_relative "../lib/index_html"
4
3
  include IndexHtml
5
4
  if ARGV.empty?
data/index_html.gemspec CHANGED
@@ -2,7 +2,6 @@
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "index_html/version"
5
-
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "index_html"
8
7
  spec.version = IndexHtml::VERSION
@@ -24,11 +23,9 @@ Gem::Specification.new do |spec|
24
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
25
  spec.require_paths = ["lib"]
27
-
28
- spec.add_runtime_dependency "agile_utils", "~> 0.2.2"
29
- spec.add_runtime_dependency "code_lister", "~> 0.2.2"
26
+ spec.add_runtime_dependency "agile_utils", "~> 0.2.3"
27
+ spec.add_runtime_dependency "code_lister", "~> 0.2.4"
30
28
  spec.add_runtime_dependency "thor", "~> 0.19.1"
31
-
32
29
  spec.add_development_dependency "awesome_print", "~> 1.2.0"
33
30
  spec.add_development_dependency "bundler", "~> 1.7.3"
34
31
  spec.add_development_dependency "coveralls", "~> 0.7.0"
@@ -37,6 +34,6 @@ Gem::Specification.new do |spec|
37
34
  spec.add_development_dependency "pry", "~> 0.10.0"
38
35
  spec.add_development_dependency "pry-byebug", "~> 2.0.0" if RUBY_VERSION >= "2.0.0"
39
36
  spec.add_development_dependency "rake", "~> 10.3.2"
40
- spec.add_development_dependency "rspec", "~> 3.0.0"
37
+ spec.add_development_dependency "rspec", "~> 3.1.0"
41
38
  spec.add_development_dependency "rubocop", "~> 0.26.1"
42
39
  end
@@ -1,6 +1,3 @@
1
- require "thor"
2
- require "agile_utils"
3
- require_relative "../index_html"
4
1
  module IndexHtml
5
2
  class CLI < Thor
6
3
  # rubocop:disable AmbiguousOperator, LineLength
@@ -0,0 +1,112 @@
1
+ module IndexHtml
2
+ CustomError = Class.new(StandardError)
3
+ class << self
4
+ # Create html links for a given list of files
5
+ #
6
+ # @param [Array<String>] file_list list of input file
7
+ # @param [Hash<Synbol, Object>] args the argument hash
8
+ def htmlify(file_list, args = {})
9
+ header = <<-END.gsub(/^\s+\|/, "")
10
+ |<html>
11
+ |<title>File Listing</title>
12
+ |<header>File List</header>
13
+ | <body>
14
+ | <ol>
15
+ END
16
+
17
+ footer = <<-END.gsub(/^\s+\|/, "")
18
+ | </ol>
19
+ | </body>
20
+ |</html>
21
+ END
22
+
23
+ indent = args.fetch(:indent, 6)
24
+ output = args.fetch(:output, "index.html")
25
+
26
+ File.open(output, "w") do |file|
27
+ file.write(header)
28
+ links = make_links file_list, prefix: args.fetch(:prefix, ".") ,
29
+ base_dir: args[:base_dir],
30
+ drop_ext: args.fetch(:drop_ext, false)
31
+ links.each { |link| file.write("#{" " * indent}#{link}\n") }
32
+ file.write(footer)
33
+ end
34
+ end
35
+
36
+ # Transform the list of full path to list of base name
37
+ #
38
+ # @param [Array<String>] file_list input file list
39
+ # @param [Hash<Symbol, Object>] args list of options
40
+ #
41
+ # @return [Array<String>] list of basename of a given input file
42
+ def basenames!(file_list, args = {})
43
+ file_list.map! { |file| File.basename(file) } if args.fetch(:basename, false)
44
+ file_list
45
+ end
46
+
47
+ def escape_uris!(file_list, args = {})
48
+ if args.fetch(:encoded, false)
49
+ file_list.map! { |file| URI.escape(file, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) }
50
+ end
51
+ file_list
52
+ end
53
+
54
+ # Make links using <li> tags
55
+ #
56
+ # @param [Array<String>] file_list the input file list
57
+ # @param [Hash<Symbol,Object>] args the option hash
58
+ #
59
+ # @return [Array<String>] the list of valid <li> tags
60
+ def make_links(file_list, args)
61
+ prefix = args.fetch(:prefix, ".")
62
+ drop_ext = args.fetch(:drop_ext, false)
63
+ result = []
64
+ file_list.each do |file|
65
+ path = File.absolute_path(file).gsub(Dir.pwd, "")
66
+ if prefix
67
+ # link = %Q(<li><a href="#{prefix}#{drop_ext ? drop_extension(path): path}" target='_blank'>#{prefix}#{path}</li>)
68
+ link = %Q(<li><a href="#{prefix}#{path}" target='_blank'>#{prefix}#{drop_last_ext(path, drop_ext)}</li>)
69
+ else
70
+ # add "." in front of the link and drop the last extension
71
+ # link = %Q(<li><a href=".#{drop_ext ? drop_extension(path) : path}" target='_blank'>#{path.gsub(/^\//, "")}</li>)
72
+ # at this point path always start with "/"
73
+ link = %Q(<li><a href=".#{path}" target='_blank'>#{drop_last_ext(path.gsub(/^\//, ""), drop_ext)}</li>)
74
+ end
75
+ result << link
76
+ end
77
+ result
78
+ end
79
+
80
+ # Wrapper method to call the drop_extension if applicable
81
+ #
82
+ # @param [String] link the input link
83
+ # @param [Boolean] flag the boolean flag
84
+ # @return (see #drop_extension)
85
+ def drop_last_ext(link, flag = false)
86
+ if flag
87
+ drop_extension(link)
88
+ else
89
+ link
90
+ end
91
+ end
92
+
93
+ # Drop string after the last '.' dot string if any
94
+ #
95
+ # @param [String] link the input link
96
+ # @return [String] the new string with extension drop if any
97
+ # @example
98
+ # drop_extension("some_file") == "some_file"
99
+ # drop_extension("some_file.txt") == "some_file"
100
+ # drop_extension("/path/to/some_file") == "/path/to/some_file"
101
+ # drop_extension("/path/to/some_file.txt") == "/path/to/some_file"
102
+ # drop_extension("/path/to/some_file.txt.pdf") == "/path/to/some_file.txt"
103
+ def drop_extension(link)
104
+ dot_index = link.rindex(".")
105
+ if dot_index
106
+ link[0..(dot_index - 1)]
107
+ else
108
+ link
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,3 +1,3 @@
1
1
  module IndexHtml
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/index_html.rb CHANGED
@@ -1,116 +1,11 @@
1
1
  require "uri"
2
+ require "thor"
3
+ require "fileutils"
4
+ require "agile_utils"
2
5
  require "code_lister"
3
- require_relative "./index_html/version"
4
- require_relative "./index_html/cli"
5
- module IndexHtml
6
- CustomError = Class.new(StandardError)
7
- class << self
8
- # Create html links for a given list of files
9
- #
10
- # @param [Array<String>] file_list list of input file
11
- # @param [Hash<Synbol, Object>] args the argument hash
12
- def htmlify(file_list, args = {})
13
- header = <<-END.gsub(/^\s+\|/, "")
14
- |<html>
15
- |<title>File Listing</title>
16
- |<header>File List</header>
17
- | <body>
18
- | <ol>
19
- END
6
+ require "index_html/version"
7
+ require "index_html/cli"
8
+ require "index_html/index_html"
20
9
 
21
- footer = <<-END.gsub(/^\s+\|/, "")
22
- | </ol>
23
- | </body>
24
- |</html>
25
- END
26
-
27
- indent = args.fetch(:indent, 6)
28
- output = args.fetch(:output, "index.html")
29
-
30
- File.open(output, "w") do |file|
31
- file.write(header)
32
- links = make_links file_list, prefix: args.fetch(:prefix, ".") ,
33
- base_dir: args[:base_dir],
34
- drop_ext: args.fetch(:drop_ext, false)
35
- links.each { |link| file.write("#{" " * indent}#{link}\n") }
36
- file.write(footer)
37
- end
38
- end
39
-
40
- # Transform the list of full path to list of base name
41
- #
42
- # @param [Array<String>] file_list input file list
43
- # @param [Hash<Symbol, Object>] args list of options
44
- #
45
- # @return [Array<String>] list of basename of a given input file
46
- def basenames!(file_list, args = {})
47
- file_list.map! { |file| File.basename(file) } if args.fetch(:basename, false)
48
- file_list
49
- end
50
-
51
- def escape_uris!(file_list, args = {})
52
- if args.fetch(:encoded, false)
53
- file_list.map! { |file| URI.escape(file, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) }
54
- end
55
- file_list
56
- end
57
-
58
- # Make links using <li> tags
59
- #
60
- # @param [Array<String>] file_list the input file list
61
- # @param [Hash<Symbol,Object>] args the option hash
62
- #
63
- # @return [Array<String>] the list of valid <li> tags
64
- def make_links(file_list, args)
65
- prefix = args.fetch(:prefix, ".")
66
- drop_ext = args.fetch(:drop_ext, false)
67
- result = []
68
- file_list.each do |file|
69
- path = File.absolute_path(file).gsub(Dir.pwd, "")
70
- if prefix
71
- # link = %Q(<li><a href="#{prefix}#{drop_ext ? drop_extension(path): path}" target='_blank'>#{prefix}#{path}</li>)
72
- link = %Q(<li><a href="#{prefix}#{path}" target='_blank'>#{prefix}#{drop_last_ext(path, drop_ext)}</li>)
73
- else
74
- # add "." in front of the link and drop the last extension
75
- # link = %Q(<li><a href=".#{drop_ext ? drop_extension(path) : path}" target='_blank'>#{path.gsub(/^\//, "")}</li>)
76
- # at this point path always start with "/"
77
- link = %Q(<li><a href=".#{path}" target='_blank'>#{drop_last_ext(path.gsub(/^\//, ""), drop_ext)}</li>)
78
- end
79
- result << link
80
- end
81
- result
82
- end
83
-
84
- # Wrapper method to call the drop_extension if applicable
85
- #
86
- # @param [String] link the input link
87
- # @param [Boolean] flag the boolean flag
88
- # @return (see #drop_extension)
89
- def drop_last_ext(link, flag = false)
90
- if flag
91
- drop_extension(link)
92
- else
93
- link
94
- end
95
- end
96
-
97
- # Drop string after the last '.' dot string if any
98
- #
99
- # @param [String] link the input link
100
- # @return [String] the new string with extension drop if any
101
- # @example
102
- # drop_extension("some_file") == "some_file"
103
- # drop_extension("some_file.txt") == "some_file"
104
- # drop_extension("/path/to/some_file") == "/path/to/some_file"
105
- # drop_extension("/path/to/some_file.txt") == "/path/to/some_file"
106
- # drop_extension("/path/to/some_file.txt.pdf") == "/path/to/some_file.txt"
107
- def drop_extension(link)
108
- dot_index = link.rindex(".")
109
- if dot_index
110
- link[0..(dot_index - 1)]
111
- else
112
- link
113
- end
114
- end
115
- end
116
- end
10
+ include CodeLister
11
+ include IndexHtml
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.2.3
4
+ version: 0.2.4
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-09-25 00:00:00.000000000 Z
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: agile_utils
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.2
19
+ version: 0.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.2
26
+ version: 0.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: code_lister
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.2
33
+ version: 0.2.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.2
40
+ version: 0.2.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 3.0.0
173
+ version: 3.1.0
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 3.0.0
180
+ version: 3.1.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubocop
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -211,6 +211,7 @@ files:
211
211
  - index_html.gemspec
212
212
  - lib/index_html.rb
213
213
  - lib/index_html/cli.rb
214
+ - lib/index_html/index_html.rb
214
215
  - lib/index_html/version.rb
215
216
  homepage: https://github.com/agilecreativity/index_html
216
217
  licenses: