Module: Gumdrop::Util::ViewHelpers

Included in:
Generator::DSL, RenderContext
Defined in:
lib/gumdrop/util/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#cache_bust(path) ⇒ Object



47
48
49
# File 'lib/gumdrop/util/view_helpers.rb', line 47

def cache_bust(path)
  uri_fresh(path)
end

#checksum_for(path) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/gumdrop/util/view_helpers.rb', line 51

def checksum_for(path)
  path= path[1..-1] if path[0] == '/'
  @_checksum_cache ||= {}
  if @_checksum_cache.has_key? path
    @_checksum_cache[path]
  else
    content= render path
    @_checksum_cache[path]= Digest::MD5.hexdigest( content )
  end
end

#configObject



62
63
64
# File 'lib/gumdrop/util/view_helpers.rb', line 62

def config
  site.config
end

#dataObject



66
67
68
# File 'lib/gumdrop/util/view_helpers.rb', line 66

def data
  site.data
end

#gumdrop_versionObject



70
71
72
# File 'lib/gumdrop/util/view_helpers.rb', line 70

def gumdrop_version
  ::Gumdrop::VERSION
end

#hidden(&block) ⇒ Object



8
9
10
# File 'lib/gumdrop/util/view_helpers.rb', line 8

def hidden(&block)
  #no-op
end

#markdown(source) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/gumdrop/util/view_helpers.rb', line 17

def markdown(source)
  eng_class= Gumdrop::Renderer.for 'markdown'
  unless eng_class.nil?
    eng= eng_class.new { source }
    eng.render
  else
    raise StandardError, "Markdown is not available: Include a Markdown engine in your Gemfile!"
  end
end

#textile(source) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/gumdrop/util/view_helpers.rb', line 27

def textile(source)
  eng_class= Gumdrop::Renderer.for 'textile'
  unless eng_class.nil?
    eng= eng_class.new { source }
    eng.render
  else
    raise StandardError, "Textile is not available: Include a Textile engine in your Gemfile!"
  end
end

#uri_fresh(path) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/gumdrop/util/view_helpers.rb', line 37

def uri_fresh(path)
  if (path[0] == '/')
    internal_path= path[1..-1]
  else
    internal_path= path
    path= "/#{path}"
  end
  "#{ path }?v=#{ checksum_for internal_path }"
end

#urlencode(string) ⇒ Object



12
13
14
15
# File 'lib/gumdrop/util/view_helpers.rb', line 12

def urlencode(string)
  require "erb" unless defined? ERB
  ERB::Util.url_encode(string)
end