Module: AllGems::ViewHelpers

Included in:
App
Defined in:
lib/allgems/ViewHelpers.rb

Instance Method Summary collapse

Instance Method Details

#content_tag(name, content, options, escape = true) ⇒ Object



11
12
13
14
# File 'lib/allgems/ViewHelpers.rb', line 11

def (name, content, options, escape = true)
    tag_options = tag_options(options, escape) if options
    "<#{name}#{tag_options}>#{content}</#{name}>"
end


16
17
18
19
20
# File 'lib/allgems/ViewHelpers.rb', line 16

def link_to(text, link = nil, options = {})         
    link ||= text
    link = url_for(link)
    "<a href=\"#{link}\">#{text}</a>"
end


22
23
24
25
26
# File 'lib/allgems/ViewHelpers.rb', line 22

def link_to_gem(gem, options = {})
    version = options[:version] ? options[:version] : ''
    text = options[:text] ? options[:text] : gem
    link_to(text, "/gems/#{gem}/#{version}")
end

#rdocify(text) ⇒ Object



43
44
45
46
# File 'lib/allgems/ViewHelpers.rb', line 43

def rdocify(text)
    @_rdoc ||= RDoc::Markup::ToHtml.new
    @_rdoc.convert(text)
end

#tag_options(options, escape = true) ⇒ Object



6
7
8
9
# File 'lib/allgems/ViewHelpers.rb', line 6

def tag_options(options, escape = true)
    option_string = options.collect {|k,v| %{#{k}="#{v}"}}.join(' ')
    option_string = " " + option_string unless option_string.blank?
end

#ts(time) ⇒ Object



39
40
41
# File 'lib/allgems/ViewHelpers.rb', line 39

def ts(time)
    time.strftime('%b %d, %Y') if time
end

#url_for(link_options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/allgems/ViewHelpers.rb', line 28

def url_for(link_options)
    case link_options
    when Hash
        path = link_options.delete(:path) || request.path_info
        params.delete('captures')
        path + '?' + build_query(params.merge(link_options))
    else
        link_options
    end
end