Module: Origen::Generator::Compiler::DocHelpers::SearchableHelpers

Included in:
Origen::Generator::Compiler::DocHelpers
Defined in:
lib/origen_doc_helpers/helpers.rb

Overview

Helpers for the searchable doc layout

Instance Method Summary collapse

Instance Method Details

#_doc_root_dir(options) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/origen_doc_helpers/helpers.rb', line 255

def _doc_root_dir(options)
  f = options[:root]
  @_doc_root_dirs ||= {}
  return @_doc_root_dirs[f] if @_doc_root_dirs[f]
  unless File.exist?(f)
    if File.exist?("#{Origen.root}/app/")
      f = Pathname.new("#{Origen.root}/app/templates/web/#{f}")
    else
      f = Pathname.new("#{Origen.root}/templates/web/#{f}")
    end
    unless f.exist?
      fail "#{options[:root]} does not exist!"
    end
  end
  f = Pathname.new(f) if f.is_a?(String)
  @_doc_root_dirs[options[:root]] = f
end

#_resolve_tab(options) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/origen_doc_helpers/helpers.rb', line 273

def _resolve_tab(options)
  tab = tab.to_s.downcase
  active = false
  if options[:tab]
    options[:tab]
  else
    rel = begin
        options[:top_level_file].relative_path_from(_doc_root_dir(options)).sub_ext('').sub_ext('').to_s
      rescue
        '..'
      end
    # If the file lives outside of the current app (e.g. it comes from a plugin), then the above approach
    # doesn't work, so let's just take the last dirname and the filename
    if rel =~ /\.\./
      dir = options[:top_level_file].dirname.basename
      file = options[:top_level_file].basename('.*').basename('.*')  # twice to allow for my_file.md.erb
      rel = "#{dir}_#{file}"
    end
    rel.gsub(/(\/|\\)/, '_').downcase.to_sym
  end
end

#_root_path(options) ⇒ Object



295
296
297
298
299
300
301
302
# File 'lib/origen_doc_helpers/helpers.rb', line 295

def _root_path(options)
  if File.exist?("#{Origen.root}/app/templates/web")
    root = Pathname.new("#{Origen.root}/app/templates/web")
  else
    root = Pathname.new("#{Origen.root}/templates/web")
  end
  _doc_root_dir(options).relative_path_from(root)
end