Module: Guides::Helpers
- Defined in:
- lib/guides/helpers.rb
Instance Method Summary collapse
- #all_guides ⇒ Object
- #author(name, nick, image = 'credits_pic_blank.gif', &block) ⇒ Object
- #clickable_index ⇒ Object
- #code(&block) ⇒ Object
- #guide(name, url, options = {}, &block) ⇒ Object
- #guide_chapter_link(guide, chapter) ⇒ Object
- #guide_exists?(guide) ⇒ Boolean
- #guide_link(guide) ⇒ Object
- #is_production? ⇒ Boolean
Instance Method Details
#all_guides ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/guides/helpers.rb', line 27 def all_guides Guides.["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 (name, nick, image = 'credits_pic_blank.gif', &block) image = "images/#{image}" unless image =~ /^http/ result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name) result << content_tag(:h3, name) result << content_tag(:p, capture(&block)) content_tag(:div, result, :class => 'author clearfix', :id => nick) end |
#clickable_index ⇒ Object
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) content_tag(: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, = {}, &block) link = content_tag(:a, :href => url) { name } result = content_tag(:dt, link) if [:work_in_progress] result << content_tag(:dd, 'Work in progress', :class => 'work-in-progress') end result << content_tag(:dd, capture(&block)) result end |
#guide_chapter_link(guide, chapter) ⇒ Object
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
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 |
#guide_link(guide) ⇒ Object
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
23 24 25 |
# File 'lib/guides/helpers.rb', line 23 def is_production? assigns[:production] end |