Module: InfoHelpers

Included in:
DocRenderer::Base
Defined in:
lib/paperwork/tasks/middleman_template/lib/info_helpers.rb

Overview

helpers for info fields in documents

Instance Method Summary collapse

Instance Method Details



60
61
62
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 60

def footer_text
    data.paperwork.footer if paperwork?
end

Returns:

  • (Boolean)


42
43
44
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 42

def navbar?
    paperwork? && data.paperwork.respond_to?(:navbar)
end


56
57
58
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 56

def navbar_brand
    data.paperwork.navbar.brand if navbar?
end


46
47
48
49
50
51
52
53
54
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 46

def navbar_links
    nav = data.paperwork.navbar.links if navbar?
    nav ||= {}
    mapped = {}
    nav.each do |name, link|
        mapped[name] = relative_link(link)
    end
    mapped
end

#page_info(**options) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 15

def page_info(**options)
    content_for :page_infos do
        options.keys.map do |name|
            partial("layouts/info", locals: { name: name, value: options[name] })
        end.join
    end
end

#paperwork?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 38

def paperwork?
    data.respond_to?(:paperwork)
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 23

def relative_link(stringifyable, current_path = current_page.path)
    relative = String.new
    dots = current_path.split(/[\/\\]/).size - 1
    dots.times{ relative += "../" }
    # This has been some nasty part to debug...
    # keep these comments for debugging session yet to come
    # puts "##################################"
    # puts "current_page.path: #{current_page.path}"
    # puts "stringifyable: #{stringifyable.to_s}"
    # puts "dots: #{dots}"
    # puts "relative link: #{relative + stringifyable.to_s}"
    # puts "##################################"
    relative + stringifyable.to_s
end

#text_for(**options) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 7

def text_for(**options)
    options.keys.map do |key|
        content_for key do
            options[key].to_s
        end
    end
end

#toc?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/paperwork/tasks/middleman_template/lib/info_helpers.rb', line 64

def toc?
    !data.paperwork.config.nil? &&
        !data.paperwork.config.toc.nil? &&
        data.paperwork.config.toc
end