Module: HamlHelpers

Included in:
Machinery::StaticHtml, Server::Helpers
Defined in:
lib/haml_helpers.rb

Overview

Copyright © 2013-2016 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Method Summary collapse

Instance Method Details



53
54
55
56
57
58
59
# File 'lib/haml_helpers.rb', line 53

def nav_class(scope)
  if @description
    return @description[scope] ? "" : "disabled"
  elsif @description_a && @description_b
    return @description_a[scope] && @description_b[scope] ? "" : "disabled"
  end
end

#render_partial(partial, locals = {}) ⇒ Object



19
20
21
22
# File 'lib/haml_helpers.rb', line 19

def render_partial(partial, locals = {})
  source = File.read(File.join(Machinery::ROOT, "html/partials/#{partial}.html.haml"))
  haml source, locals: locals
end

#render_scope(scope) ⇒ Object



24
25
26
# File 'lib/haml_helpers.rb', line 24

def render_scope(scope)
  render_partial scope, scope => @description[scope]
end

#scope_help(scope) ⇒ Object



36
37
38
39
# File 'lib/haml_helpers.rb', line 36

def scope_help(scope)
  text = scope_info(scope)[:description]
  Kramdown::Document.new(text).to_html
end

#scope_info(scope) ⇒ Object



41
42
43
# File 'lib/haml_helpers.rb', line 41

def scope_info(scope)
  YAML.load(File.read(File.join(Machinery::ROOT, "plugins", "#{scope}/#{scope}.yml")))
end

#scope_initials(scope) ⇒ Object



49
50
51
# File 'lib/haml_helpers.rb', line 49

def scope_initials(scope)
  scope_info(scope)[:initials].upcase
end

#scope_meta_info(scope) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/haml_helpers.rb', line 28

def scope_meta_info(scope)
  return "" unless @description[scope]

  " (" \
    "inspected host: '#{@description[scope].meta.hostname}', " \
    "at: #{DateTime.parse(@description[scope].meta.modified).strftime("%F %T")})"
end

#scope_title(scope) ⇒ Object



45
46
47
# File 'lib/haml_helpers.rb', line 45

def scope_title(scope)
  scope_info(scope)[:name]
end