Class: RSpecDocumentation::Util
- Inherits:
-
Object
- Object
- RSpecDocumentation::Util
- Defined in:
- lib/rspec_documentation/util.rb
Overview
Misc utility classes for functionality shared between components, helpers for path normalization.
Constant Summary collapse
- ORDERING_PREFIX_REGEXP =
/^[0-9]+-/.freeze
Class Method Summary collapse
- .assets_root ⇒ Object
- .base_dir ⇒ Object
- .bundle_dir ⇒ Object
- .bundle_index_path ⇒ Object
- .bundle_path(path) ⇒ Object
- .href(path) ⇒ Object
- .label(path) ⇒ Object
- .normalized_filename(path) ⇒ Object
- .path_id(path) ⇒ Object
- .root_dir ⇒ Object
- .spec_helper_path ⇒ Object
- .tokens(path) ⇒ Object
- .url_root ⇒ Object
Class Method Details
.assets_root ⇒ Object
58 59 60 |
# File 'lib/rspec_documentation/util.rb', line 58 def self.assets_root url_root.join('assets') end |
.base_dir ⇒ Object
21 22 23 |
# File 'lib/rspec_documentation/util.rb', line 21 def self.base_dir root_dir.join('rspec-documentation', 'pages') end |
.bundle_dir ⇒ Object
25 26 27 28 29 |
# File 'lib/rspec_documentation/util.rb', line 25 def self.bundle_dir return root_dir.join('rspec-documentation', 'bundle') unless ENV.key?('RSPEC_DOCUMENTATION_BUNDLE_PATH') Pathname.new(ENV.fetch('RSPEC_DOCUMENTATION_BUNDLE_PATH')) end |
.bundle_index_path ⇒ Object
13 14 15 |
# File 'lib/rspec_documentation/util.rb', line 13 def self.bundle_index_path bundle_dir.join('index.html') end |
.bundle_path(path) ⇒ Object
8 9 10 11 |
# File 'lib/rspec_documentation/util.rb', line 8 def self.bundle_path(path) relative_path = Pathname.new(path).relative_path_from(base_dir) bundle_dir.join(*relative_path.split.map { |segment| normalized_filename(segment) }).sub_ext('.html') end |
.href(path) ⇒ Object
47 48 49 50 |
# File 'lib/rspec_documentation/util.rb', line 47 def self.href(path) relative_path = Pathname.new(path).relative_path_from(base_dir) url_root.join(*relative_path.split.map { |segment| normalized_filename(segment) }).sub_ext('.html') end |
.label(path) ⇒ Object
35 36 37 |
# File 'lib/rspec_documentation/util.rb', line 35 def self.label(path) Pathname.new(path).basename.sub_ext('').sub(ORDERING_PREFIX_REGEXP, '').to_s end |
.normalized_filename(path) ⇒ Object
62 63 64 65 66 |
# File 'lib/rspec_documentation/util.rb', line 62 def self.normalized_filename(path) path.split.map do |segment| segment.to_s.gsub(' ', '-').downcase.sub(ORDERING_PREFIX_REGEXP, '') end.join('/') end |
.path_id(path) ⇒ Object
43 44 45 |
# File 'lib/rspec_documentation/util.rb', line 43 def self.path_id(path) "path-id-#{Digest::SHA256.hexdigest(bundle_path(path).relative_path_from(bundle_dir).to_s)}" end |
.root_dir ⇒ Object
31 32 33 |
# File 'lib/rspec_documentation/util.rb', line 31 def self.root_dir Pathname.new(Dir.pwd) end |
.spec_helper_path ⇒ Object
17 18 19 |
# File 'lib/rspec_documentation/util.rb', line 17 def self.spec_helper_path root_dir.join('rspec-documentation/spec_helper.rb') end |
.tokens(path) ⇒ Object
39 40 41 |
# File 'lib/rspec_documentation/util.rb', line 39 def self.tokens(path) label(path).downcase.split end |
.url_root ⇒ Object
52 53 54 55 56 |
# File 'lib/rspec_documentation/util.rb', line 52 def self.url_root return bundle_dir unless ENV.key?('RSPEC_DOCUMENTATION_URL_ROOT') Pathname.new(ENV.fetch('RSPEC_DOCUMENTATION_URL_ROOT')) end |