Module: Guides::Helpers

Defined in:
lib/guides/helpers.rb

Instance Method Summary collapse

Instance Method Details

#all_guidesObject


27
28
29
30
31
32
33
# File 'lib/guides/helpers.rb', line 27

def all_guides
  Guides.meta["index"].inject({}) do |ret, (section, items)|
    items = items.reject{|item| item['construction'] } if is_production?
    ret[section] = items unless items.empty?
    ret
  end
end

#author(name, nick, image = 'credits_pic_blank.gif', &block) ⇒ Object


47
48
49
50
51
52
53
54
# File 'lib/guides/helpers.rb', line 47

def author(name, nick, image = 'credits_pic_blank.gif', &block)
  image = "images/#{image}" unless image =~ /^http/

  result = (:img, nil, :src => image, :class => 'left pic', :alt => name)
  result << (:h3, name)
  result << (:p, capture(&block))
  (:div, result, :class => 'author clearfix', :id => nick)
end

#clickable_indexObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/guides/helpers.rb', line 3

def clickable_index
  total_guides = all_guides.inject(0) do |sum, (name, guides)|
    sum + guides.size
  end

  lgroup, rgroup, counted_guides = {}, {}, 0

  all_guides.each do |name, guides|
    if counted_guides > (total_guides / 2.0)
      rgroup[name] = guides
    else
      lgroup[name] = guides
    end

    counted_guides += guides.size
  end

  render "clickable_index", :lgroup => lgroup, :rgroup => rgroup
end

#code(&block) ⇒ Object


56
57
58
59
# File 'lib/guides/helpers.rb', line 56

def code(&block)
  c = capture(&block)
  (:code, c)
end

#guide(name, url, options = {}, &block) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/guides/helpers.rb', line 35

def guide(name, url, options = {}, &block)
  link = (:a, :href => url) { name }
  result = (:dt, link)

  if options[:work_in_progress]
    result << (:dd, 'Work in progress', :class => 'work-in-progress')
  end

  result << (:dd, capture(&block))
  result
end

76
77
78
79
80
81
82
83
# File 'lib/guides/helpers.rb', line 76

def guide_chapter_link(guide, chapter)
  if guide_exists?(guide)
    anchor = chapter.gsub(/\s/, '-').downcase
    link_to(chapter, "#{guide["url"]}.html##{anchor}")
  else
    chapter
  end
end

#guide_exists?(guide) ⇒ Boolean

Returns:

  • (Boolean)

61
62
63
64
65
66
# File 'lib/guides/helpers.rb', line 61

def guide_exists?(guide)
  # Might be able to use build in view_paths methods but I couldn't figure them out - PW
  view_paths.any? do |p|
    Guides::Generator::EXTENSIONS.any?{|e| File.exist? "#{p}/#{guide["url"]}.#{e}" }
  end
end

68
69
70
71
72
73
74
# File 'lib/guides/helpers.rb', line 68

def guide_link(guide)
  if guide_exists?(guide)
    link_to guide["title"], "#{guide["url"]}.html"
  else
    guide["title"]
  end
end

#is_production?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/guides/helpers.rb', line 23

def is_production?
  assigns[:production]
end